Settings

Theme

Ask HN: What resources do you recommend for learning Haskell?

109 points by hackerthemonkey 2 years ago · 66 comments · 1 min read


What resources do you recommend for learning Haskell?

I am working my way through “Learn You a Haskell for the greater good”

I also have a side project to learn things by doing, but was wondering what the most recommended learning sources were which people found very useful.

anfelor 2 years ago

Perhaps contrary to most people in this thread, I think you should avoid learning lenses or category theory too early. These are great tools, but they take months or even years to master and are not required to write useful code in the language.

I find Haskell very useful for my projects, but to achieve this I restrict myself to the basic subset of the language (Haskell 2010, no fancy extensions such as type families or GADTs) and use few libraries aside from the core libraries. New features and libraries always carry a high learning curve in Haskell and less popular libraries can be buggy. Instead, you will often be more productive just writing the required functionality from scratch (and it will teach you more too!).

At Jane Street, I saw my coworkers learn functional programming in just one week. (some still struggled with monads in the second week -- if that is you, I can recommend Phil's paper: https://homepages.inf.ed.ac.uk/wadler/papers/marktoberdorf/b...). If you are learning Haskell in your free time and with no one experienced to help, it will obviously take you longer. If you have questions, feel free to post on the Haskell IRC or Reddit. Just don't worry that you need to read another tutorial before getting started :)

  • doctorpangloss 2 years ago

        type JokeM a = IO a
    
        askQuestion :: JokeM String
        askQuestion = do
          putStr "How do you know someone works at Jane Street? "
          hFlush stdout
          getLine
    
        tellPunchline :: String -> JokeM ()
        tellPunchline _ = putStrLn "They tell you!"
    
        janeStreetJoke :: JokeM ()
        janeStreetJoke = askQuestion >>= tellPunchline
    
        main :: IO ()
        main = forever janeStreetJoke
    
    I don't know this feels kind of verbose to me.
  • tmountain 2 years ago

    I like this advice, but I would suggest adopting a prelude that has better defaults than what the language ships with.

  • TwentyPosts 2 years ago

    ...what are lenses? Never heard of those.

    • turboponyy 2 years ago

      As with anything Haskell, one could simply reply with "here's the formal definition."

      But in easily digestible terms, it's a way to narrow your view over a collection to a subset that satisfies some property, and perhaps perform some operations on that subset.

      This video presentation (with a very humorous audience dynamic, might I add) serves as a great introduction by example: https://youtube.com/watch?v=QZy4Yml3LTY

      • Zambyte 2 years ago

        I'm going to watch the video, but I'm having trouble understanding how lenses are different from filter, and perhaps map. Is it just a combination of filter and map?

        • matt-noonan 2 years ago

          No, it's quite different. A super rough but somewhat accurate starting point is to think of a lens as being like the `.foo.bar.baz` in `myobject.foo.bar.baz`: a way to describe some "location" inside of a data structure, in a way that allows for getting and setting. But lenses are also data, so they can be stored in variables, manipulated, and so on. It's a very useful concept, and very much not required or helpful when learning Haskell. It's also not a core Haskell concept in any sense, just something that has been built on top of Haskell as a library.

          • lgas 2 years ago

            Also helpful to note that the "location" can be virtual. For example you could have a lens into the hours field a string that contains an ISO-8601 formatted date, so you could do something like

                let s = "20240722T193456.789-0800"
                putStrLn $ 19840206T193456.789-0800  -- prints "20240722T203456.789-0800"
            
            and they can be composed, so if you have some other lens that gets from your outer structure to an ISO-8601 formatted date string field, let's call that lens `fieldLens` then `fieldLens . hours` will get from your outer structure to the hours field of that date field.
matt-noonan 2 years ago

A common failure mode is for people to think Haskell is some special snowflake that requires reading 50 books and papers to understand. It doesn’t. Learning by doing is definitely the way to go. LYAH is fine but not great at practical problems. Real World Haskell is somewhat out of date but better at the actual “how do I make a program that does real things?” question. Best bet is to hack until you get stuck or your solution seems too ugly, then ask for leads on Reddit or the FP discord.

nvarsj 2 years ago

Haven’t touched Haskell in years, but I found the best guide was Brent Yorgey’s old UPenn CIS194 online class. It contains easy to digest text lectures with follow up classwork.

I successfully taught dozens of people who had no former functional background. Just did a weekly meeting covering the lecture and prior week’s homework.

https://www.cis.upenn.edu/~cis1940/spring13/lectures.html

  • nextos 2 years ago

    It's also my favorite beginners resource. And free.

    Straightforward and short. Takes you to the interesting bits very quickly.

  • undefined_user6 2 years ago

    I also found this course to be a great resource!

