Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbb40a68

Browse files
pirrmannlatkin
authored andcommitted
Add an active pattern to match constant decimal in quotations
commit 45aed39c90ac5799c92ab73be3a558074caec37bAuthor: latkin <latkin@microsoft.com>Date: Mon Dec 15 12:12:39 2014 -0800 Updating portable surface area testcommit 64d3c0d84ae220569034bc19b5ea1b8b4f541516Merge:47aff4d 55b7abaAuthor: latkin <latkin@microsoft.com>Date: Mon Dec 15 12:06:02 2014 -0800 Merge branch 'fsharp4' ofhttps://git01.codeplex.com/forks/veritax/fsharp into decimalcommit 55b7aba7996424418b68c9e5eede03afb41cc697Author: Pierre IRRMANN <pierre.irrmann@gmail.com>Date: Fri Nov 7 13:38:40 2014 +0100 Not using the SpecificCall pattern anymorecommit 30d609727d1f0d1a9b70fa7ad5825b07f46b1633Author: Pierre IRRMANN <pierre.irrmann@gmail.com>Date: Thu Oct 23 06:41:22 2014 +0200 New test to prove the previously incorrect implementation, and fixcommit 46cdf51905c1fbab4a26726cde19662ab66611beAuthor: Pierre IRRMANN <pierre.irrmann@gmail.com>Date: Fri Oct 17 22:29:11 2014 +0200 Add an active pattern to match constant decimal in quotations
1 parent47aff4d commitbb40a68

File tree

5 files changed

+43
-20
lines changed

5 files changed

+43
-20
lines changed

‎src/fsharp/FSharp.Core.Unittests/SurfaceArea.4.0.fs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3208,6 +3208,7 @@ Microsoft.FSharp.Quotations.DerivedPatternsModule: Microsoft.FSharp.Core.FSharpO
32083208
Microsoft.FSharp.Quotations.DerivedPatternsModule: Microsoft.FSharp.Core.FSharpOption`1[System.Boolean] BoolPattern(Microsoft.FSharp.Quotations.FSharpExpr)
32093209
Microsoft.FSharp.Quotations.DerivedPatternsModule: Microsoft.FSharp.Core.FSharpOption`1[System.Byte] BytePattern(Microsoft.FSharp.Quotations.FSharpExpr)
32103210
Microsoft.FSharp.Quotations.DerivedPatternsModule: Microsoft.FSharp.Core.FSharpOption`1[System.Char] CharPattern(Microsoft.FSharp.Quotations.FSharpExpr)
3211+
Microsoft.FSharp.Quotations.DerivedPatternsModule: Microsoft.FSharp.Core.FSharpOption`1[System.Decimal] DecimalPattern(Microsoft.FSharp.Quotations.FSharpExpr)
32113212
Microsoft.FSharp.Quotations.DerivedPatternsModule: Microsoft.FSharp.Core.FSharpOption`1[System.Double] DoublePattern(Microsoft.FSharp.Quotations.FSharpExpr)
32123213
Microsoft.FSharp.Quotations.DerivedPatternsModule: Microsoft.FSharp.Core.FSharpOption`1[System.Int16] Int16Pattern(Microsoft.FSharp.Quotations.FSharpExpr)
32133214
Microsoft.FSharp.Quotations.DerivedPatternsModule: Microsoft.FSharp.Core.FSharpOption`1[System.Int32] Int32Pattern(Microsoft.FSharp.Quotations.FSharpExpr)

‎src/fsharp/FSharp.Core.Unittests/SurfaceArea.Portable.fs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3186,6 +3186,7 @@ Microsoft.FSharp.Quotations.DerivedPatternsModule: Microsoft.FSharp.Core.FSharpO
31863186
Microsoft.FSharp.Quotations.DerivedPatternsModule: Microsoft.FSharp.Core.FSharpOption`1[System.Boolean] BoolPattern(Microsoft.FSharp.Quotations.FSharpExpr)
31873187
Microsoft.FSharp.Quotations.DerivedPatternsModule: Microsoft.FSharp.Core.FSharpOption`1[System.Byte] BytePattern(Microsoft.FSharp.Quotations.FSharpExpr)
31883188
Microsoft.FSharp.Quotations.DerivedPatternsModule: Microsoft.FSharp.Core.FSharpOption`1[System.Char] CharPattern(Microsoft.FSharp.Quotations.FSharpExpr)
3189+
Microsoft.FSharp.Quotations.DerivedPatternsModule: Microsoft.FSharp.Core.FSharpOption`1[System.Decimal] DecimalPattern(Microsoft.FSharp.Quotations.FSharpExpr)
31893190
Microsoft.FSharp.Quotations.DerivedPatternsModule: Microsoft.FSharp.Core.FSharpOption`1[System.Double] DoublePattern(Microsoft.FSharp.Quotations.FSharpExpr)
31903191
Microsoft.FSharp.Quotations.DerivedPatternsModule: Microsoft.FSharp.Core.FSharpOption`1[System.Int16] Int16Pattern(Microsoft.FSharp.Quotations.FSharpExpr)
31913192
Microsoft.FSharp.Quotations.DerivedPatternsModule: Microsoft.FSharp.Core.FSharpOption`1[System.Int32] Int32Pattern(Microsoft.FSharp.Quotations.FSharpExpr)

‎src/fsharp/FSharp.Core/quotations.fs‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2029,7 +2029,19 @@ module DerivedPatterns =
20292029
|_-> None)
20302030
|_->
20312031
invalidArg"templateParameter"(SR.GetString(SR.QunrecognizedMethodCall))
2032-
2032+
2033+
letprivatenew_decimal_info=
2034+
methodhandleof(fun(low,medium,high,isNegative,scale)-> LanguagePrimitives.IntrinsicFunctions.MakeDecimal low medium high isNegative scale)
2035+
|> System.Reflection.MethodInfo.GetMethodFromHandle
2036+
:?> MethodInfo
2037+
2038+
[<CompiledName("DecimalPattern")>]
2039+
let(|Decimal|_|)=function
2040+
| Call(None, mi,[Int32 low; Int32 medium; Int32 high; Bool isNegative; Byte scale])
2041+
when mi.Name= new_decimal_info.Name
2042+
&& mi.DeclaringType.FullName= new_decimal_info.DeclaringType.FullName->
2043+
Some(LanguagePrimitives.IntrinsicFunctions.MakeDecimal low medium high isNegative scale)
2044+
|_-> None
20332045

20342046
[<CompiledName("MethodWithReflectedDefinitionPattern")>]
20352047
let(|MethodWithReflectedDefinition|_|)(minfo)=

‎src/fsharp/FSharp.Core/quotations.fsi‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,11 @@ module DerivedPatterns =
627627
/// <returns>uint64 option</returns>
628628
[<CompiledName("UInt64Pattern")>]
629629
val(|UInt64|_|):input:Expr->uint64 option
630+
/// <summary>An active pattern to recognize constant decimal expressions</summary>
631+
/// <param name="input">The input expression to match against.</param>
632+
/// <returns>decimal option</returns>
633+
[<CompiledName("DecimalPattern")>]
634+
val(|Decimal|_|):input:Expr->decimal option
630635
/// <summary>A parameterized active pattern to recognize calls to a specified function or method.
631636
/// The returned elements are the optional target object (present if the target is an
632637
/// instance method), the generic type instantation (non-empty if the target is a generic

‎tests/fsharp/core/quotes/test.fsx‎

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -68,25 +68,29 @@ module TypedTest = begin
6868

6969
letx=<@1@>
7070

71-
test"check SByte"((<@1y@>|>(function SByte1y->true|_->false)))
72-
test"check Int16"((<@1s@>|>(function Int161s->true|_->false)))
73-
test"check Int32"((<@1@>|>(function Int321->true|_->false)))
74-
test"check Int64"((<@1L@>|>(function Int641L->true|_->false)))
75-
test"check Byte"((<@1uy@>|>(function Byte1uy->true|_->false)))
76-
test"check UInt16"((<@1us@>|>(function UInt161us->true|_->false)))
77-
test"check UInt32"((<@1u@>|>(function UInt321u->true|_->false)))
78-
test"check UInt64"((<@1UL@>|>(function UInt641UL->true|_->false)))
79-
test"check String"((<@"1"@>|>(function String"1"->true|_->false)))
80-
81-
test"check ~SByte"((<@"1"@>|>(function SByte_->false|_->true)))
82-
test"check ~Int16"((<@"1"@>|>(function Int16_->false|_->true)))
83-
test"check ~Int32"((<@"1"@>|>(function Int32_->false|_->true)))
84-
test"check ~Int64"((<@"1"@>|>(function Int64_->false|_->true)))
85-
test"check ~Byte"((<@"1"@>|>(function Byte_->false|_->true)))
86-
test"check ~UInt16"((<@"1"@>|>(function UInt16_->false|_->true)))
87-
test"check ~UInt32"((<@"1"@>|>(function UInt32_->false|_->true)))
88-
test"check ~UInt64"((<@"1"@>|>(function UInt64_->false|_->true)))
89-
test"check ~String"((<@1@>|>(function String"1"->false|_->true)))
71+
test"check SByte"((<@1y@>|>(function SByte1y->true|_->false)))
72+
test"check Int16"((<@1s@>|>(function Int161s->true|_->false)))
73+
test"check Int32"((<@1@>|>(function Int321->true|_->false)))
74+
test"check Int64"((<@1L@>|>(function Int641L->true|_->false)))
75+
test"check Byte"((<@1uy@>|>(function Byte1uy->true|_->false)))
76+
test"check UInt16"((<@1us@>|>(function UInt161us->true|_->false)))
77+
test"check UInt32"((<@1u@>|>(function UInt321u->true|_->false)))
78+
test"check UInt64"((<@1UL@>|>(function UInt641UL->true|_->false)))
79+
test"check Decimal"((<@1M@>|>(function Decimal1M->true|_->false)))
80+
test"check String"((<@"1"@>|>(function String"1"->true|_->false)))
81+
82+
test"check ~SByte"((<@"1"@>|>(function SByte_->false|_->true)))
83+
test"check ~Int16"((<@"1"@>|>(function Int16_->false|_->true)))
84+
test"check ~Int32"((<@"1"@>|>(function Int32_->false|_->true)))
85+
test"check ~Int64"((<@"1"@>|>(function Int64_->false|_->true)))
86+
test"check ~Byte"((<@"1"@>|>(function Byte_->false|_->true)))
87+
test"check ~UInt16"((<@"1"@>|>(function UInt16_->false|_->true)))
88+
test"check ~UInt32"((<@"1"@>|>(function UInt32_->false|_->true)))
89+
test"check ~UInt64"((<@"1"@>|>(function UInt64_->false|_->true)))
90+
test"check ~Decimal"((<@"1"@>|>(function Decimal_->false|_->true)))
91+
test"check ~String"((<@1@>|>(function String"1"->false|_->true)))
92+
93+
test"check ~Decimal neither"((<@1M+1M@>|>(function Decimal_->false|_->true)))
9094

9195
test"check AndAlso"((<@true&&true@>|>(function AndAlso(Bool(true),Bool(true))->true|_->false)))
9296
test"check OrElse"((<@true||true@>|>(function OrElse(Bool(true),Bool(true))->true|_->false)))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp