Skip to content

Instantly share code, notes, and snippets.

@Luiz-Monad
Created December 22, 2020 22:03
Show Gist options
  • Save Luiz-Monad/81128d3fab689af3954025a071c8dbf7 to your computer and use it in GitHub Desktop.
Save Luiz-Monad/81128d3fab689af3954025a071c8dbf7 to your computer and use it in GitHub Desktop.
FSharp custom equality overload
type Equality =
static member inline Mk = Unchecked.defaultof<Equality>
static member inline Eq (x: T1, y: T1) = (x.String = y.String)
static member inline Eq (x: T2, y: T2) = (x.Array = y.Array)
let inline liftEquals (c: ^C) x y =
let inline call (_: ^C, x: ^X, y: ^Y) =
((^C or ^X or ^Y): (static member Eq: 'X * 'Y -> bool) (x, y))
call (c, x, y)
let inline (=) x y = liftEquals Equality.Mk x y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment