fun x -> match x with
| None -> 0
| Some y -> y
What exactly is “y”? I understand that it has to be an int because the return types must match, and 0 is an int. But is y just a place holder?
fun x -> match x with
| None -> 0
| Some y -> y
What exactly is “y”? I understand that it has to be an int because the return types must match, and 0 is an int. But is y just a place holder?
It’s called a ‘binding’. It is bound to a value–whatever value is in the Some
constructor–and is then brought into scope after the ->
.
Yes, y
in Some y
you can imagine it as a placeholder. Actually in the exact same way as the x
in fun x
: a value will be bound to that name in the following body of code.