Is reason not support "function" keyword?


I try to do this:

let call = function {
| Some x => x * 2
| None => 0

but it looks not be support. it is work in ml file.

is that true?


@andares I’m new to this too but I’ll take a crack at answering. I believe you are correct, in ReasonML you have to use arrow function syntax. let fun = () => ...

Also () is shorthand for unit type, because all functions need an input type. In your example above (x) => … looks like it function has type: option(int) -> int

I believe it would be confusing to have two different ways to write a function (like there is currently in JS), so in Reason there is only one way.


In Reason we use fun instead of function.

let call = fun
| Some(x) => x * 2
| None => 0

There is an example of this in the Comparison to OCaml section of the docs. Might be good to give that whole section a read through if you’re coming from OCaml.


I wasn’t aware there was a fun keyword. So I think my answer is wrong.
I found this issue:
Which left me thoroughly confused, lol!