-- Factorial function with conditional: facif :: Integer -> Integer facif n = if n == 0 then 1 else n * facif (n - 1) add1 :: Int -> Int -> Int add1 x y = x + y add2 :: Int -> (Int -> Int) add2 x = \y -> x + y add3 :: (Int,Int) -> Int add3 (x,y) = x + y -- Own data types: algebraic data types: enumeration all constructors -- Constructors: define the actual data -- data Tau = C1 tau11 ... t1n_1 | ... | Ck tauk1 ... tkn_k -- Enumeration types: --data Bool = False | True data Color = Blue | Green | Yellow -- Record types: data Complex = Complex Float Float -- Variant records: Integer lists data IntList = Nil | Cons Int IntList list123 :: IntList list123 = Cons 1 (Cons 2 (Cons 3 Nil)) -- Binary integer trees: data IntTree = Leaf Int | Node IntTree IntTree tree123 :: IntTree tree123 = Node (Leaf 1) (Node (Leaf 2) (Leaf 3)) addLeaves :: IntTree -> Int addLeaves (Leaf n) = n addLeaves (Node t1 t2) = addLeaves t1 + addLeaves t2