Tuesday, September 20, 2005

Haskell sample

About haskell haskell.org
-----------------
len :: [a] -> Int
len []
= 0
len (a : rest)
= 1 + len rest
-----------------
everyThird :: [Char] -> Int
everyThird [] = []
everyThird (x:y:z:xs) = x : everyThird xs
everyThird (x:y:xs) = []
everyThird (x:xs) = []
-- Um, whouldn't these be ambiguous? [1,2,3] ought to match x:xs and x:y:xs and x:y:z:xs, cxu ne?
-- Result of everyThird "classroom" : "arm"
-----------------
To load a file: :l filename.hs
To get the type of something: :t 123
output: 123.0 :: Int

0 Comments:

Post a Comment

<< Home