Learn Haskell in minutes
learnxinyminutes.com
learnxinyminutes.com
> myMap func [x] = [func x]
> myMap func (x:xs) = func x:(myMap func xs)
myMap does not deal with the empty list, will throw an exception if it is called with one, and there is no reason for it. (Just replace myMap func [x] = [func x] with myMap func [] = []).
Several functions that throw exceptions on empty lists (head, last) are introduced without any warning (such functions are considered bad style by many Haskellers).
> -- Haskell has a very strong type system, and everything has a type signature.
I believe a 'type signature' is the annotation, and no, not everything in Haskell has a type signature. Everything has a type.
> -- if statements
If is not a statement in Haskell, it is an expression. Same with case 'statements'.
There were quite a few more, see discussion on the Haskell reddit: http://www.reddit.com/r/programming/comments/1h917l/learn_x_...
Not all have been fixed. I love the idea of this, but I think these issues should be addressed before people actually use this to 'learn' Haskell.
Edit: corrections
1. myMap: fixed, good catch.
2. Using `head` and `last` being bad style: Where did you hear this?
3. The fixed the issues in the reddit thread yesterday. Here's the commit if you want to check it out: https://github.com/adambard/learnxinyminutes-docs/pull/62
Is there something specific that you think should be fixed?
There's a few more points that I can't go into in detail due to lack of time (reason for use of recursion instead of loops, if / case statements, purity) and I do appreciate the effort and can imagine that it will prove useful but I felt obliged to point out these things. If I can see them it's not a good sign ;)
I feel like the only thing these "learn X in Y minutes" pages are good for is for looking at other languages and judge the way their syntax looks like.
Furthermore, I don't think it is necessary to post a link here every time someone adds a new file to his website.
http://www.cl.cam.ac.uk/~ns441/files/thips.pdf
http://blog.codeslower.com/static/CheatSheet.pdf
http://strictlypositive.org/slicing-jpgs/ (handdrawn!)
http://blog.ezyang.com/2011/11/how-to-read-haskell/
http://www.fing.edu.uy/inco/cursos/proggen/Transparencias/Po...
"Strings are lists" !! 0 -- 'S'
That could probably be omitted or the logical progression modified so that you learn about `!!` and lists first.Of course, ignore my suggestion if the whole "learn x in y minutes" format assumes prior knowledge of programming language concepts.
Here's a Haskell version of the "real" quicksort, though it isn't nearly easy a read as the faux-quicksort:
http://augustss.blogspot.jp/2007/08/quicksort-in-haskell-qui...
For what is worth, the standard Haskell sort is a variant of merge sort.
http://hackage.haskell.org/packages/archive/base/latest/doc/...
merge :: Ord x => [x] -> [x] -> [x]
merge [] y = y
merge x [] = x
merge (x:xs) (y:ys) =
if x < y then
x:(merge xs (y:ys))
else
y:(merge (x:xs) ys)
odds :: [x] -> [x]
odds [] = []
odds (x:xs) = x:(evens xs)
evens :: [x] -> [x]
evens = odds . drop 1
mergesort :: Ord x => [x] -> [x]
mergesort [] = []
mergesort [x] = [x]
mergesort x = merge (mergesort (odds x)) (mergesort (evens x))Also in order to use ghci with this examples, multiples lines must be separated with semicolon.
EDIT: Two minutes later and it's merged already :) https://github.com/adambard/learnxinyminutes-docs/pull/78