
Functional Programming 101 with Haskell - Who828
http://blog.gja.in/2014/01/functional-programming-101-with-haskell.html
======
freyrs3
The equivalent chapter in Learn you a Haskell is probably a better place to
learn about list processing in Haskell.

[http://learnyouahaskell.com/starting-out#an-intro-to-
lists](http://learnyouahaskell.com/starting-out#an-intro-to-lists)

~~~
idProQuo
Having finally finished my first read of LYAH (It took me months of reading,
practicing and taking breaks to let it all sink in), I can only see one way to
improve upon it: Make a video series.

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.

~~~
laureny
> Having finally finished my first read of LYAH (It took me months of reading,
> practicing and taking breaks to let it all sink in), I can only see one way
> to improve upon it: Make a video series.

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.

~~~
idProQuo
While I don't _need_ videos in order to learn, I find that seeing concepts
represented visually while hearing them described by someone often works
better than simply reading them. I've done some of CodeSchool's courses even
though I already kind of knew the material, just because seeing it presented
in that format helped reinforce things.

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.

------
res0nat0r
I'll chime in and mention that Learn You A Haskell is the best online Haskell
tutorial I've found. I've been working through bits of it the last couple of
weeks and it is excellent.

Also the artwork is great.

[http://learnyouahaskell.com/](http://learnyouahaskell.com/)

------
hamburglar
As a complete and total haskell noob, I am unable to even get through your
syntax examples:

Prelude> sumOfElements [] = 0

<interactive>:12:18: parse error on input `='

~~~
gizmo686
This defiantly falls under Haskell not being noob friendly.

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.

~~~
hamburglar
aha, i tried using 'let' on the assumption that he was just being brief, but I
put a 'let' in front of each of the pattern-matching function signatures,
which didn't work. Thanks.

edit: I take your last comment as "when using the REPL, it is easier not to
use the REPL." :D

~~~
brandonbloom
Since Haskell has a strong divide between compile and runtime, the REPL is
this weird pseudo-runtime. It's best not to think of it like a REPL except for
very simple use cases and instead think of it like a command prompt that you
can evaluate some portion of Haskell in.

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>`.

------
asattarmd
The best intro for functional programming, IMO, is Joel Spolsky's "Can your
language do this"
([http://www.joelonsoftware.com/items/2006/08/01.html](http://www.joelonsoftware.com/items/2006/08/01.html)).

~~~
copx
Every newer language can do "this". First class functions and anonymous
functions have been a standard feature for a while. Does not mean that say Lua
or Ruby are functional programming languages. If you just require the ability
to pass around anonymous functions even C++ is a functional programming
language these days.

To meaningfully distinguish functional from imperative programming you have to
add purity/immutable data to the definition at least.

------
MaxGabriel
For a 101, you may want to direct readers to install Haskell Platform as an
easy way to get GHCI and all that set up.

~~~
tdinkar
Thanks for this, I added a link in the bottom.

~~~
jamesbritt
_... I added a link in the bottom._

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.

~~~
hamburglar
Yeah, the statement at the top that "you can run most of these examples in
ghci" really tripped me up. On one hand, it gave me the clue that the haskell
REPL is called "ghci", so I just went to my ubuntu box and typed "ghci" and
got told I needed to install "ghc", which I did and was on my way. On the
other hand, the examples weren't actually able to be run in ghci. :/

~~~
codygman
What you can do is:

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!

------
coldcode
Every time I see Haskell I am reminded of programming in Forth for some
reason.

~~~
codygman
Perhaps because of point free style?

------
euph0ria
Why is it not n! ?

~~~
nbouscal
There will be n! of the smallest heads, the ones which don't spawn any new
heads. Total heads, though, will be 9 + 9 * 8 + 9 * 8 * 7 + ...

~~~
euph0ria
aargh, of course... thanks!

