examplePair :: (Double, Bool) examplePair = (3.14, False) exampleTriple :: (Bool, Int, String) exampleTriple = (False, 42, "Answer") exampleFunction :: (Bool, Int, String) -> Bool exampleFunction (b,n,s) = not b && length s < n
A
[A]
A
[Integer]
Integer
[A]
[]
x:xs
x
A
xs
[A]
x
xs
[Integer]
42 : []
42 : 9
1 : (2 : [])
1:(2:(3:[]))
1:2:3:[]
[1,2,3]
[1,2] ++ [3]
[1..3]
['a'..'z']
summary :: [String] -> String summary [] = "Nothing" summary [x] = "Just "++x summary [x,y] = x++" and "++y summary _ = "Several things"
_
-- doubles [3,6,10] = [6,12,20]
doubles :: [Integer] -> [Integer]
doubles [] = (...)
doubles (x:xs) = (...)
-- doubles [3,6,10] = [6,12,20] doubles :: [Integer] -> [Integer] doubles [] = [] doubles (x:xs) = 2*x : doubles xs
-- map f [x1,x2,...,xn] = [f x1,f x2,...,f cn]
map f [] = ...
map f (x:xs) = ...
-- map f [x1,x2,...,xn] = [f x1,f x2,...,f cn]
map f [] = []
map f (x:xs) = f x : map f xs
filter even [1..9] == [2,4,6,8]
filter :: (a -> Bool) -> [a] -> [a] filter p [] = [] filter p (x:xs) | p x = x : filter p xs | otherwise = filter p xs
[2*n | n <- [10..12]]
[20,22,24]
[3*n | n<- [10..12], even n]
3*n
[10..12]
n
map (3*) (filter even [10..12])
pythag n = [(x,y,z) | x <- [1..n], y <- [x..n], z <- [y..n], x^2 + y^2 == z^2]