cs_lang:haskell
This is an old revision of the document!
Table of Contents
Presentation
Paradigm
- purely-functional;
- lazy evaluation.
Typing discipline
- static typed;
- strongly typed;
- inferred.
Learning Haskell
Simple examples
Increment a number
let inc n = (+) n 1 -- Alternative: let inc n = succ n
Caeser cipher
-- Shifts a character to the right if positive, left if negative. shift :: Int -> Char -> Char shift n c | isUpper c = chr $ ord 'A' + ((ord c + n - ord 'A') `mod` 26) | isLower c = chr $ ord 'a' + ((ord c + n - ord 'a') `mod` 26) | otherwise = c encode :: Int -> String -> String encode _ [] = [] encode n xs = map (shift n) xs
cs_lang/haskell.1335729946.txt.gz · Last modified: 2012/04/29 22:05 by cedric