I am trying out the following code in F# interactive and getting ‘error FS0001: the type ‘int -> int’ does not match the type ‘int’. Here is the code I am trying
> let rec factorial n = function
| 0 -> 1
| n -> n * factorial (n - 1);;
This is off of ‘F3 for scientist’ book example.
Thanks,
As you’ve defined it,
factorialtakes two arguments, but you’re only passing it one. Consequently, the second branch of the function is trying to multiply anintwith a partially applied function of typeint -> int.The first line should read
(sans
n).