Created
June 15, 2018 10:25
-
-
Save gusty/70b1dae708c3ee41ac6f9ceb257264e6 to your computer and use it in GitHub Desktop.
Efficiently constrained isNull
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type A = class end | |
type B = class inherit A end | |
type C = class inherit B end | |
type D = class inherit C end | |
type IsNull = | |
inherit D | |
static member inline ($) (_:A , x :'a when 'a : not struct) = System.Object.ReferenceEquals(x, null) | |
static member inline ($) (_:B , x :'a when 'a : null ) = match x with null -> true | _ -> false | |
static member inline ($) (_:C , _:D) = false | |
static member inline ($) (_:D , _:C) = false | |
let inline isNull x = Unchecked.defaultof<IsNull> $ x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment