Created
January 22, 2014 16:22
-
-
Save palladin/8561783 to your computer and use it in GitHub Desktop.
My Favorite Active Pattern
This file contains hidden or 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
let (|Named|Array|Ptr|Param|) (t : System.Type) = | |
if t.IsGenericType | |
then Named(t.GetGenericTypeDefinition(), t.GetGenericArguments()) | |
elif t.IsGenericParameter | |
then Param(t.GenericParameterPosition) | |
elif not t.HasElementType | |
then Named(t, [| |]) | |
elif t.IsArray | |
then Array(t.GetElementType(), t.GetArrayRank()) | |
elif t.IsByRef | |
then Ptr(true, t.GetElementType()) | |
elif t.IsPointer | |
then Ptr(false, t.GetElementType()) | |
else failwith "MSDN says this can’t happen" |
Yes check this https://github.com/palladin/LinqOptimizer/blob/gpu/LinqOptimizer.Core/ExpressionHelpers.fs
for a partial list of LINQ active patterns.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Active patterns are also great to match .Net AST for Linq !