Use of the and keyword in F# in discriminated unions

前端 未结 2 842
说谎
说谎 2021-02-13 02:38

I was faced today with the following DUs declarations:

type Grammar = Definition list

and  Definition = Def of string * Expression

and  Range =
     | Char  of         


        
2条回答
  •  既然无缘
    2021-02-13 03:01

    The and is needed for the definitions of Grammar and Definition to compile correctly. The Grammar type is listed first but depends on the type Definition which is defined later. In order to compile properly it must be linked with and which tells the F# compiler the type definitions are dependent / related.

    There is no reason for Range to be declared in such a way and should be declared with type

提交回复
热议问题