ahf8Aithaex7Nai 2 years ago

My biggest difficulty in learning Haskell was to distinguish the really useful from the useless. There is a lot of “academic nonsense” in Haskell (both in the language and in the code people have written) and a lot that is just broken and abandoned or unnecessarily complicated. Unfortunately, it takes a lot of time to separate the wheat from the chaff. Underneath the 50 or so language extensions, the completely outdated (and in my opinion broken) Prelude and the super frustrating and unpolished tooling and cursed lazyness hides a very beautiful and powerful, simple, productive, purely functional programming language.

To summarize, you could say that Haskell is not really made of one piece, but is something like a 34 year old, very messy academic playground.

So it might be helpful to switch to a purely functional alternative, Purescript/Elm/Gren for practical programming, or Idris/Agda to explore the more academic side.

rnallandigal 2 years ago

"What I wish I knew when learning Haskell" by Stephen Diehl[0][1]. It has commentary on a great deal of topics in Haskell and is very approachable. Also, learning to use Hoogle[2] will serve you well.

[0] https://smunix.github.io/dev.stephendiehl.com/hask/index.htm...

[1] https://github.com/sdiehl/wiwinwlh

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

  • lemonwaterlime 2 years ago

    This, and get comfortable letting the compiler (ghc) and the type system find errors for you. Change a piece of code and let the compiler tell you everywhere that is now broken. Fix it all. Continue coding.

tombert 2 years ago

Working through Learn You A Haskell is a good start.

After that, I honestly think you'll get the best bang-for-buck by reading library-specific tutorials. If you play with enough of the libraries the rest of the language more or less falls into place.

Conduit is a pretty ok streaming library, and has good documentation: https://github.com/snoyberg/conduit#readme

Lens gives you a lot of useful features that more or less correspond to stuff like Getters and Setters in something like Java, and the tutorials for it get into some helpful details about writing Haskell code: https://hackage.haskell.org/package/lens

Otherwise it's basically a lot of "just build shit, and don't be afraid to feel confused" and it'll fall into place.

francogt 2 years ago

Haskell Programming from First Principles is probably the best and most exhaustive resource on learning Haskell.

I now refer people to “Effective Haskell” by Rebecca Skinner[0]. It’s well written, modern (published in 2023) and goes into everything you need to know to use haskell in common, real world tasks.

[0] https://pragprog.com/titles/rshaskell/effective-haskell/

ks2048 2 years ago

Graham Hutton YouTube series:

Functional Programming in Haskell https://youtube.com/playlist?list=PLF1Z-APd9zK7usPMx3LGMZEHr...

yoyohello13 2 years ago

I really liked https://haskellbook.com/. It’s long, but has exercises after each chapter which I found very helpful.

The first chapter is about Lambda Calculus which is kind of a Haskell meme at this point, but learning it actually did help me a lot to grok how Haskell programs are meant to fit together.

Other than that, just doing some basic side projects and leaning about how to use Cabal effectively should get you there.

  • fn-mote 2 years ago

    I love Haskell Programming from First Principles. It has details for everything. It has plenty of exercises you help you make friends with all of the "esoterica". Once I worked with the rules (e.g. how to make an instance of Applicative), they were a lot more concrete for me.

    In Haskell, when you don't understand some detail it really comes back to get you. I read LYaH and I felt like I understood the big picture, but I didn't understand that it was critical to understand the types of _everything_ in an expression that I wrote. (My own failing.)

    In summary: I highly recommend. https://HaskellBook.com

    My background when I read it: 10+ years programming, 5+ years functional programming, 2 attempts reading LYaH (1 successfully). I still loved it. It would have saved me a lot of grief to start with the HB instead of LYaH.

    • hiAndrewQuinn 2 years ago

      +1 for HPFFP. The 1200 page behemoth that finally made everything, and I mean everything, click.

viking66 2 years ago

Learning haskell is like learning to program from scratch. Do you remember the your journey learning to code for the first time? If you're anything like me, that was a lot of banging your head against the wall, trying all sorts of different resources, giving up only to try again a little while later, and then one day everything starts to click. It's all part of the journey.

Haskell is so different from all the languages people tend to learn so it feels much like learning to code all over again. That being said, it's totally worth it! I'm a much better developer (in any language) thanks to all the wonderful things haskell has taught me. I'm much better at designing clean abstractions, I have more tools for solving problems, I have more fun coding, and new challenges don't scare me so much because I know I just need to go through the process and I'll come out the other side even better.

