-- Computes the square of a number. square :: Int -> Int square x = x * x -- Computes the mininmum of two numbers. mini :: Int -> Int -> Int mini x y = if x <= y then x else y -- Computes the factorial of a number. fac :: Int -> Int fac n = if n == 0 then 1 else fac (n - 1) * n {- fac 2 = if 2 == 0 then 1 else fac (2 - 1) * 2 = if False then 1 else fac (2 - 1) * 2 = fac (2 - 1) * 2 = fac 1 * 2 = (if 1 == 0 then 1 else fac (1 - 1) * 1) * 2 = (if False then 1 else fac (1 - 1) * 1) * 2 = (fac (1 - 1) * 1) * 2 = (fac 0 * 1) * 2 ... = (1 * 1) * 2 = 1 * 2 = 2 -} -- Computes the n-th Fibonacci number fib1 :: Int -> Int fib1 n = if n == 0 then 0 else if n == 1 then 1 else fib1 (n - 1) + fib1 (n - 2)