A couple of very good Haskell articles I have seen recently:
- Introducing the Monads by Aditya Siram. An great overview which serves to confirm/reinforce things that I have learnt or figured out so far. Tho’ I think uses
returnwhere it is unnecessary; for example the first snippet on p.4 should be:
mport Data.Char main :: IO () main = do writeFile "test.txt" "a,b,c,d,e" x <- readFile "test.txt" print (map toUpper x)
IMHO. Into what are we injecting
y? Surely if you have an
IO Stringat the first opportunity you would want to ← it to a
Stringso you could play with it in pure code (i.e.
toUpperin this case).
Also I wasn’t aware of this technique, which I will definitely be using:
import "mtl" Control.Monad.State
Then compile with:
ghc --make -XPackageImports ...
Since I seem to have both
mtlinstalled. Previously I had been using
- Monad Transformers Step by Step by Martin Grabmüller. Much more theoretical, I think I probably need to read it a few times to get the most out of it.
Normally I learn a language by just dropping myself in at the deep end and saying right, this program that I need to write anyway, instead of using (language I know) I’ll do it in (new language), God help me. Pascal, MATLAB, FORTRAN, C, C++, Perl, Java, Python, Tcl/Tk… I started in Python using it as I would have used Perl (yuk! but I was young), then before long worked up to HOFs, generators, decorators, etc. Same with Tcl. My early Java looked like C and my early C looked like Pascal.
But that doesn’t work for Haskell or OCaml. I tried it before and had to give up, this time I am being much more methodical about it, getting the foundations in place, and it’s paying off so far.