I have a function that generates Fibonacci numbers:
let rec fib n =
match n with
| (0 | 1) -> 1
| x when x > 0 -> (fib (x-2) + fib (x-1))
| _ -> raise (Invalid_argument "Negative value supplied to fib");;
but what I really want is for it to return a list of said numbers. I tried this:
let rec fib n list =
match n with
| (0 | 1) -> 1 :: []
| x when x > 0 -> (fib (x-2) list + fib (x-1) list) :: list
| _ -> raise (Invalid_argument "Negative value supplied to fib");;
But ocamlc says
File "main.ml", line 2, characters 4-174: Error: This expression has type int list but an expression was expected of type int
(Line 2 characters 4-174 corresponds to the match block). I want this to return type "int list", why is it inferring type int?