To answer your question, there was no one resource that worked for me. It was just a matter of time and effort going through lots of resources until one day my brain had established new neural connections and things clicked. I read several books and watched lots of people writing haskell and explaining the new (to me) concepts on twitch and youtube.

bramhaag 2 years ago

Haskell Programming from First Principles[1] is extremely comprehensive, covering everything from lambda calculus to IO.

For further self-learning, it might be interesting to learn about the underlying mathematical concepts, such as category theory. A deep dive into the workings of a Hindley–Milner type system might also help demystify some of Haskell's typing magic.

[1] https://haskellbook.com/

wavemode 2 years ago

I can only speak about my personal experience.

When I was in college I read through Haskell Programming From First Principles. My prior programming experience (of probably ~10ish years, as a hobbyist) was mostly C++, Java and PHP.

I found it grueling. I really was just not used to reading definitions like

  newtype State s a = State { runState :: s -> (a, s) }
  instance Monad (State s) where
      return x = State $ \s -> (x,s)
      (State h) >>= f = State $ \s -> let (a, newState) = h s
                                          (State g) = f a
                                      in  g newState
Nowadays, such a definition (and its practical applications) seems very trivial, but at the time I remember it felt like learning a new type of math, or a new language. Most of my time reading that book was spent struggling to figure out how the types fit together and why they were useful and/or necessary to be structured the way they were.

This wasn't the book's fault - I actually think the book does go to great lengths to try to guide the reader gradually toward understanding. My brain just wasn't ready for it. It took a long time of playing around with Haskell, as well as playing around with other languages (and seeing things like async-await and thinking to myself "hey! that's a monad!") before these things became second nature. I think it just goes to the concept of "osmosis" in psychology - sometimes you subconsciously absorb information over time before it starts to make sense.

Dunno if this comment constitutes "advice" per se, lol. Just offering you something to relate to, I guess.

makerofthings 2 years ago

I did https://learnyouahaskell.com and then https://adventofcode.com . I've been learning Haskell for about 6 years now and I sort of get it.

codethief 2 years ago

I recently started reading Bartosz Milewski's Category Theory for Programmers[0] and while it's less about Haskell per se and more about the ideas behind it, I found it did a much better job at explaining Haskell to me than any other introduction I read before. At least I'm able to appreciate Typing the Technical Interview[1] now. :-)

[0]: https://github.com/hmemcpy/milewski-ctfp-pdf

[1]: https://aphyr.com/posts/342-typing-the-technical-interview

  • goostavos 2 years ago

    This is a good source if you feel like waiting until chapter 14 for "so, anyways, that's how addition works." I know Haskell pretty well and I've bounced off Milewski's stuff multiple times.

    Haskell != Category Theory. You don't have to know what an Endofunctor is in order to write useful programs. Haskell is just another programming language. It's totally possible to do cool stuff in it without knowing any of the theories that back a lot of the "why" behind its common abstractions.

    Pick up any book and just start building toy programs! Don't over think it. Start very small. Make a CLI tool. Scrape some data off the internet. Even simple haskell programs will cause you to bump into all kinds of concepts at the time you need to learn them.

    Just working through a book can make Haskell seem painfully esoteric. Monad transformers broke my brain when I tried to learn them simply because I reached the monad transformer chapter. However, I finally "got" them once I was actually building something, because their existence is something you naturally start to bump into the more you program. There's a friction that comes from no having them, but noticing that "friction" and letting it guide you can only happen over time as you use the language.

graphov 2 years ago

I'd recommend Well-Typed's YouTube channel: https://www.youtube.com/@well-typed

Andres Loeh has recently released a pretty comprehensive introductory series there and in addition they have a fortnightly stream "The Haskell Unfolder" where they go over some more advanced subjects with examples.

3D39739091 2 years ago

https://www.manning.com/books/get-programming-with-haskell

Get Programming With Haskell by Will Kurt. Made up of small lessons that all build on top of each other and will really help you understand what's going on.

I wanted to like Effective Haskell but honestly didn't. YMMV.

mhitza 2 years ago

I think Learn you a Haskell is a good introduction, but you will learn more by doing.

I don't know what state of the art is nowadays for learning Haskell, I started my journey more than 10 years ago, but for help I recommend https://discourse.haskell.org/ whenever you feel stuck, have questions; instead of SO/subreddit.

edit: while Copilot, or equivalent, will hallucinate APIs that don't exist, I recommend having such a thing enabled as it will help you with syntax / standard library functions early on.

Also take a good look at the base, containers, directory, filepath, etc packages documentation. These come as part of the standard installation (with something like ghcup), and represent the "standard library" you have access to (on paper that would be only limited to base). For a full list of installed packages you can always run `ghc-pkg list` and start browsing the generated documentation on hackage.haskell.org

