0

I know that discriminated unions can refer to themselves, e.g.

type Tree=
    | Node of Tree
    | Leaf

but is there any means to refer to other cases in the type signatures? Both of the following raise errors that "The type 'Year' is not defined" & "The type 'Month' is not defined"

type Period =
    | Year of int
    | Month of Year * int
    | Day of Month * int
type Period' =
    | Year of int
    | Month of Period'.Year * int
    | Day of Period'.Month * int

Is there some form of annotation or a keyword I've yet to encounter (analogous to rec) that would permit such a usage?

Ghillie Dhu
  • 203
  • 2
  • 9

1 Answers1

4

I think you are confused about what constitutes a union case. You cannot reference a union case as a type. I think what you're looking for is single case DUs like this:

type Year = Year of int
type Month = | Month of Year * int
type Day = Month * int
type Period =
  | Year of Year
  | Month of Month
  | Day of Day
N_A
  • 19,387
  • 4
  • 47
  • 95