Prelude> sumOfElements [] = 0
<interactive>:12:18: parse error on input `='
Prelude> sumOfElements [] = 0
<interactive>:12:18: parse error on input `='
If you are in the REPL, you want to do `let sumOfElements [] = 0`
If you want multiline input, you open with `:{` and close with `:}`. Both of these need to be on their own line. For example:
Prelude>:{
Prelude| let sum [] = 0
Prelude| sum (x:xs) = x + sum xs
Prelude|:}
As tdinkar points out, it is often easier to define your functions if a file and load that file from the REPL.edit: I take your last comment as "when using the REPL, it is easier not to use the REPL." :D
If you type `:help` you'll see all of the colon-commands that make up the command language. I'm not a Haskell expert, but my naive workflow tends to be a lot of usage of `:reload`. As a Lisper, I kinda feel like the colon commands should have been the default (sans colon) and one of the commands should have been `eval <haskel code>`.
It lets you do multiline stuff, and you get to see the output right away. You don't need let, or to repeat the "main = do ..." every time you want to run a block of code.
I think it's really helpful when you're starting out.
If you get an error like that where you intend to define something, use let.
like: let sumOfElements [] = 0
Haskell is not like ruby, it's a bit harder to define functions in the interpreter. It's easier to put them in a .hs file and then :load file.hs