Haskell Style

First of all, Hamler is purely functional. It has really similar syntax to Haskell, so if you are familiar with Haskell it should not be a problem. However, if you are not, the guide should be able to walk through the basic syntax and make you more comfortable with programming functionally.

This is an example of implementing merge sort in Hamler. It is normal that you don’t understand what going, the purpose of the example to is just let you get a gist of what will the code look.

  1. merge :: forall a. Ord a => [a] -> [a] -> [a]
  2. merge [] ys = ys
  3. merge xs [] = xs
  4. merge [x|xs] [y|ys] = if x <= y
  5. then [x |merge xs [y|ys]]
  6. else [y |merge [x|xs] ys]
  7. mergesort :: forall a. Ord a => [a] -> [a]
  8. mergesort [] = []
  9. mergesort [x] = [x]
  10. mergesort xs = let (as, bs) = splitAt (length xs / 2) xs
  11. in merge (mergesort as) (mergesort bs)