Reputation: 12107
from the documentation at https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/keyword-reference:
it looks like 'and' can be used in the four categories above. With records and constraints, I see the use cases. But can anyone illustrate the uses in let bindings and members?
I see an example in this gist: https://gist.github.com/theburningmonk/3199252 but I'm not sure how it works.
Upvotes: 7
Views: 1498
Reputation: 243061
For let bindings and members, the and
keyword is used for definining mutually recursive types and functions. A silly example with functions:
let rec f x = g x + 1
and g x = f x - 1
A silly example with classes:
type A() =
member x.B = B()
and B() =
member x.A = A()
The case with classes really covers all possible type definitions, including records and discriminated unions:
type A =
| Aaa of int
| Aaaa of C
and C =
{ Bbb : B }
and B() =
member x.Bbb = Aaa 10
Upvotes: 9