
Ask HN: What is the best way to learn Haskell for “real world use" (in 2019)? - bananapear
I am currently working mainly in Java, Python and C#. I&#x27;m a little familiar with Haskell syntax but I have found that most of the usual resources (Learn you a Haskell, Real World Haskell) tend to focus mainly on Haskell language basics and not on how to build a production application (e.g. web service).<p>What are the best resources to learn how to architect Haskell applications? What are the best example apps on GitHub etc?
======
unhammer
[https://typeclasses.com/phrasebook](https://typeclasses.com/phrasebook)
(especially the later lessons) has some nice little tutorials / tips and
tricks showing off libraries you'd want to use in production for various
tasks, very practical. (I haven't tried their for-pay courses, so can't
comment on that.)

[https://tech.fpcomplete.com/haskell/library/rio](https://tech.fpcomplete.com/haskell/library/rio)
is a tutorial for an alternative prelude, perhaps a bit opinionated, but it
shows a common "production" architecture.

------
jolmg
> and not on how to build a production application (e.g. web service).

Yesod is the web framework I use in Haskell:

[https://www.yesodweb.com/page/quickstart](https://www.yesodweb.com/page/quickstart)

[https://www.yesodweb.com/book](https://www.yesodweb.com/book)

For the database library, I prefer to use Esqueleto over Persistent, though:

[https://hackage.haskell.org/package/esqueleto-2.4.3/docs/Dat...](https://hackage.haskell.org/package/esqueleto-2.4.3/docs/Database-
Esqueleto.html)

In general, you'll want to use `stack` and Stackage[1] to manage your projects
and package dependencies. Hackage[2] has the latest package submissions.
Because they're simply the latest, they might be incompatible with one
another. Stackage groups the compatible versions of all packages in Hackage
into snapshots. `stack`, besides helping manage your dependencies, also has
package templates for how a new project's files should be layed out.

[1] [https://www.stackage.org/](https://www.stackage.org/)

[2] [https://hackage.haskell.org/](https://hackage.haskell.org/)

------
mrkeen
Build a simple web service using Scotty or Spock.

[http://hackage.haskell.org/package/scotty](http://hackage.haskell.org/package/scotty)

[https://github.com/scotty-web/scotty/wiki/Scotty-
Tutorials-&...](https://github.com/scotty-web/scotty/wiki/Scotty-
Tutorials-&-Examples)

------
alexmingoia
The best way is to try and build a web app and learn along the way. Here's the
stack I use for all my Haskell web apps:

\- Stack to manage the project and dependencies.

\- WAI and Warp to construct your own bare bones web app (see
[https://broch.io/posts/build-your-own-wai-
framework/](https://broch.io/posts/build-your-own-wai-framework/)). I don't
like frameworks like Yesod or Spock because I like to keep it simple.

\- blaze-html ([https://hackage.haskell.org/package/blaze-
html](https://hackage.haskell.org/package/blaze-html)) for constructing HTML.

\- selda ([https://selda.link](https://selda.link)) for PostgreSQL/SQLite
interface (it might be too much for beginners, but there's other modules like
postgres-simple).

\- wai-extra for form/file upload parsing, gzip, and other basic middleware.

\- wai-middleware-static for serving static files

\- aeson for JSON encoding/decoding

This stack is what I use for building webapps with Haskell. If you're building
JSON REST APIs you might want to look into Servant. I haven't used it
personally but I hear good things.

I strongly recommend learning the basics of Functors, Applicatives, and Monads
_before_ venturing into building applications: See
[http://adit.io/posts/2013-04-17-functors,_applicatives,_and_...](http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html)
and [http://adit.io/posts/2013-06-10-three-useful-
monads.html](http://adit.io/posts/2013-06-10-three-useful-monads.html) If you
know how Functors, Applicatives, and Monads work then you can understand
almost everything about Haskell.

Good luck! Feel free to email me if you have questions.

------
zerr
Just to note, Haskell is not that pretty when used for "real world" tasks.

~~~
alexmingoia
I _love_ building web apps with Haskell. Experiencing zero bugs and crashes
after pushing to production is so much _less stressful_ than when I worked on
webapps using Node.JS and React. The last few startups I worked at we had a
bug in production at least once a week, sometimes every day. Completely
eliminating that stress has _changed my life_ as a developer. I still use
JavaScript for some progressive-enhancement, but I'll be trying PureScript for
progressive enhancement for my future projects.

Haskell isn't perfect, the tooling and ecosystem leaves much to be desired,
but I'll trade Haskell's imperfections for the constant stress of bugs in
production any day.

~~~
natalyarostova
As someone learning clojure (my first FP) I realized I’m learning it because
a.) Im good enough now that I can learn it after learning languages like
python, and b.) it’s because I love the craft of programming so much that I
want to push myself to be better in hard ways.

I wonder sometimes if Haskell or lisp whatever crash less in production
because they’re written by people with a penchant for high quality
craftsmanship?

I can imagine Python written beautifully and craftfully could also have these
same properties.

Or maybe not. As I said, I just started learning FP :)

~~~
alexmingoia
Haskell is one of the few pure languages, pure meaning it's _entirely_
referentially transparent, only allowing pure functions. This is not the case
with Lisp, Clojure, or many languages that are described as functional
programming. Referential transparency means that a function returns the same
output for given input. This is not the case in Clojure, Python, or most all
programming languages, and in contrast what makes Haskell safe.

Haskell's purity combined with strong typing is what ensures its safety at
runtime. In other words, it's trivial to write a program that crashes at
runtime in CommonLisp, Clojure, Python, etc. Haskell eliminates this issue by
construction. In these other languages, incorrectness can crash a program.
Haskell intends to eliminate this.

One of the major tests of referential transparency is if you can lazily
evaluate it. Only a 100% pure language can be lazily evaluated. Which Haskell
is, excluding warts and historical baggage from its development as a research
project.

[https://en.wikipedia.org/wiki/Referential_transparency](https://en.wikipedia.org/wiki/Referential_transparency)

[https://en.wikipedia.org/wiki/Pure_function](https://en.wikipedia.org/wiki/Pure_function)

Haskell functions are pure like math functions. If we have a function f(x)=x+2
then f(16) is _always_ 18\. In Python or Javascript or Lisp I can write a
function where f(16) returns 18, 1000, or "foobar" depending on the time of
day. In impure languages the output of a function can change even with the
same input. That's why from a Haskell perspective most languages are unsafe by
design and encourage programs riddled with bugs.

~~~
crimsonalucard
This is not the reason why haskell is "Safe"

Haskell is safe because of type checking. A function in python f(x) = x / 3
will crash if you make x = "a string" because "a string" / 3 doesn't make any
sense. Python won't let you know about this until the program actually calls
f(x).

In haskell f(x: int) -> int = x + 3 is type checked meaning that this program
will never compile unless you make x = <some integer>. Haskell does not need
to compile the program to know about this.

At a very high level what this means is this , languages like python and
closure are so expressive they allow you to write programs that will crash
during runtime. Languages like haskell are restrictive. They are so
restrictive that they will only allow you to write programs that compile and
make sense.

You will note even when using clojure or untyped lisp languages in the usual
way (via functional programming with pure functions) you will still run into
many runtime type errors just like python.

