Having a custom variant type as below:
type yolo =
| A of string
| B of yolo
| C of yolo * yolo
| D of yolo * yolo
I also have a function that performs some operations on instances of yolo similar to this:
let rec swag y =
match y with
| A _ -> 1
| B _ -> 2
| C (left,right) -> (swag left) + (swag right)
| D (left,right) -> (swag left) + (swag right)
Since operations for cases C and D are exactly the same I would like to merge them, is it possible?
A pattern like
pat1 | pat2matches either of the two patterns:Naturally the two patterns must bind the same names (left and right in this case) with the same types.