Skip to content

Instantly share code, notes, and snippets.

@voronoipotato
Last active December 2, 2022 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save voronoipotato/a6a85ec47991a2a245652ad8d7a1be23 to your computer and use it in GitHub Desktop.
Save voronoipotato/a6a85ec47991a2a245652ad8d7a1be23 to your computer and use it in GitHub Desktop.
// Link: http://fssnip.net/7U0
// Posted: 5 years ago
// Author: Evgeniy Andreev
// Tags: #active patterns , #srtp
let inline (|HasLength|) x =
fun () -> (^a: (member Length: int) x)
// `this` is optional here, just for demonstration of `as` pattern
let inline length (HasLength f as this) = f()
// It works!
let foo = length [1; 2; 3]
let bar = length [|1; 2; 3|]
//vopo, alternative approach
let inline length' x = (^a : (member Length:int) x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment