-- Below, are four different ways to implement this infinite corecursive sequence: -- https://en.wikipedia.org/wiki/Fibonacci_sequence -- | if then else -- >>> fibIf 10 -- 89 fibIf :: Int -> Int fibIf x = if x == 1 then 1 else if x == 2 then 2 else fibIf (x - 1) + fibIf (x - 2) -- | Guards -- >>> fibGuard 10 -- 89 fibGuard :: Int -> Int fibGuard x | x == 1 = 1 | x == 2 = 2 | otherwise = fibGuard (x - 1) + fibGuard (x - 2) -- | Actual case -- >>> fibCase 10 -- 89 fibCase :: Int -> Int fibCase x = case x of 1 -> 1 2 -> 2 x -> fibCase (x - 1) + fibCase (x - 2) -- | Syntantic sugar for case -- >>> fibOverload 10 -- 89 fibOverload :: Int -> Int fibOverload 1 = 1 fibOverload 2 = 2 fibOverload x = fibOverload (x - 1) + fibOverload (x - 2)