RosettaCodeData/Task/Anonymous-recursion/OCaml/anonymous-recursion-1.ocaml

11 lines
154 B
Text
Raw Permalink Normal View History

2013-04-10 22:43:41 -07:00
let fib n =
let rec real = function
0 -> 1
| 1 -> 1
| n -> real (n-1) + real (n-2)
in
if n < 0 then
None
else
Some (real n)