-- Computes the factorial of a non-negative number. fac :: Integer -> Integer fac n = if n==0 then 1 else n * fac (n-1) -- Computes the n-th Fibonacci number. Mathematical definition! fib1 :: Int -> Int fib1 n = if n==0 then 0 else if n==1 then 1 else fib1 (n-1) + fib1 (n-2) -- Computes the n-th Fibonacci number. fib2 :: Int -> Int fib2 n = fib2' 0 1 n where -- Computes the n-th Fibonacci number with the n-th and (n-1)-th Fib. number. fib2' :: Int -> Int -> Int -> Int fib2' fibn fibnp1 n = if n==0 then fibn else fib2' fibnp1 (fibn + fibnp1) (n-1) myconst42 = (let x = 10 y = 3 z = y*x in x + z) + 2 -- Check whether a (non-negative) number is a prime number. isPrime :: Int -> Bool isPrime n = n /= 1 && checkPrime (div n 2) where checkPrime d = d==1 || mod n d /= 0 && checkPrime (d-1)