HACKER Q&A
📣 bananapear

What is the best way to learn Haskell for “real world use" (in 2019)?


I am currently working mainly in Java, Python and C#. I'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).

What are the best resources to learn how to architect Haskell applications? What are the best example apps on GitHub etc?


  👤 unhammer Accepted Answer ✓
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 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/book

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

https://hackage.haskell.org/package/esqueleto-2.4.3/docs/Dat...

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/

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



👤 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/). 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) for constructing HTML.

- selda (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_... and 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.