Created
October 11, 2022 23:08
-
-
Save TheAngryByrd/8a020be6a00d1488e3cb8886e9215796 to your computer and use it in GitHub Desktop.
SRTP-Active-Patterns.fs
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
module NameOps = | |
let inline (|HasName|) x = (^a : (member Name : string) x) | |
let inline (|HasAge|) x = (^a : (member Age : int) x) | |
let inline (|IsIdentifyable|) (HasName name & HasAge age) = name, age | |
let inline doWithIsIdentifyable (IsIdentifyable (name,age)) = | |
printfn $"{name} - {age}" | |
type Dog = { | |
Name : string | |
Age: int | |
FavoriteChewToy : string | |
} | |
type Cat = { | |
Name : string | |
Age : int | |
FeedingTime : System.DateTime | |
} | |
let dog = { | |
Name = "Fido" | |
Age = 3 | |
FavoriteChewToy = "My shoes" | |
} | |
let cat = { | |
Name = "Mr Muffin" | |
Age = 30 | |
FeedingTime = System.DateTime.Now | |
} | |
NameOps.doWithIsIdentifyable dog | |
NameOps.doWithIsIdentifyable cat |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment