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 Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Categories:Tutorials

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.

Entrées

How to eat?

  square x = x*x
The function 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?

Plats principaux

Desserts

Vins