cs_lang:haskell
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
cs_lang:haskell [2012/04/29 22:05] – [Simple examples] cedric | cs_lang:haskell [2012/04/30 16:51] (current) – [Caeser cipher] cedric | ||
---|---|---|---|
Line 16: | Line 16: | ||
====== Simple examples ====== | ====== Simple examples ====== | ||
+ | |||
+ | You can compare functions below with the [[cs_lang: | ||
+ | |||
===== Increment a number ===== | ===== Increment a number ===== | ||
<code haskell> | <code haskell> | ||
- | let inc n = (+) n 1 | + | let inc = (+) n |
-- Alternative: | -- Alternative: | ||
Line 25: | Line 28: | ||
- | ===== Caeser | + | ===== Caesar |
<code haskell> | <code haskell> | ||
Line 38: | Line 41: | ||
encode _ [] = [] | encode _ [] = [] | ||
encode n xs = map (shift n) xs | encode n xs = map (shift n) xs | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Parity ===== | ||
+ | <code haskell> | ||
+ | parity :: Integral a => [a] -> [Bool] | ||
+ | -- Using recursion | ||
+ | parity [] = [] | ||
+ | parity (x:list) = [even x] ++ parity list | ||
+ | |||
+ | -- Using map | ||
+ | parity list = map even list | ||
</ | </ |
cs_lang/haskell.1335729946.txt.gz · Last modified: 2012/04/29 22:05 by cedric