Skip to content

Instantly share code, notes, and snippets.

@serjKim
Last active February 16, 2020 13:27
Show Gist options
  • Save serjKim/c2c2f6ceef90be8352f9da2a0a64a85e to your computer and use it in GitHub Desktop.
Save serjKim/c2c2f6ceef90be8352f9da2a0a64a85e to your computer and use it in GitHub Desktop.
F#: SRTP + AP
let inline (|HasLength|) x =
fun () -> (^a: (member Length: int) fst x)
let inline (|HasMethod|) x =
fun () -> (^a: (member Method: int with get) snd x)
let inline length (HasLength f1 & HasMethod f2) =
let a = f1()
let b = f2()
a + b
type IMethod =
abstract member Method : int with get
let o =
{ new IMethod with member x.Method = 1 }
printfn "%A" (length ([1], o))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment