RosettaCodeData/Task/Anonymous-recursion/Haskell/anonymous-recursion-2.hs

7 lines
170 B
Haskell
Raw Permalink Normal View History

2013-04-10 14:58:50 -07:00
import Data.Function (fix)
fib :: Integer -> Maybe Integer
fib n
| n < 0 = Nothing
| otherwise = Just $ fix (\f -> (\n -> if n > 1 then f (n-1) + f (n-2) else 1)) n