Last active
December 2, 2022 20:58
-
-
Save voronoipotato/a6a85ec47991a2a245652ad8d7a1be23 to your computer and use it in GitHub Desktop.
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
// 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