User Tools

Site Tools


cs_lang:haskell

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
cs_lang:haskell [2012/04/29 11:40] cedriccs_lang:haskell [2012/04/30 16:51] (current) – [Caeser cipher] cedric
Line 2: Line 2:
 ===== Paradigm ===== ===== Paradigm =====
   * purely-functional;   * purely-functional;
-  * lazy evaluation+  * lazy evaluation.
  
 ===== Typing discipline ===== ===== Typing discipline =====
-  * Unordered List Item 
   * static typed;   * static typed;
-  * strong types+  * strongly typed
-  * inferred; +  * inferred. 
-  * lazy evaluation;+
  
 ====== Learning Haskell ====== ====== Learning Haskell ======
  
-  * [[The Haskell Programming Language | http://www.haskell.org/]]+  * [[http://www.haskell.org/ | The Haskell Programming Language]] 
 + 
 + 
 +====== Simple examples ====== 
 + 
 +You can compare functions below with the [[cs_lang:ocaml#simple_examples | Objective Caml]] version. 
 + 
 +===== Increment a number ===== 
 +<code haskell> 
 +let inc = (+) n 
 + 
 +-- Alternative: 
 +let inc n = succ n 
 +</code> 
 + 
 + 
 +===== Caesar cipher ===== 
 + 
 +<code haskell> 
 +-- 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 
 +</code> 
 + 
 + 
 +===== 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 
 +</code>
cs_lang/haskell.1335692412.txt.gz · Last modified: 2012/04/29 11:40 by cedric