How does the typical type β€œT” evade this code of Don Shime?

let compareOn fx (yobj: obj) = match yobj with | :? 'T as y -> compare (fx) (fy) | _ -> invalidArg "yobj" "cannot compare values of different types" 

I don't see how the above applies to type x. Why isn't type x just 'a ?

Used in:

 type stamp = int [<CustomEquality; CustomComparison>] type MyUnionType = | MyUnionType of stamp * (int -> int) static member Stamp (MyUnionType (s,_)) = s override x.Equals y = equalsOn MyUnionType.Stamp xy override x.GetHashCode() = hashOn MyUnionType.Stamp x interface System.IComparable with member x.CompareTo y = compareOn MyUnionType.Stamp xy 
+4
source share
1 answer

Reason for using x . The x and y values ​​are used as arguments for the same callback: fx and fy . The type y in this expression is known as T , so x must also be of type compatible with T , so F # chooses T

+5
source

Source: https://habr.com/ru/post/1399426/


All Articles