Comment

Comment by slaymaker1907

You can definitely use it as an incredibly powerful learning tool. I've been using it to guide me through Haskell and I've learned so much more than I did in college when I had spent way more time on it (that time being 10 years ago so I had forgotten most of it). It's invaluable being able to go and ask the AI questions and have it rephrase the parts you don't understand. I spent a good hour with it figuring out exactly what the traverse function does (`traverse (\x -> ['z', x]) "ab"` probably doesn't do what you think it should).

Spoiler: The <> combines lists as cross joins (for-loop within another for-loop). The lambda maps to new lists ['z', 'a'] and ['z', 'b'] (strings are just char arrays). It then computes the various combinations to recombine them so ['z', 'z'], ['z', 'b'], ['a', 'z'], ['a', 'b']. Note it's not all permutations since you don't have ['z', 'a'] even though that's actually one of the "base" arrays we got from the lambda. It took me a long time to really internalize that and it's still probably not a function I'd reach for.

It is kind of cool, though, that you can do `(,) <$> lista <> listb` and you get a nested for loop.

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton