Hacker Newsnew | past | comments | ask | show | jobs | submit | _ft's commentslogin

I started learning Haskell for the same reason that Peaker described. From what I understand so far, Haskell is a very high level language which lets you do more with less.

One of the examples that come often is quicksort which you can write in like 3 lines:

quicksort (p:xs) = (quicksort lesser) ++ [p] ++ (quicksort greater) where lesser = filter (< p) xs greater = filter (>= p) xs

But the thing is you still have to understand a lot of stuff before being able to use it correctly. I think one of the most difficult (and interesting) topic would be monads, there are tons of tutorials online if you're interested on reading on it.


It's not a quicksort. It's a quasi-quicksort, which is actually not quick due to memory allocations.

Here's how quicksort looks like in haskell:

    import Data.Vector.Generic
    import qualified Data.Vector.Generic.Mutable as M 

    iqsort :: (Vector v a, Ord a) => v a -> v a
    iqsort = modify go where
             go xs  | len < 2   = return ()
                    | otherwise = do
                        p <- xs `M.read` (len `div` 2)
                        m <- M.unstablePartition (< p) xs
                        go $ M.slice 0     m         xs
                        go $ M.slice (m+1) (len-m-1) xs
                    where len = M.length xs
Or something like this (u-u-ugly) http://www.haskell.org/haskellwiki/Introduction/Direct_Trans...

At this point it's less for more.

I don't understand why they chose quicksort to show off.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: