News for hackers. Stuff that matters.
Re:Learn Haskell in minutes by paulkoer on Monday July 01, 2013 @11:58AM (#5971465)
I am afraid this is not a very good guide. I am by no means a Haskell expert, but even I can pick out a number of things which are not done very well and are not idiomatic Haskell. For example:

> 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

Re:Learn Haskell in minutes by egonschiele on Monday July 01, 2013 @12:12PM (#5971564)
Hey there! I wrote this Haskell guide.

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?

Re:Learn Haskell in minutes by paulkoer on Monday July 01, 2013 @12:23PM (#5971646)
Re 2: Well, sometimes you need them, but they do throw exceptions on empty lists, so if you don't know for sure that the list is non-empty it is definitely a bad idea to use them. I just thought a warning would be in order when presenting them. This is a point where Haskell's type safety (can't know at compile time if a list is empty or not) falls short and I think a lot of Haskellers try to avoid such functions for this reason. For example the Xmonad code uses zippers in a few places instead of lists which always have one element.

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 ;)

Re:Learn Haskell in minutes by quchen on Monday July 01, 2013 @08:13AM (#5970064)
Apart from pattern matching (which isn't unique among functional languages), this contains zero things about Haskell that make it good (or even usable) - type classes, more complex data types, how reusable the code is etc.

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.

Re:Learn Haskell in minutes by gtani on Monday July 01, 2013 @10:35AM (#5970893)
Re:Learn Haskell in minutes by egonschiele on Monday July 01, 2013 @12:15PM (#5971586)
Author here. Yes! A lot of Haskell is missing from this guide. I couldn't find a good way to explain those concepts while still keeping the guide at 5ish minutes. I would love to see type classes in here though, so please make a pull request! Adam has been very fast about merging mine in so far.
Re:Learn Haskell in minutes by DanWaterworth on Monday July 01, 2013 @10:51AM (#5971024)
Shameless plug: See also, "How do functional languages handle random numbers?" - http://programmers.stackexchange.com/questions/202908/how-do... .
Re:Learn Haskell in minutes by agentultra on Monday July 01, 2013 @11:53AM (#5971435)
The section on strings mentions an operator and type that isn't explained for another couple of sections:

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

Re:Learn Haskell in minutes by octo_t on Monday July 01, 2013 @08:03AM (#5970023)
Technically the quicksort at the end of the tutorial isn't idiomatic quicksort, the memory complexity is wrong.
Re:Learn Haskell in minutes by egonschiele on Monday July 01, 2013 @12:18PM (#5971608)
Correct. Sadly explaining monads and mutable data in Haskell would make this guide a lot longer. The example I gave is the traditional "look has elegant Haskell is!" example, not the "look how fast Haskell is!" example :)
Re:Learn Haskell in minutes by DanWaterworth on Tuesday July 02, 2013 @08:24AM (#5977304)
You could use mergesort instead:

    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))
Re:Learn Haskell in minutes by quchen on Monday July 01, 2013 @08:10AM (#5970056)
Even for linked lists, which is how [] is defined in Haskell?
Re:Learn Haskell in minutes by taeric on Monday July 01, 2013 @10:21AM (#5970792)
I believe the idea is that if it is not "in place," it is not quick sort.
Re:Learn Haskell in minutes by nandemo on Monday July 01, 2013 @10:39AM (#5970930)
That's right. That Haskell faux-quicksort uses a lot of extra space for the temporary lists.

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

Re:Learn Haskell in minutes by colorido on Monday July 01, 2013 @11:04AM (#5971099)
A small error, in section 8, input must be input1

Also in order to use ghci with this examples, multiples lines must be separated with semicolon.

Re:Learn Haskell in minutes by hamburglar on Tuesday July 02, 2013 @08:10PM (#5981558)
Why do all of these "Learn X in Y minutes" tutorials need to be spammed to HN? Please stop.
Re:Learn Haskell in minutes by ancarda on Monday July 01, 2013 @11:34AM (#5971303)
Unfortunately there doesn't seem to be any docs to learn Go. Can anyone point me in the direction of an equally good tutorial for Go?
Re:Learn Haskell in minutes by thenonameguy on Monday July 01, 2013 @01:31PM (#5972197)
Re:Learn Haskell in minutes by ancarda on Monday July 01, 2013 @03:37PM (#5973057)
Thank you for that!
Re:Learn Haskell in minutes by lucian1900 on Monday July 01, 2013 @11:21AM (#5971214)
"Its"!
Re:Learn Haskell in minutes by elisee on Monday July 01, 2013 @11:52AM (#5971430)
Pointing out grammar mistakes doesn't add anything of value to the HN conversation. It's an open source project, so rather than post a comment here, I took a minute to fix the errors and submitted a pull request. Consider doing the same next time.

EDIT: Two minutes later and it's merged already :) https://github.com/adambard/learnxinyminutes-docs/pull/78

Re:Learn Haskell in minutes by lucian1900 on Monday July 01, 2013 @12:47PM (#5971837)
I didn't read far enough to see the issue link.