2

Case in point, the unary negative operator implementation in prim-types.fs on Github:

[<NoDynamicInvocation>]
let inline (~-) (x: ^T) : ^T = 
    (^T : (static member (~-) : ^T -> ^T) (x))
     when ^T : int32     = (# "neg" x  : int32 #)
     when ^T : float     = (# "neg" x  : float #)
     when ^T : float32   = (# "neg" x  : float32 #)
     when ^T : int64     = (# "neg" x  : int64 #)
     when ^T : int16     = (# "neg" x  : int16 #)
     when ^T : nativeint = (# "neg" x  : nativeint #)
     when ^T : sbyte     = (# "neg" x  : sbyte #)
     when ^T : decimal   = (# "" (System.Decimal.op_UnaryNegation((# "" x : decimal #))) : ^T #)
Brad Collins
  • 846
  • 9
  • 18

0 Answers0