simonmic 2 years ago

Not yet mentioned: https://leanpub.com/haskell-cookbook, a good intro from an experienced tech writer.

If you like videos: https://www.youtube.com/results?search_query=haskell

The haskell matrix room and (slightly less useful for beginners) IRC channel: https://www.haskell.org/community

Curated resources:

https://www.extrema.is/articles/haskell-books

https://www.haskell.org/documentation

https://haskell-links.org

Strix97 2 years ago

Hi I am seeing a lot of good resources in this thread already but I might have something to add. I am also learning Haskell at the moment, and the thing that really helped me push through it was this MOOC (Massive Open Online Course) by the university of Helsinki which is completely free and online available.

https://haskell.mooc.fi/

It's a structured, has a lot of excercises and so far (I am on Lecture 5 at the moment) very clear. It wont make you an expert, but will get you writing code quickly.

__rito__ 2 years ago

Programming in Haskell, 2ed by Graham Hutton [0] is the best resource, in my opinion. It also has two comprehensive YouTube playlists that are accessible, rigorous, and fun to watch [1].

Those who learn well from a text resource, Haskell MOOC from mooc.fi [2] is pretty good.

[0]: https://www.cs.nott.ac.uk/~pszgmh/pih.html

[1]: https://www.cs.nott.ac.uk/~pszgmh/pih.html#videos

[2]: https://haskell.mooc.fi

tnch 2 years ago

The Haskell course at ITMO from Serokell is pure gold, imo: https://github.com/jagajaga/FP-Course-ITMO

lolive 2 years ago

"Mostly adequate guide to FP (in javascript)". [Don't laugh].

That course takes you into coding from scratch "bind" and "return" for several use-cases, and do a bit of currying. Very interesting small exercises.

https://github.com/MostlyAdequate/mostly-adequate-guide/rele...

johnkelly 2 years ago

I really like this new YouTube series Haskell For Dilettantes

https://m.youtube.com/watch?v=nlTJU8wLo7E

wrsh07 2 years ago

If you're familiar with functional programming, I really like the learnxinyminutes reference for Haskell: https://learnxinyminutes.com/docs/haskell/

I'm not sure why, but the Haskell one clicks for me more than some of their other guides.

This isn't a great way to learn Haskell, but it's enough to start writing working code (and writing working code is a good way to learn!!)

  • wrsh07 2 years ago

    Ooh, one nice book is the Okasaki purely functional data structures. The inline code is not Haskell, but iirc the appendix has Haskell implementations

Zhyl 2 years ago

I found these two videos on combinators and lambda calculus recently. They're only tangentially related to Haskell, but they are the most approachable videos on the topic I have ever seen.

https://www.youtube.com/watch?v=3VQ382QG-y4

https://www.youtube.com/watch?v=pAnLQ9jwN-E

graemep 2 years ago

Graham Hutton's lectures (on Youtube) seem pretty good. He also has written a book. Both seem pretty good but not got very far yet myself.

_xiaz 2 years ago

I learned a great deal by working through a bunch of haskell coding puzzles on codewars after only reading the first six chapters.

This helped a bunch with getting good at higher order functions and recursion.

I took a detour to lisp after and never looked back, but that's due to my type system preferences, you'll benefit from puzzles either way.

lambdaba 2 years ago

Not meaning to hijack the thread, but I would be interested in opinions on the "best" type system implementation that has enough of a library ecosystem to be suitable for web/app development.

To be clear it's also for learning, but I'm wondering what else is there outside of the Haskell/PureScript etc. world.

tiberius_p 2 years ago

Real World Haskell was pretty good last time I read it. It has lots of concrete code examples that you can use in real world applications. It won't bore you to death with abstract theory and instead it will blend it with real world problems and make learning both fun and useful at the same time.

robertinom 2 years ago

This is a great up to date course to get you started: https://youtube.com/playlist?list=PLNEK_Ejlx3x1D9Vq5kqeC3ZDE...

penguin_booze 2 years ago

https://duckrabbit.tech/articles/learning-haskell.html

brudgers 2 years ago

Time. Learn a little Haskell this month. Learn a little Haskell in December. Some more over the next few years. In between you will be learning more about programming in general and many other things including how you learn.

There’s no midterm in eight weeks; no final grade after that, and nobody who matters cares how good or bad you are at Haskell. Like most things, it’s not worth having an opinion about.

Give yourself permission to write Haskell poorly because that makes it more likely you will write Haskell. Give yourself permission to not learn Haskell because maybe you like the idea of writing Haskell more than the work of learning Haskell…

…yep, time and permission are the best resources for learning Haskell (or anything else as an adult). It really doesn’t matter what book you pick. Either you enjoy committing or you don’t. Either the work feels satisfying while doing the work or doesn’t.

When the work is truly satisfying, it doesn’t need to be optimized against imagined external opinions. You just do it because it is what you do.

Or not. Good luck.

carterschonwald 2 years ago

It’s just a programming language. Write something and fail and ask for feedback and help when stuck.

Source: I’ve been using Haskell for fun and profit on and off since 2004

karambit 2 years ago

Since no one has mentioned this yet, https://haskell.mooc.fi

exe34 2 years ago

never learnt it myself, but if I ever tried again, I'd work my way through this: https://wiki.haskell.org/Typeclassopedia

rank0 2 years ago

What is the appeal of haskell? Genuinely curious

  • mrkeen 2 years ago

    Before Haskell I felt like I was cargo-culting advice - "use private fields with getters & setters", "everything should have an interface", "avoid static methods", "avoid 'new' and use factories instead". I figured eventually one of these days these things would click.

    With Haskell came new principles which had immediately obvious value - "is your function well-defined over all possible inputs?" and "does it always produce the same output given the same input?".

    I later 'got' that first set of principles, but I mostly disagree with them.

    My day job has always involved looking at exceptions and logs, figuring out "how something went wrong", and then trying to fix it. Guess which set of principles helps me make software that typically "just works".

  • kryptiskt 2 years ago

    It takes an idea[0] and runs with it as far as it goes. The best part is that when they got to obstacles like handling of IO, they didn't take the easy route and compromise the vision in favor of a pragmatic solution. Instead they went into unexplored territory and came back with monads, which proved an extremely fertile ground for more than IO.

    Obviously, Haskell being an academic language helps here, since novel ideas lead to papers and boring old ideas don't.

    [0]: That is statically typed lazy functional programming.

  • exe34 2 years ago

    pure functional. no mutations. (state and i/o handled with inscrutable magic).

    basically every code base out there could use more functional effort - simple data structures and simple functions that operate on these to return a brand new structure.

  • shae 2 years ago

    Easy to fix work code in the middle of the night when pagerduty hits

tpoacher 2 years ago

Here's the reading list I created for the undergrad module I taught:

Haskell

Books:

- Maybe Haskell by Pat Brisbin [https://thoughtbot.gumroad.com/l/maybe-haskell]: Very good book, available under a "pay what you want" model (or free pdf here [https://books.thoughtbot.com/books/maybe-haskell.html]).

- Learn you a Haskell for Great Good by Miran Lipvača: Available to read online for free [http://www.learnyouahaskell.com/].

- Real World Haskell by Bryan O'Sullivan, Don Stewart, and John Goerzen: Available to read online for free [http://book.realworldhaskell.org/read/].

Online tutorials:

- List of resources on haskell.org

- Haskell Wiki [https://wiki.haskell.org/Haskell]

- The Basics of Haskell series [https://www.schoolofhaskell.com/school/starting-with-haskell...] by Bartosz Milewski, from the School of Haskell website [https://www.schoolofhaskell.com/] (which also contains a number of other great resources on Haskell more generally).

- The Haskell Phrasebook [https://typeclasses.com/phrasebook]: a free quick-start Haskell guide comprised of a sequence of small annotated programs. It stands out from more traditional Haskell tutorials in that, instead of using the principles of Functional Programming as the theoretical starting point from which to start introducing the motivation and syntax of Haskell as a programming language, instead, it introduces Haskell syntax directly using code snippets that mimic traditional imperative programming as much as possible. This is intended to help users coming from imperative languages familiarise themselves with Haskell syntax first, and then slowly build on that by using progressively more idiomatic Haskell code, motivating its suitability for Functional Programming.

Other:

- The Hoogle Search Engine [https://hoogle.haskell.org/]; search for haskell operators or expressions here to get information on them. Good for looking up functions and operators defined in the Prelude (the haskell standard library) and other modules.

- List of haskell reserved symbols and keywords with brief description / explanations [https://wiki.haskell.org/Keywords].

2-3-7-43-1807 2 years ago

aren't there like dozens of AskHNs about that question already?

singularity2001 2 years ago

Julia. Haskell has incomplete polymorphism

lemper 2 years ago

aight bro, haskell from first principle is good book. at the very least, it gives you some explanation why haskell doing things as it does (lambda calculus thingy). then you can check matt parsons' book.

John23832 2 years ago

"Real World Haskell"

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection