blob: 1918fc8372d2816d4f91418f1deb2dde72d343db (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
-- Point-less fibonacci
fib :: Int -> Int
fib = fix fib'
where
fib' =
ap (when 0 . (0 ==)) .
ap (when 1 . (1 ==)) .
ap (ap . ((+) .) . (. subtract 1)) (. subtract 2)
when t c e = if c then t else e
ap mf m = mf >>= (\f -> m >>= return . f)
fix f = f (fix f)
main :: IO ()
main = mapM_ (print . fib) [0 .. 10]
|