One hurdle for learning Haskell is that it seems like all of the code you find online doesn't work when you type it into the interpreter.
This is because (unfortunately, though probably for good reasons that aren't apparent to me) Haskell programs are typically a collection of definitions and the REPL only evaluates expressions. So
2 * 2works fine but
x = 2 * 2doesn't.
Instead, you have to make a file. I then use
ghci foo.hsto load it into the REPL, where you can write
mainto run it or any other expression to test code. And to just run a file directly, use
(PS: I lied in the above. It's actually that everything given at the prompt is interpreted within the IO monad. So you can do
let x = 2 * 2in the REPL, but this is a confusing way to get started, because the syntax is different than normal code.)