Functional Programming 101 with Haskell
blog.gja.in
blog.gja.in
I don't know enough about Haskell to pull it off (though I may try if no one's done it in a year or so). However if someone could inject the wacky sensibility* of things like LYAH, Computerphile and CodeSchool.com into a Haskell video tutorial, it would do worlds of good for the community. Better yet, if someone could make an interactive class like CodeSchool or Codecademy, that would be amazing.
* Thought I should mention that the wackiness isn't the only important part, it also needs to be properly paced. That was LYAH's other strong point, they hammer home each concept with multiple examples before moving on.
Why? I can't think of any advantage that a video has over an article when it comes to teaching computer science. An article allows me to read and understand each concept at my own pace and rereading something I didn't quite get is trivial. All these simple things are just tedious with a video.
Furthermore, having coding exercises with a checker that can tell if you've done things correctly would help a ton when it comes to actually writing Haskell code.
More material here: http://www.haskell.org/haskellwiki/Video_presentations#Intro...
I think vasquez put an extra right angle bracket by mistake.
Also the artwork is great.
Prelude> sumOfElements [] = 0
<interactive>:12:18: parse error on input `='
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
If you get an error like that where you intend to define something, use let.
like: let sumOfElements [] = 0
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.
To meaningfully distinguish functional from imperative programming you have to add purity/immutable data to the definition at least.
Perhaps helping users get set-up should be the first thing you address.
Also, you start off by saying the examples should work well in ghci but then show examples that are not run in ghci.
I fear your experience is blinding you to the numerous little things that trip up newcomers.
You might also state upfront what you assume the reader already knows. Such as the existence, and use, of ghci.
If you are mentioning ghci at the start then maybe show the examples as run in ghci. Or, if you prefer files, then explain how to run a file from the command line.
1. paste all (well most, I haven't verified it to say all) of the functions in "anyfile.hs" 2. cd to the same directory as anyfile.hs in terminal 3. open ghci 4. :load anyfile.hs 5. Play with the functions!
(because your expression expands to 9 + 9(8) + 9(8)(7) + ... 9! = 9!(1+1/1 + 1/2! + ... 1/8!) = -1 + 9! e - (1/10 + 1/(10 11) + ...))