F# syntax of comma within lambda expression

Viewed 84

I'm new to F#. Can someone explain what the following lambda expression is saying? Specifically, what the comma after the Some c.Id is doing and what all the parenthesis are about?

(fun ((b, p), c) -> (b && p.SelectedInnerRow = Some c.Id, c))

I'm a bit confused coming from C#.

Thanks.

1 Answers

The parentheses are for deconstruction of tuples. The lambda expression takes a tuple of (a tuple and some value) and some other value; and it returns yet another tuple.

Now for the types involved - as the argument named b is operand to the boolean operator &&, it must be of type bool. The argument p has to have a property named SelectedInnerRow, which in turn ought to produce an option. This option is equality-compared to another option value of argument c's property Id, so the whole expression will return a tuple of a bool and the unchanged argument c.)

(* Dummy types to make it work *)
type Foo = { SelectedInnerRow : int option }
type Bar = { Id : int }

(fun ((b, p), c) -> (b && p.SelectedInnerRow = Some c.Id, c))
(* val it : _arg1:(bool * Foo) * c:Bar -> bool * Bar *)
Related