I have the following code:
type CapturablePieces = Pawn | Knight | Bishop | Rook | Queen
I can define another type as follows:
type Pieces = Pawn | Knight | Bishop | Rook | Queen | King
However, there is obviously a lot of code repetition here. Is there a way to avoid this by incorporating CapturablePieces
into the definition of Pieces
?
In formal writing it is common to avoid repeating a verb phrase by using the appropriate form of do + so: The charity converted several disused car parks into winter soup kitchens. When it had done so, it was able to provide daily meals for more than 200 people.
If you don't need CapturablePieces to be separable type, just some subset of particular cases, maybe it can be implemented as member? I can think of two ways:
a) Collection of capturable pieces in static member:
type Pieces = Pawn | Knight | Bishop | Rook | Queen | King
static member Capturable = [Pawn; Knight; Bishop; Rook; Queen]
b) Boolean member:
type Pieces = Pawn | Knight | Bishop | Rook | Queen | King
member x.IsCapturable = match x with King -> false | _ -> true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With