Skip to content

Instantly share code, notes, and snippets.

@ForNeVeR
Last active November 30, 2023 09:48
Show Gist options
  • Save ForNeVeR/135addb5c95faaba80e8a122dcaf7392 to your computer and use it in GitHub Desktop.
Save ForNeVeR/135addb5c95faaba80e8a122dcaf7392 to your computer and use it in GitHub Desktop.

Revisions

  1. ForNeVeR revised this gist Aug 1, 2020. 1 changed file with 3 additions and 7 deletions.
    10 changes: 3 additions & 7 deletions Zombify.fs
    Original file line number Diff line number Diff line change
    @@ -4,15 +4,11 @@ let mutable debug = true

    type T = T with
    static member inline ($) (T, arg: unit) = ()
    static member inline ($) (T, arg: int) = 0
    let inline zombify a : 'r = T $ a

    type T with
    static member inline ($) (T, arg: int) = 0 // mandatory second terminal case; is unused in runtime but is required for the code to compile
    static member inline ($) (T, func: ^a -> ^b): ^a -> ^b =
    fun (_: 'a) -> zombify Unchecked.defaultof<'b>
    fun (_: 'a) -> T $ Unchecked.defaultof<'b>

    let inline negate(): 'a =
    // printfn "%A" <| typeof<'a>
    T $ Unchecked.defaultof<'a>

    let inline debugLog format =
    @@ -25,7 +21,7 @@ let inline debugLog format =

    [<EntryPoint>]
    let main _ =
    debug <- true
    debug <- false
    debugLog "This: %s" "foo"
    debugLog "That: %d - %d = %d" 2 2 4
    debugLog "Invisible! %s" "haha"
  2. ForNeVeR revised this gist Aug 1, 2020. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions Zombify.fs
    Original file line number Diff line number Diff line change
    @@ -12,10 +12,10 @@ type T with
    fun (_: 'a) -> zombify Unchecked.defaultof<'b>

    let inline negate(): 'a =
    printfn "%A" <| typeof<'a>
    // printfn "%A" <| typeof<'a>
    T $ Unchecked.defaultof<'a>

    let debugLog format =
    let inline debugLog format =
    if debug then
    Printf.kprintf (
    printfn "%A: %s" DateTime.Now
    @@ -25,10 +25,10 @@ let debugLog format =

    [<EntryPoint>]
    let main _ =
    debug <- false
    // debugLog "This: %s" "foo"
    debug <- true
    debugLog "This: %s" "foo"
    debugLog "That: %d - %d = %d" 2 2 4
    // debugLog "Invisible! %s" "haha"
    // debug <- true
    // debugLog "Visible"
    debugLog "Invisible! %s" "haha"
    debug <- true
    debugLog "Visible"
    0
  3. ForNeVeR created this gist Aug 1, 2020.
    34 changes: 34 additions & 0 deletions Zombify.fs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    open System

    let mutable debug = true

    type T = T with
    static member inline ($) (T, arg: unit) = ()
    static member inline ($) (T, arg: int) = 0
    let inline zombify a : 'r = T $ a

    type T with
    static member inline ($) (T, func: ^a -> ^b): ^a -> ^b =
    fun (_: 'a) -> zombify Unchecked.defaultof<'b>

    let inline negate(): 'a =
    printfn "%A" <| typeof<'a>
    T $ Unchecked.defaultof<'a>

    let debugLog format =
    if debug then
    Printf.kprintf (
    printfn "%A: %s" DateTime.Now
    ) format
    else negate()


    [<EntryPoint>]
    let main _ =
    debug <- false
    // debugLog "This: %s" "foo"
    debugLog "That: %d - %d = %d" 2 2 4
    // debugLog "Invisible! %s" "haha"
    // debug <- true
    // debugLog "Visible"
    0