I was faced today with the following DUs declarations:
type Grammar = Definition list
and Definition = Def of string * Expression
and Range =
| Char of char
| Range of char * char
Why would one use the keyword and instead of type, here?
The
andis needed for the definitions ofGrammarandDefinitionto compile correctly. TheGrammartype is listed first but depends on the typeDefinitionwhich is defined later. In order to compile properly it must be linked withandwhich tells the F# compiler the type definitions are dependent / related.There is no reason for
Rangeto be declared in such a way and should be declared withtype