-- Factorial function: fac :: Int -> Int fac n = if n == 0 then 1 else n * fac (n-1) (++) :: [a] -> [a] -> [a] [] ++ ys = ys (x:xs) ++ ys = x : (xs ++ ys) test1234 = [1,2] ++ [3,4] -- Computing the last element of a list: the logic programming way last :: Eq a => [a] -> a last xs | _ ++ [x] == xs = x where x free -- Functional pattern: last' (_ ++ [x]) = x -- Computation permutations via functional patterns perm [] = [] perm (xs ++ [x] ++ ys) = x : perm (xs ++ ys)