How to make a function that checks if the labels of discriminatory unions match?

Say we have a union type in F #:

type Example = |FirstLabel of int |SecondLabel of int |ThirdLabel of int 

How could you create a function that takes 2 parameters of the Example type and returns true if two parameters have the same label and then returns false? I want this function to return these results regardless of the value of integers.

So, if we have parameter1 and parameter2 with

 val parameter1 : Example = SecondLabel 2 

and

 val parameter2 : Example = Secondlabel 5 

function will return true

I could not find the answer to this question, even having carefully studied it. Perhaps I searched the wrong way. So could you also give me a source to solve such problems?

+6
source share
1 answer
 let sameLabels xy = match x, y with | FirstLabel _ , FirstLabel _ | SecondLabel _, SecondLabel _ | ThirdLabel _ , ThirdLabel _ -> true | _ -> false 
+7
source

All Articles