Personal tools

Haskell a la carte

From HaskellWiki

Revision as of 12:23, 14 December 2007 by Apfelmus (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Categories:Tutorials

Contents

1 Apéritifs

Foretaste of an excellent meal.

  qsort :: Ord a => [a] -> [a]
  qsort []     = []
  qsort (x:xs) = qsort (filter (<x) xs) ++ [x] ++ qsort (filter (>x) xs))
Quicksort in three lines (!). Sorts not only integers but anything that can be compared.
  fibs = 1:1:zipWith (+) fibs (tail fibs)
The infinite list of fibonacci numbers. Just don't try to print all of it.
  linecount = interact $ show . length . lines
  wordcount = interact $ show . length . words
Count the number of lines or words from standard input.

2 Entrées

How to eat?

  square x = x*x
The function f(x)=x\cdot x which maps a number to its square. While we commonly write parenthesis around function arguments in mathematics and most programming languages, a simple space is enough in Haskell. We're going supply arguments all around, so why clutter the notation with unnecessary ballast?

3 Plats principaux

4 Desserts

5 Vins