How to make a F# discriminated union out of another type's union cases? -
imagine discriminated union:
type direction = | north | south | east | west
now imagine want type accepts tuples of (north, south) or (east, west). perhaps describe train routes run north south, or east west. (north, east) , (south, west) should forbidden, perhaps because trains don't run that.
this doesn't work:
type trainlines = | north, south | east, west
even though doesn't work, perhaps can see i'm trying do.
this works, doesn't restrict possibilites (north, south) , (east, west):
type trainlines = direction * direction
any guidance welcomed.
this isn't asked for, think it's
type trainlines = | northsouth | eastwest
would good. if needed add e.g.
member this.directions = match | northsouth -> [north; south] | eastwest -> [east; west]
Comments
Post a Comment