提交 553fc9bc 编写于 作者: D Don Syme 提交者: GitHub

Align signature/implementation argument names in FSharp.Core (#3531)

* implement check and codefix for mismatched parameters

* apply consistent param names to FSHarp.Core

* undo changes to fst/snd to prevent any codegen changes
上级 8917d88a
......@@ -21,6 +21,9 @@
<CompilingFsLib>true</CompilingFsLib>
<AllowCrossTargeting>true</AllowCrossTargeting>
<FX_NO_LOADER>true</FX_NO_LOADER>
<OtherFlags>$(OtherFlags) --warnon:1182 --compiling-fslib --extraoptimizationloops:1</OtherFlags>
<OtherFlags>$(OtherFlags) --warnon:3218</OtherFlags>
<OtherFlags>$(OtherFlags) --maxerrors:20</OtherFlags>
<OtherFlags>$(OtherFlags) --warnon:1182 --compiling-fslib --maxerrors:20 --extraoptimizationloops:1</OtherFlags>
<OtherFlags Condition="'$(TargetDotnetProfile)' == 'net40'">$(OtherFlags) --compiling-fslib-40</OtherFlags>
</PropertyGroup>
......
......@@ -78,69 +78,68 @@ module Nullable =
open System
[<CompiledName("ToUInt8")>]
let inline uint8 (x:Nullable<_>) = if x.HasValue then Nullable(Operators.byte x.Value) else Nullable()
let inline uint8 (value:Nullable<_>) = if value.HasValue then Nullable(Operators.byte value.Value) else Nullable()
[<CompiledName("ToInt8")>]
let inline int8 (x:Nullable<_>) = if x.HasValue then Nullable(Operators.sbyte x.Value) else Nullable()
let inline int8 (value:Nullable<_>) = if value.HasValue then Nullable(Operators.sbyte value.Value) else Nullable()
[<CompiledName("ToByte")>]
let inline byte (x:Nullable<_>) = if x.HasValue then Nullable(Operators.byte x.Value) else Nullable()
let inline byte (value:Nullable<_>) = if value.HasValue then Nullable(Operators.byte value.Value) else Nullable()
[<CompiledName("ToSByte")>]
let inline sbyte (x:Nullable<_>) = if x.HasValue then Nullable(Operators.sbyte x.Value) else Nullable()
let inline sbyte (value:Nullable<_>) = if value.HasValue then Nullable(Operators.sbyte value.Value) else Nullable()
[<CompiledName("ToInt16")>]
let inline int16 (x:Nullable<_>) = if x.HasValue then Nullable(Operators.int16 x.Value) else Nullable()
let inline int16 (value:Nullable<_>) = if value.HasValue then Nullable(Operators.int16 value.Value) else Nullable()
[<CompiledName("ToUInt16")>]
let inline uint16 (x:Nullable<_>) = if x.HasValue then Nullable(Operators.uint16 x.Value) else Nullable()
let inline uint16 (value:Nullable<_>) = if value.HasValue then Nullable(Operators.uint16 value.Value) else Nullable()
[<CompiledName("ToInt")>]
let inline int (x:Nullable<_>) = if x.HasValue then Nullable(Operators.int x.Value) else Nullable()
let inline int (value:Nullable<_>) = if value.HasValue then Nullable(Operators.int value.Value) else Nullable()
[<CompiledName("ToEnum")>]
let inline enum (x:Nullable< int32 >) = if x.HasValue then Nullable(Operators.enum x.Value) else Nullable()
let inline enum (value:Nullable< int32 >) = if value.HasValue then Nullable(Operators.enum value.Value) else Nullable()
[<CompiledName("ToInt32")>]
let inline int32 (x:Nullable<_>) = if x.HasValue then Nullable(Operators.int32 x.Value) else Nullable()
let inline int32 (value:Nullable<_>) = if value.HasValue then Nullable(Operators.int32 value.Value) else Nullable()
[<CompiledName("ToUInt32")>]
let inline uint32 (x:Nullable<_>) = if x.HasValue then Nullable(Operators.uint32 x.Value) else Nullable()
let inline uint32 (value:Nullable<_>) = if value.HasValue then Nullable(Operators.uint32 value.Value) else Nullable()
[<CompiledName("ToInt64")>]
let inline int64 (x:Nullable<_>) = if x.HasValue then Nullable(Operators.int64 x.Value) else Nullable()
let inline int64 (value:Nullable<_>) = if value.HasValue then Nullable(Operators.int64 value.Value) else Nullable()
[<CompiledName("ToUInt64")>]
let inline uint64 (x:Nullable<_>) = if x.HasValue then Nullable(Operators.uint64 x.Value) else Nullable()
let inline uint64 (value:Nullable<_>) = if value.HasValue then Nullable(Operators.uint64 value.Value) else Nullable()
[<CompiledName("ToFloat32")>]
let inline float32 (x:Nullable<_>) = if x.HasValue then Nullable(Operators.float32 x.Value) else Nullable()
let inline float32 (value:Nullable<_>) = if value.HasValue then Nullable(Operators.float32 value.Value) else Nullable()
[<CompiledName("ToFloat")>]
let inline float (x:Nullable<_>) = if x.HasValue then Nullable(Operators.float x.Value) else Nullable()
let inline float (value:Nullable<_>) = if value.HasValue then Nullable(Operators.float value.Value) else Nullable()
[<CompiledName("ToSingle")>]
let inline single (x:Nullable<_>) = if x.HasValue then Nullable(Operators.float32 x.Value) else Nullable()
let inline single (value:Nullable<_>) = if value.HasValue then Nullable(Operators.float32 value.Value) else Nullable()
[<CompiledName("ToDouble")>]
let inline double (x:Nullable<_>) = if x.HasValue then Nullable(Operators.float x.Value) else Nullable()
let inline double (value:Nullable<_>) = if value.HasValue then Nullable(Operators.float value.Value) else Nullable()
[<CompiledName("ToIntPtr")>]
let inline nativeint (x:Nullable<_>) = if x.HasValue then Nullable(Operators.nativeint x.Value) else Nullable()
let inline nativeint (value:Nullable<_>) = if value.HasValue then Nullable(Operators.nativeint value.Value) else Nullable()
[<CompiledName("ToUIntPtr")>]
let inline unativeint (x:Nullable<_>) = if x.HasValue then Nullable(Operators.unativeint x.Value) else Nullable()
let inline unativeint (value:Nullable<_>) = if value.HasValue then Nullable(Operators.unativeint value.Value) else Nullable()
[<CompiledName("ToDecimal")>]
let inline decimal (x:Nullable<_>) = if x.HasValue then Nullable(Operators.decimal x.Value) else Nullable()
let inline decimal (value:Nullable<_>) = if value.HasValue then Nullable(Operators.decimal value.Value) else Nullable()
[<CompiledName("ToChar")>]
let inline char (x:Nullable<_>) = if x.HasValue then Nullable(Operators.char x.Value) else Nullable()
let inline char (value:Nullable<_>) = if value.HasValue then Nullable(Operators.char value.Value) else Nullable()
namespace Microsoft.FSharp.Linq.RuntimeHelpers
open System
open System.Linq
open System.Collections.Generic
open System.Linq.Expressions
open System.Reflection
......@@ -165,7 +164,6 @@ module LeafExpressionConverter =
// The following is recognized as a LINQ 'member initialization pattern' in a quotation.
let MemberInitializationHelper (_x:'T) : 'T = raise (NotSupportedException "This function should not be called directly")
// The following is recognized as a LINQ 'member initialization pattern' in a quotation.
let NewAnonymousObjectHelper (_x:'T) : 'T = raise (NotSupportedException "This function should not be called directly")
......@@ -180,7 +178,9 @@ module LeafExpressionConverter =
let bindingFlags = BindingFlags.Public ||| BindingFlags.NonPublic
let instanceBindingFlags = BindingFlags.Instance ||| BindingFlags.Public ||| BindingFlags.NonPublic ||| BindingFlags.DeclaredOnly
let isNamedType(typ:Type) = not (typ.IsArray || typ.IsByRef || typ.IsPointer)
let equivHeadTypes (ty1:Type) (ty2:Type) =
isNamedType(ty1) &&
if ty1.IsGenericType then
......@@ -189,6 +189,7 @@ module LeafExpressionConverter =
ty1.Equals(ty2)
let isFunctionType typ = equivHeadTypes typ (typeof<(int -> int)>)
let getFunctionType typ =
if not (isFunctionType typ) then invalidArg "typ" "cannot convert recursion except for function types"
let tyargs = typ.GetGenericArguments()
......@@ -422,24 +423,6 @@ module LeafExpressionConverter =
with
| :? KeyNotFoundException -> invalidOp ("The variable '"+ v.Name + "' was not found in the translation context'")
#if WORKAROUND_FSHARP_2_0_BUG
| :? KeyNotFoundException when v.Name = "this" ->
let message =
"Encountered unxpected variable named 'this'. This might happen because " +
"quotations used in queries can’t contain references to let-bound values in classes unless the quotation literal occurs in an instance member. " +
"If this is the case, workaround by replacing references to implicit fields with references to " +
"local variables, e.g. rewrite\r\n" +
" type Foo() =\r\n" +
" let x = 1\r\n" +
" let bar() = (methodhandleof (fun -> x))\r\n" +
"as: \r\n" +
" type Foo() =\r\n" +
" let x = 1\r\n" +
" let bar() = let x = x in (methodhandleof (fun -> x))\r\n";
NotSupportedException(message) |> raise
#endif
| DerivedPatterns.AndAlso(x1, x2) -> Expression.AndAlso(ConvExprToLinqInContext env x1, ConvExprToLinqInContext env x2) |> asExpr
| DerivedPatterns.OrElse(x1, x2) -> Expression.OrElse(ConvExprToLinqInContext env x1, ConvExprToLinqInContext env x2) |> asExpr
| Patterns.Value(x, ty) -> Expression.Constant(x, ty) |> asExpr
......@@ -659,8 +642,7 @@ module LeafExpressionConverter =
let argsP = ConvExprsToLinq env args
Expression.Call(ConvObjArg env objOpt None, minfo, argsP) |> asExpr
#if NO_CURRIED_FUNCTION_OPTIMIZATIONS
#else
#if !NO_CURRIED_FUNCTION_OPTIMIZATIONS
// f x1 x2 x3 x4 --> InvokeFast4
| Patterns.Application(Patterns.Application(Patterns.Application(Patterns.Application(f, arg1), arg2), arg3), arg4) ->
// TODO: amortize this computation based on f.Type
......@@ -722,8 +704,7 @@ module LeafExpressionConverter =
let argsR = ConvExprsToLinq env args
Expression.Call((null:Expression), methInfo, argsR) |> asExpr
#if NO_PATTERN_MATCHING_IN_INPUT_LANGUAGE
#else
#if !NO_PATTERN_MATCHING_IN_INPUT_LANGUAGE
| Patterns.UnionCaseTest(e, unionCaseInfo) ->
let methInfo = Reflection.FSharpValue.PreComputeUnionTagMemberInfo(unionCaseInfo.DeclaringType, showAll)
let obj = ConvExprToLinqInContext env e
......
此差异已折叠。
此差异已折叠。
......@@ -8,6 +8,8 @@ namespace Microsoft.FSharp.Collections
open Microsoft.FSharp.Core.Operators
open Microsoft.FSharp.Core.Operators.Checked
#nowarn "3218" // mismatch of parameter name where 'count1' --> 'length1' would shadow function in module of same name
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
[<RequireQualifiedAccess>]
module Array2D =
......@@ -24,63 +26,70 @@ namespace Microsoft.FSharp.Collections
[<CompiledName("Length1")>]
let length1 (array: 'T[,]) = (# "ldlen.multi 2 0" array : int #)
[<CompiledName("Length2")>]
let length2 (array: 'T[,]) = (# "ldlen.multi 2 1" array : int #)
[<CompiledName("Base1")>]
let base1 (array: 'T[,]) = array.GetLowerBound(0)
[<CompiledName("Base2")>]
let base2 (array: 'T[,]) = array.GetLowerBound(1)
[<CompiledName("Get")>]
let get (array: 'T[,]) (n:int) (m:int) = (# "ldelem.multi 2 !0" type ('T) array n m : 'T #)
let get (array: 'T[,]) (index1:int) (index2:int) =
(# "ldelem.multi 2 !0" type ('T) array index1 index2 : 'T #)
[<CompiledName("Set")>]
let set (array: 'T[,]) (n:int) (m:int) (x:'T) = (# "stelem.multi 2 !0" type ('T) array n m x #)
let set (array: 'T[,]) (index1:int) (index2:int) (value:'T) =
(# "stelem.multi 2 !0" type ('T) array index1 index2 value #)
[<CompiledName("ZeroCreate")>]
let zeroCreate (n:int) (m:int) =
if n < 0 then invalidArgInputMustBeNonNegative "length1" n
if m < 0 then invalidArgInputMustBeNonNegative "length2" m
(# "newarr.multi 2 !0" type ('T) n m : 'T[,] #)
let zeroCreate (length1: int) (length2: int) =
if length1 < 0 then invalidArgInputMustBeNonNegative "length1" length1
if length2 < 0 then invalidArgInputMustBeNonNegative "length2" length2
(# "newarr.multi 2 !0" type ('T) length1 length2 : 'T[,] #)
[<CompiledName("ZeroCreateBased")>]
let zeroCreateBased (b1:int) (b2:int) (n1:int) (n2:int) =
if (b1 = 0 && b2 = 0) then
let zeroCreateBased (base1:int) (base2:int) (length1:int) (length2:int) =
if (base1 = 0 && base2 = 0) then
#if FX_PORTABLE_OR_NETSTANDARD
zeroCreate n1 n2
zeroCreate length1 length2
#else
// Note: this overload is available on Compact Framework and Silverlight, but not Portable
(System.Array.CreateInstance(typeof<'T>, [|n1;n2|]) :?> 'T[,])
(System.Array.CreateInstance(typeof<'T>, [|length1;length2|]) :?> 'T[,])
#endif
else
(Array.CreateInstance(typeof<'T>, [|n1;n2|],[|b1;b2|]) :?> 'T[,])
(Array.CreateInstance(typeof<'T>, [|length1;length2|],[|base1;base2|]) :?> 'T[,])
[<CompiledName("CreateBased")>]
let createBased b1 b2 n m (x:'T) =
let array = (zeroCreateBased b1 b2 n m : 'T[,])
for i = b1 to b1+n - 1 do
for j = b2 to b2+m - 1 do
array.[i,j] <- x
let createBased base1 base2 length1 length2 (initial:'T) =
let array = (zeroCreateBased base1 base2 length1 length2 : 'T[,])
for i = base1 to base1+length1 - 1 do
for j = base2 to base2+length2 - 1 do
array.[i,j] <- initial
array
[<CompiledName("InitializeBased")>]
let initBased b1 b2 n m f =
let array = (zeroCreateBased b1 b2 n m : 'T[,])
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(f)
for i = b1 to b1+n - 1 do
for j = b2 to b2+m - 1 do
let initBased base1 base2 length1 length2 initializer =
let array = (zeroCreateBased base1 base2 length1 length2 : 'T[,])
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(initializer)
for i = base1 to base1+length1 - 1 do
for j = base2 to base2+length2 - 1 do
array.[i,j] <- f.Invoke(i, j)
array
[<CompiledName("Create")>]
let create n m (x:'T) =
createBased 0 0 n m x
let create length1 length2 (value:'T) =
createBased 0 0 length1 length2 value
[<CompiledName("Initialize")>]
let init n m f =
initBased 0 0 n m f
let init length1 length2 initializer =
initBased 0 0 length1 length2 initializer
[<CompiledName("Iterate")>]
let iter f array =
let iter action array =
checkNonNull "array" array
let count1 = length1 array
let count2 = length2 array
......@@ -88,29 +97,29 @@ namespace Microsoft.FSharp.Collections
let b2 = base2 array
for i = b1 to b1+count1 - 1 do
for j = b2 to b2+count2 - 1 do
f array.[i,j]
action array.[i,j]
[<CompiledName("IterateIndexed")>]
let iteri (f : int -> int -> 'T -> unit) (array:'T[,]) =
let iteri (action : int -> int -> 'T -> unit) (array:'T[,]) =
checkNonNull "array" array
let count1 = length1 array
let count2 = length2 array
let b1 = base1 array
let b2 = base2 array
let f = OptimizedClosures.FSharpFunc<_,_,_,_>.Adapt(f)
let f = OptimizedClosures.FSharpFunc<_,_,_,_>.Adapt(action)
for i = b1 to b1+count1 - 1 do
for j = b2 to b2+count2 - 1 do
f.Invoke(i, j, array.[i,j])
[<CompiledName("Map")>]
let map f array =
let map mapping array =
checkNonNull "array" array
initBased (base1 array) (base2 array) (length1 array) (length2 array) (fun i j -> f array.[i,j])
initBased (base1 array) (base2 array) (length1 array) (length2 array) (fun i j -> mapping array.[i,j])
[<CompiledName("MapIndexed")>]
let mapi f array =
let mapi mapping array =
checkNonNull "array" array
let f = OptimizedClosures.FSharpFunc<_,_,_,_>.Adapt(f)
let f = OptimizedClosures.FSharpFunc<_,_,_,_>.Adapt(mapping)
initBased (base1 array) (base2 array) (length1 array) (length2 array) (fun i j -> f.Invoke(i, j, array.[i,j]))
[<CompiledName("Copy")>]
......
......@@ -28,39 +28,39 @@ namespace Microsoft.FSharp.Collections
let length3 (array: 'T[,,]) = (# "ldlen.multi 3 2" array : int #)
[<CompiledName("Get")>]
let get (array: 'T[,,]) n1 n2 n3 = array.[n1,n2,n3]
let get (array: 'T[,,]) index1 index2 index3 = array.[index1,index2,index3]
[<CompiledName("Set")>]
let set (array: 'T[,,]) n1 n2 n3 x = array.[n1,n2,n3] <- x
let set (array: 'T[,,]) index1 index2 index3 value = array.[index1,index2,index3] <- value
[<CompiledName("ZeroCreate")>]
let zeroCreate (n1:int) (n2:int) (n3:int) =
if n1 < 0 then invalidArgInputMustBeNonNegative "n1" n1
if n2 < 0 then invalidArgInputMustBeNonNegative "n2" n2
if n3 < 0 then invalidArgInputMustBeNonNegative "n3" n3
(# "newarr.multi 3 !0" type ('T) n1 n2 n3 : 'T[,,] #)
let zeroCreate length1 length2 length3 =
if length1 < 0 then invalidArgInputMustBeNonNegative "n1" length1
if length2 < 0 then invalidArgInputMustBeNonNegative "n2" length2
if length3 < 0 then invalidArgInputMustBeNonNegative "n3" length3
(# "newarr.multi 3 !0" type ('T) length1 length2 length3 : 'T[,,] #)
[<CompiledName("Create")>]
let create (n1:int) (n2:int) (n3:int) (x:'T) =
let arr = (zeroCreate n1 n2 n3 : 'T[,,])
for i = 0 to n1 - 1 do
for j = 0 to n2 - 1 do
for k = 0 to n3 - 1 do
arr.[i,j,k] <- x
let create length1 length2 length3 (initial:'T) =
let arr = (zeroCreate length1 length2 length3 : 'T[,,])
for i = 0 to length1 - 1 do
for j = 0 to length2 - 1 do
for k = 0 to length3 - 1 do
arr.[i,j,k] <- initial
arr
[<CompiledName("Initialize")>]
let init n1 n2 n3 f =
let arr = (zeroCreate n1 n2 n3 : 'T[,,])
let f = OptimizedClosures.FSharpFunc<_,_,_,_>.Adapt(f)
for i = 0 to n1 - 1 do
for j = 0 to n2 - 1 do
for k = 0 to n3 - 1 do
let init length1 length2 length3 initializer =
let arr = (zeroCreate length1 length2 length3 : 'T[,,])
let f = OptimizedClosures.FSharpFunc<_,_,_,_>.Adapt(initializer)
for i = 0 to length1 - 1 do
for j = 0 to length2 - 1 do
for k = 0 to length3 - 1 do
arr.[i,j,k] <- f.Invoke(i, j, k)
arr
[<CompiledName("Iterate")>]
let iter f array =
let iter action array =
checkNonNull "array" array
let len1 = length1 array
let len2 = length2 array
......@@ -68,10 +68,10 @@ namespace Microsoft.FSharp.Collections
for i = 0 to len1 - 1 do
for j = 0 to len2 - 1 do
for k = 0 to len3 - 1 do
f array.[i,j,k]
action array.[i,j,k]
[<CompiledName("Map")>]
let map f array =
let map mapping array =
checkNonNull "array" array
let len1 = length1 array
let len2 = length2 array
......@@ -80,29 +80,29 @@ namespace Microsoft.FSharp.Collections
for i = 0 to len1 - 1 do
for j = 0 to len2 - 1 do
for k = 0 to len3 - 1 do
res.[i,j,k] <- f array.[i,j,k]
res.[i,j,k] <- mapping array.[i,j,k]
res
[<CompiledName("IterateIndexed")>]
let iteri f array =
let iteri action array =
checkNonNull "array" array
let len1 = length1 array
let len2 = length2 array
let len3 = length3 array
let f = OptimizedClosures.FSharpFunc<_,_,_,_,_>.Adapt(f)
let f = OptimizedClosures.FSharpFunc<_,_,_,_,_>.Adapt(action)
for i = 0 to len1 - 1 do
for j = 0 to len2 - 1 do
for k = 0 to len3 - 1 do
f.Invoke(i, j, k, array.[i,j,k])
[<CompiledName("MapIndexed")>]
let mapi f array =
let mapi mapping array =
checkNonNull "array" array
let len1 = length1 array
let len2 = length2 array
let len3 = length3 array
let res = (zeroCreate len1 len2 len3 : 'b[,,])
let f = OptimizedClosures.FSharpFunc<_,_,_,_,_>.Adapt(f)
let f = OptimizedClosures.FSharpFunc<_,_,_,_,_>.Adapt(mapping)
for i = 0 to len1 - 1 do
for j = 0 to len2 - 1 do
for k = 0 to len3 - 1 do
......@@ -126,37 +126,37 @@ namespace Microsoft.FSharp.Collections
let length4 (array: 'T[,,,]) = (# "ldlen.multi 4 3" array : int #)
[<CompiledName("ZeroCreate")>]
let zeroCreate (n1:int) (n2:int) (n3:int) (n4:int) =
if n1 < 0 then invalidArgInputMustBeNonNegative "n1" n1
if n2 < 0 then invalidArgInputMustBeNonNegative "n2" n2
if n3 < 0 then invalidArgInputMustBeNonNegative "n3" n3
if n4 < 0 then invalidArgInputMustBeNonNegative "n4" n4
(# "newarr.multi 4 !0" type ('T) n1 n2 n3 n4 : 'T[,,,] #)
let zeroCreate length1 length2 length3 length4 =
if length1 < 0 then invalidArgInputMustBeNonNegative "n1" length1
if length2 < 0 then invalidArgInputMustBeNonNegative "n2" length2
if length3 < 0 then invalidArgInputMustBeNonNegative "n3" length3
if length4 < 0 then invalidArgInputMustBeNonNegative "n4" length4
(# "newarr.multi 4 !0" type ('T) length1 length2 length3 length4 : 'T[,,,] #)
[<CompiledName("Create")>]
let create n1 n2 n3 n4 (x:'T) =
let arr = (zeroCreate n1 n2 n3 n4 : 'T[,,,])
for i = 0 to n1 - 1 do
for j = 0 to n2 - 1 do
for k = 0 to n3 - 1 do
for m = 0 to n4 - 1 do
arr.[i,j,k,m] <- x
let create length1 length2 length3 length4 (initial:'T) =
let arr = (zeroCreate length1 length2 length3 length4 : 'T[,,,])
for i = 0 to length1 - 1 do
for j = 0 to length2 - 1 do
for k = 0 to length3 - 1 do
for m = 0 to length4 - 1 do
arr.[i,j,k,m] <- initial
arr
[<CompiledName("Initialize")>]
let init n1 n2 n3 n4 f =
let arr = (zeroCreate n1 n2 n3 n4 : 'T[,,,])
let f = OptimizedClosures.FSharpFunc<_,_,_,_,_>.Adapt(f)
for i = 0 to n1 - 1 do
for j = 0 to n2 - 1 do
for k = 0 to n3 - 1 do
for m = 0 to n4 - 1 do
let init length1 length2 length3 length4 initializer =
let arr = (zeroCreate length1 length2 length3 length4 : 'T[,,,])
let f = OptimizedClosures.FSharpFunc<_,_,_,_,_>.Adapt(initializer)
for i = 0 to length1 - 1 do
for j = 0 to length2 - 1 do
for k = 0 to length3 - 1 do
for m = 0 to length4 - 1 do
arr.[i,j,k,m] <- f.Invoke(i, j, k, m)
arr
[<CompiledName("Get")>]
let get (array: 'T[,,,]) n1 n2 n3 n4 = array.[n1,n2,n3,n4]
let get (array: 'T[,,,]) index1 index2 index3 index4 = array.[index1,index2,index3,index4]
[<CompiledName("Set")>]
let set (array: 'T[,,,]) n1 n2 n3 n4 x = array.[n1,n2,n3,n4] <- x
let set (array: 'T[,,,]) index1 index2 index3 index4 value = array.[index1,index2,index3,index4] <- value
......@@ -27,10 +27,10 @@ namespace Microsoft.FSharp.Collections
member __.GetHashCode(x) = NonStructuralComparison.hash x
member __.Equals(x, y) = NonStructuralComparison.(=) x y }
let inline FromFunctions hash eq : IEqualityComparer<'T> =
let eq = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(eq)
let inline FromFunctions hasher equality : IEqualityComparer<'T> =
let eq = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(equality)
{ new IEqualityComparer<'T> with
member __.GetHashCode(x) = hash x
member __.GetHashCode(x) = hasher x
member __.Equals(x,y) = eq.Invoke(x,y) }
......
此差异已折叠。
......@@ -29,7 +29,7 @@ module ExtraTopLevelOperators =
| _ -> ()
[<CompiledName("CreateSet")>]
let set l = Collections.Set.ofSeq l
let set elements = Collections.Set.ofSeq elements
let dummyArray = [||]
let inline dont_tail_call f =
......@@ -101,14 +101,14 @@ module ExtraTopLevelOperators =
let dictRefType (l:seq<'Key*'T>) = dictImpl RuntimeHelpers.StructBox<'Key>.Comparer (fun k -> RuntimeHelpers.StructBox k) (fun sb -> sb.Value) l
[<CompiledName("CreateDictionary")>]
let dict (l:seq<'Key*'T>) =
let dict (keyValuePairs:seq<'Key*'T>) =
#if FX_RESHAPED_REFLECTION
if (typeof<'Key>).GetTypeInfo().IsValueType
#else
if typeof<'Key>.IsValueType
#endif
then dictValueType l
else dictRefType l
then dictValueType keyValuePairs
else dictRefType keyValuePairs
let getArray (vals : seq<'T>) =
match vals with
......@@ -142,56 +142,56 @@ module ExtraTopLevelOperators =
// --------------------------------------------------------------------
[<CompiledName("PrintFormatToString")>]
let sprintf fp = Printf.sprintf fp
let sprintf format = Printf.sprintf format
[<CompiledName("PrintFormatToStringThenFail")>]
let failwithf fp = Printf.failwithf fp
let failwithf format = Printf.failwithf format
[<CompiledName("PrintFormatToTextWriter")>]
let fprintf (os:TextWriter) fp = Printf.fprintf os fp
let fprintf (textWriter:TextWriter) format = Printf.fprintf textWriter format
[<CompiledName("PrintFormatLineToTextWriter")>]
let fprintfn (os:TextWriter) fp = Printf.fprintfn os fp
let fprintfn (textWriter:TextWriter) format = Printf.fprintfn textWriter format
#if !FX_NO_SYSTEM_CONSOLE
[<CompiledName("PrintFormat")>]
let printf fp = Printf.printf fp
let printf format = Printf.printf format
[<CompiledName("PrintFormatToError")>]
let eprintf fp = Printf.eprintf fp
let eprintf format = Printf.eprintf format
[<CompiledName("PrintFormatLine")>]
let printfn fp = Printf.printfn fp
let printfn format = Printf.printfn format
[<CompiledName("PrintFormatLineToError")>]
let eprintfn fp = Printf.eprintfn fp
let eprintfn format = Printf.eprintfn format
#endif
[<CompiledName("FailWith")>]
let failwith s = raise (Failure s)
[<CompiledName("DefaultAsyncBuilder")>]
let async = new Microsoft.FSharp.Control.AsyncBuilder()
let async = AsyncBuilder()
[<CompiledName("ToSingle")>]
let inline single x = float32 x
let inline single value = float32 value
[<CompiledName("ToDouble")>]
let inline double x = float x
let inline double value = float value
[<CompiledName("ToByte")>]
let inline uint8 x = byte x
let inline uint8 value = byte value
[<CompiledName("ToSByte")>]
let inline int8 x = sbyte x
let inline int8 value = sbyte value
module Checked =
[<CompiledName("ToByte")>]
let inline uint8 x = Checked.byte x
let inline uint8 value = Checked.byte value
[<CompiledName("ToSByte")>]
let inline int8 x = Checked.sbyte x
let inline int8 value = Checked.sbyte value
[<CompiledName("SpliceExpression")>]
let (~%) (_:Microsoft.FSharp.Quotations.Expr<'a>) : 'a = raise <| InvalidOperationException(SR.GetString(SR.firstClassUsesOfSplice))
......@@ -209,7 +209,7 @@ module ExtraTopLevelOperators =
do()
[<CompiledName("LazyPattern")>]
let (|Lazy|) (x:Lazy<_>) = x.Force()
let (|Lazy|) (input:Lazy<_>) = input.Force()
let query = Microsoft.FSharp.Linq.QueryBuilder()
......
此差异已折叠。
......@@ -244,13 +244,13 @@ module internal List =
setFreshConsTail cons cons2
mapToFreshConsTail cons2 f t
let map f x =
let map mapping x =
match x with
| [] -> []
| [h] -> [f h]
| [h] -> [mapping h]
| h::t ->
let cons = freshConsNoTail (f h)
mapToFreshConsTail cons f t
let cons = freshConsNoTail (mapping h)
mapToFreshConsTail cons mapping t
cons
let rec mapiToFreshConsTail cons (f:OptimizedClosures.FSharpFunc<_,_,_>) x i =
......@@ -283,11 +283,11 @@ module internal List =
| [],xs2 -> invalidArgDifferentListLength "list1" "list2" xs2.Length
| xs1,[] -> invalidArgDifferentListLength "list2" "list1" xs1.Length
let map2 f xs1 xs2 =
let map2 mapping xs1 xs2 =
match xs1,xs2 with
| [],[] -> []
| h1::t1, h2::t2 ->
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(f)
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(mapping)
let cons = freshConsNoTail (f.Invoke(h1,h2))
map2ToFreshConsTail cons f t1 t2
cons
......@@ -305,11 +305,11 @@ module internal List =
| xs1,xs2,xs3 ->
invalidArg3ListsDifferent "list1" "list2" "list3" xs1.Length xs2.Length xs3.Length
let map3 f xs1 xs2 xs3 =
let map3 mapping xs1 xs2 xs3 =
match xs1,xs2,xs3 with
| [],[],[] -> []
| h1::t1, h2::t2, h3::t3 ->
let f = OptimizedClosures.FSharpFunc<_,_,_,_>.Adapt(f)
let f = OptimizedClosures.FSharpFunc<_,_,_,_>.Adapt(mapping)
let cons = freshConsNoTail (f.Invoke(h1,h2,h3))
map3ToFreshConsTail cons f t1 t2 t3
cons
......@@ -399,15 +399,15 @@ module internal List =
let s' = mapFoldToFreshConsTail cons f s' t
cons, s'
let rec forall f xs1 =
let rec forall predicate xs1 =
match xs1 with
| [] -> true
| h1::t1 -> f h1 && forall f t1
| h1::t1 -> predicate h1 && forall predicate t1
let rec exists f xs1 =
let rec exists predicate xs1 =
match xs1 with
| [] -> false
| h1::t1 -> f h1 || exists f t1
| h1::t1 -> predicate h1 || exists predicate t1
let rec revAcc xs acc =
match xs with
......@@ -487,20 +487,20 @@ module internal List =
else
filterToFreshConsTail cons f t
let rec filter f l =
let rec filter predicate l =
match l with
| [] -> l
| h :: ([] as nil) -> if f h then l else nil
| h :: ([] as nil) -> if predicate h then l else nil
| h::t ->
if f h then
if predicate h then
let cons = freshConsNoTail h
filterToFreshConsTail cons f t
filterToFreshConsTail cons predicate t
cons
else
filter f t
filter predicate t
let iteri f x =
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(f)
let iteri action x =
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(action)
let rec loop n x =
match x with
| [] -> ()
......@@ -675,15 +675,15 @@ module internal List =
setFreshConsTail consR cons'
partitionToFreshConsTailRight cons' p t
let partition p l =
let partition predicate l =
match l with
| [] -> l,l
| h :: ([] as nil) -> if p h then l,nil else nil,l
| h :: ([] as nil) -> if predicate h then l,nil else nil,l
| h::t ->
let cons = freshConsNoTail h
if p h
then cons, (partitionToFreshConsTailLeft cons p t)
else (partitionToFreshConsTailRight cons p t), cons
if predicate h
then cons, (partitionToFreshConsTailLeft cons predicate t)
else (partitionToFreshConsTailRight cons predicate t), cons
let rec truncateToFreshConsTail cons count list =
if count = 0 then setFreshConsTail cons [] else
......@@ -940,31 +940,31 @@ module internal Array =
let inline indexNotFound() = raise (KeyNotFoundException(SR.GetString(SR.keyNotFoundAlt)))
let findBack f (array: _[]) =
let findBack predicate (array: _[]) =
let rec loop i =
if i < 0 then indexNotFound()
elif f array.[i] then array.[i]
elif predicate array.[i] then array.[i]
else loop (i - 1)
loop (array.Length - 1)
let tryFindBack f (array: _[]) =
let tryFindBack predicate (array: _[]) =
let rec loop i =
if i < 0 then None
elif f array.[i] then Some array.[i]
elif predicate array.[i] then Some array.[i]
else loop (i - 1)
loop (array.Length - 1)
let findIndexBack f (array: _[]) =
let findIndexBack predicate (array: _[]) =
let rec loop i =
if i < 0 then indexNotFound()
elif f array.[i] then i
elif predicate array.[i] then i
else loop (i - 1)
loop (array.Length - 1)
let tryFindIndexBack f (array: _[]) =
let tryFindIndexBack predicate (array: _[]) =
let rec loop i =
if i < 0 then None
elif f array.[i] then Some i
elif predicate array.[i] then Some i
else loop (i - 1)
loop (array.Length - 1)
......@@ -1016,13 +1016,13 @@ module internal Array =
res.[i - start] <- state
res
let unstableSortInPlaceBy (f: 'T -> 'U) (array : array<'T>) =
let unstableSortInPlaceBy (projection: 'T -> 'U) (array : array<'T>) =
let len = array.Length
if len < 2 then ()
else
let keys = zeroCreateUnchecked array.Length
for i = 0 to array.Length - 1 do
keys.[i] <- f array.[i]
keys.[i] <- projection array.[i]
Array.Sort<_,_>(keys, array, fastComparerForArraySort())
let unstableSortInPlace (array : array<'T>) =
......@@ -1061,14 +1061,14 @@ module internal Array =
let c = LanguagePrimitives.FastGenericComparer<'Key>
stableSortWithKeysAndComparer cFast c array keys
let stableSortInPlaceBy (f: 'T -> 'U) (array : array<'T>) =
let stableSortInPlaceBy (projection: 'T -> 'U) (array : array<'T>) =
let len = array.Length
if len < 2 then ()
else
// 'keys' is an array storing the projected keys
let keys = zeroCreateUnchecked array.Length
for i = 0 to array.Length - 1 do
keys.[i] <- f array.[i]
keys.[i] <- projection array.[i]
stableSortWithKeys array keys
let stableSortInPlace (array : array<'T>) =
......
......@@ -470,15 +470,15 @@ namespace Microsoft.FSharp.Collections
static member Create() : Map<'Key,'Value> = empty
new(ie : seq<_>) =
new(elements : seq<_>) =
let comparer = LanguagePrimitives.FastGenericComparer<'Key>
new Map<_,_>(comparer,MapTree.ofSeq comparer ie)
new Map<_,_>(comparer,MapTree.ofSeq comparer elements)
[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
member internal m.Comparer = comparer
//[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
member internal m.Tree = tree
member m.Add(k,v) : Map<'Key,'Value> =
member m.Add(key,value) : Map<'Key,'Value> =
#if TRACE_SETS_AND_MAPS
MapTree.report()
MapTree.numAdds <- MapTree.numAdds + 1
......@@ -488,18 +488,18 @@ namespace Microsoft.FSharp.Collections
MapTree.largestMapSize <- size
MapTree.largestMapStackTrace <- System.Diagnostics.StackTrace().ToString()
#endif
new Map<'Key,'Value>(comparer,MapTree.add comparer k v tree)
new Map<'Key,'Value>(comparer,MapTree.add comparer key value tree)
[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
member m.IsEmpty = MapTree.isEmpty tree
member m.Item
with get(k : 'Key) =
with get(key : 'Key) =
#if TRACE_SETS_AND_MAPS
MapTree.report()
MapTree.numLookups <- MapTree.numLookups + 1
MapTree.totalSizeOnMapLookup <- MapTree.totalSizeOnMapLookup + float (MapTree.size tree)
#endif
MapTree.find comparer k tree
MapTree.find comparer key tree
member m.TryPick(f) = MapTree.tryPick f tree
member m.Exists(f) = MapTree.exists f tree
member m.Filter(f) : Map<'Key,'Value> = new Map<'Key,'Value>(comparer ,MapTree.filter comparer f tree)
......@@ -520,24 +520,24 @@ namespace Microsoft.FSharp.Collections
member m.Count = MapTree.size tree
member m.ContainsKey(k) =
member m.ContainsKey(key) =
#if TRACE_SETS_AND_MAPS
MapTree.report()
MapTree.numLookups <- MapTree.numLookups + 1
MapTree.totalSizeOnMapLookup <- MapTree.totalSizeOnMapLookup + float (MapTree.size tree)
#endif
MapTree.mem comparer k tree
MapTree.mem comparer key tree
member m.Remove(k) : Map<'Key,'Value> =
new Map<'Key,'Value>(comparer,MapTree.remove comparer k tree)
member m.Remove(key) : Map<'Key,'Value> =
new Map<'Key,'Value>(comparer,MapTree.remove comparer key tree)
member m.TryFind(k) =
member m.TryFind(key) =
#if TRACE_SETS_AND_MAPS
MapTree.report()
MapTree.numLookups <- MapTree.numLookups + 1
MapTree.totalSizeOnMapLookup <- MapTree.totalSizeOnMapLookup + float (MapTree.size tree)
#endif
MapTree.tryFind comparer k tree
MapTree.tryFind comparer key tree
member m.ToList() = MapTree.toList tree
......@@ -650,83 +650,83 @@ namespace Microsoft.FSharp.Collections
module Map =
[<CompiledName("IsEmpty")>]
let isEmpty (m:Map<_,_>) = m.IsEmpty
let isEmpty (table:Map<_,_>) = table.IsEmpty
[<CompiledName("Add")>]
let add k v (m:Map<_,_>) = m.Add(k,v)
let add key value (table:Map<_,_>) = table.Add(key,value)
[<CompiledName("Find")>]
let find k (m:Map<_,_>) = m.[k]
let find key (table:Map<_,_>) = table.[key]
[<CompiledName("TryFind")>]
let tryFind k (m:Map<_,_>) = m.TryFind(k)
let tryFind key (table:Map<_,_>) = table.TryFind(key)
[<CompiledName("Remove")>]
let remove k (m:Map<_,_>) = m.Remove(k)
let remove key (table:Map<_,_>) = table.Remove(key)
[<CompiledName("ContainsKey")>]
let containsKey k (m:Map<_,_>) = m.ContainsKey(k)
let containsKey key (table:Map<_,_>) = table.ContainsKey(key)
[<CompiledName("Iterate")>]
let iter f (m:Map<_,_>) = m.Iterate(f)
let iter action (table:Map<_,_>) = table.Iterate(action)
[<CompiledName("TryPick")>]
let tryPick f (m:Map<_,_>) = m.TryPick(f)
let tryPick chooser (table:Map<_,_>) = table.TryPick(chooser)
[<CompiledName("Pick")>]
let pick f (m:Map<_,_>) = match tryPick f m with None -> raise (KeyNotFoundException()) | Some res -> res
let pick chooser (table:Map<_,_>) = match tryPick chooser table with None -> raise (KeyNotFoundException()) | Some res -> res
[<CompiledName("Exists")>]
let exists f (m:Map<_,_>) = m.Exists(f)
let exists predicate (table:Map<_,_>) = table.Exists(predicate)
[<CompiledName("Filter")>]
let filter f (m:Map<_,_>) = m.Filter(f)
let filter predicate (table:Map<_,_>) = table.Filter(predicate)
[<CompiledName("Partition")>]
let partition f (m:Map<_,_>) = m.Partition(f)
let partition predicate (table:Map<_,_>) = table.Partition(predicate)
[<CompiledName("ForAll")>]
let forall f (m:Map<_,_>) = m.ForAll(f)
let forall predicate (table:Map<_,_>) = table.ForAll(predicate)
let mapRange f (m:Map<_,_>) = m.MapRange(f)
[<CompiledName("Map")>]
let map f (m:Map<_,_>) = m.Map(f)
let map mapping (table:Map<_,_>) = table.Map(mapping)
[<CompiledName("Fold")>]
let fold<'Key,'T,'State when 'Key : comparison> f (z:'State) (m:Map<'Key,'T>) = MapTree.fold f z m.Tree
let fold<'Key,'T,'State when 'Key : comparison> folder (state:'State) (table:Map<'Key,'T>) = MapTree.fold folder state table.Tree
[<CompiledName("FoldBack")>]
let foldBack<'Key,'T,'State when 'Key : comparison> f (m:Map<'Key,'T>) (z:'State) = MapTree.foldBack f m.Tree z
let foldBack<'Key,'T,'State when 'Key : comparison> folder (table:Map<'Key,'T>) (state:'State) = MapTree.foldBack folder table.Tree state
[<CompiledName("ToSeq")>]
let toSeq (m:Map<_,_>) = m |> Seq.map (fun kvp -> kvp.Key, kvp.Value)
let toSeq (table:Map<_,_>) = table |> Seq.map (fun kvp -> kvp.Key, kvp.Value)
[<CompiledName("FindKey")>]
let findKey f (m : Map<_,_>) = m |> toSeq |> Seq.pick (fun (k,v) -> if f k v then Some(k) else None)
let findKey predicate (table : Map<_,_>) = table |> toSeq |> Seq.pick (fun (k,v) -> if predicate k v then Some(k) else None)
[<CompiledName("TryFindKey")>]
let tryFindKey f (m : Map<_,_>) = m |> toSeq |> Seq.tryPick (fun (k,v) -> if f k v then Some(k) else None)
let tryFindKey predicate (table : Map<_,_>) = table |> toSeq |> Seq.tryPick (fun (k,v) -> if predicate k v then Some(k) else None)
[<CompiledName("OfList")>]
let ofList (l: ('Key * 'Value) list) = Map<_,_>.ofList(l)
let ofList (elements: ('Key * 'Value) list) = Map<_,_>.ofList(elements)
[<CompiledName("OfSeq")>]
let ofSeq l = Map<_,_>.Create(l)
let ofSeq elements = Map<_,_>.Create(elements)
[<CompiledName("OfArray")>]
let ofArray (array: ('Key * 'Value) array) =
let ofArray (elements: ('Key * 'Value) array) =
let comparer = LanguagePrimitives.FastGenericComparer<'Key>
new Map<_,_>(comparer,MapTree.ofArray comparer array)
new Map<_,_>(comparer,MapTree.ofArray comparer elements)
[<CompiledName("ToList")>]
let toList (m:Map<_,_>) = m.ToList()
let toList (table:Map<_,_>) = table.ToList()
[<CompiledName("ToArray")>]
let toArray (m:Map<_,_>) = m.ToArray()
let toArray (table:Map<_,_>) = table.ToArray()
[<CompiledName("Empty")>]
let empty<'Key,'Value when 'Key : comparison> = Map<'Key,'Value>.Empty
[<CompiledName("Count")>]
let count (m:Map<_,_>) = m.Count
\ No newline at end of file
let count (table:Map<_,_>) = table.Count
\ No newline at end of file
......@@ -366,13 +366,13 @@ namespace Microsoft.FSharp.Core
let tab64 = new System.Collections.Generic.Dictionary<int64,obj>()
let tabParse = new System.Collections.Generic.Dictionary<string,obj>()
let FromInt64Dynamic (x64:int64) : obj =
let FromInt64Dynamic (value:int64) : obj =
lock tab64 (fun () ->
let mutable res = Unchecked.defaultof<_>
let ok = tab64.TryGetValue(x64,&res)
let ok = tab64.TryGetValue(value,&res)
if ok then res else
res <- BigInteger(x64)
tab64.[x64] <- res
res <- BigInteger(value)
tab64.[value] <- res
res)
let inline get32 (x32:int32) = FromInt64Dynamic (int64 x32)
......@@ -387,13 +387,13 @@ namespace Microsoft.FSharp.Core
(get32 1 :?> 'T)
when 'T : BigInteger = BigInteger.One
let FromInt32 (i:int32): 'T =
(get32 i :?> 'T)
when 'T : BigInteger = new BigInteger(i)
let FromInt32 (value:int32): 'T =
(get32 value :?> 'T)
when 'T : BigInteger = new BigInteger(value)
let FromInt64 (i:int64): 'T =
(FromInt64Dynamic i :?> 'T)
when 'T : BigInteger = new BigInteger(i)
let FromInt64 (value:int64): 'T =
(FromInt64Dynamic value :?> 'T)
when 'T : BigInteger = new BigInteger(value)
let getParse s =
lock tabParse (fun () ->
......@@ -459,12 +459,12 @@ namespace Microsoft.FSharp.Core
tabParse.[s] <- res
res)
let FromStringDynamic (s:string) : obj =
getParse s
let FromStringDynamic (text:string) : obj =
getParse text
let FromString (s:string) : 'T =
(FromStringDynamic s :?> 'T)
when 'T : BigInteger = getParse s
let FromString (text:string) : 'T =
(FromStringDynamic text :?> 'T)
when 'T : BigInteger = getParse text
......@@ -19,31 +19,31 @@ module NativePtr =
[<NoDynamicInvocation>]
[<CompiledName("OfNativeIntInlined")>]
let inline ofNativeInt (x:nativeint) = (# "" x : nativeptr<'T> #)
let inline ofNativeInt (address:nativeint) = (# "" address : nativeptr<'T> #)
[<NoDynamicInvocation>]
[<CompiledName("ToNativeIntInlined")>]
let inline toNativeInt (x: nativeptr<'T>) = (# "" x : nativeint #)
let inline toNativeInt (address: nativeptr<'T>) = (# "" address : nativeint #)
[<NoDynamicInvocation>]
[<CompiledName("AddPointerInlined")>]
let inline add (x : nativeptr<'T>) (n:int) : nativeptr<'T> = toNativeInt x + nativeint n * (# "sizeof !0" type('T) : nativeint #) |> ofNativeInt
let inline add (address : nativeptr<'T>) (index:int) : nativeptr<'T> = toNativeInt address + nativeint index * (# "sizeof !0" type('T) : nativeint #) |> ofNativeInt
[<NoDynamicInvocation>]
[<CompiledName("GetPointerInlined")>]
let inline get (p : nativeptr<'T>) n = (# "ldobj !0" type ('T) (add p n) : 'T #)
let inline get (address : nativeptr<'T>) index = (# "ldobj !0" type ('T) (add address index) : 'T #)
[<NoDynamicInvocation>]
[<CompiledName("SetPointerInlined")>]
let inline set (p : nativeptr<'T>) n (x : 'T) = (# "stobj !0" type ('T) (add p n) x #)
let inline set (address : nativeptr<'T>) index (value : 'T) = (# "stobj !0" type ('T) (add address index) value #)
[<NoDynamicInvocation>]
[<CompiledName("ReadPointerInlined")>]
let inline read (p : nativeptr<'T>) = (# "ldobj !0" type ('T) p : 'T #)
let inline read (address : nativeptr<'T>) = (# "ldobj !0" type ('T) address : 'T #)
[<NoDynamicInvocation>]
[<CompiledName("WritePointerInlined")>]
let inline write (p : nativeptr<'T>) (x : 'T) = (# "stobj !0" type ('T) p x #)
let inline write (address : nativeptr<'T>) (value : 'T) = (# "stobj !0" type ('T) address value #)
[<NoDynamicInvocation>]
[<CompiledName("StackAllocate")>]
......
......@@ -17,7 +17,7 @@ namespace Microsoft.FSharp.Core
let inline isNone option = match option with None -> true | Some _ -> false
[<CompiledName("DefaultValue")>]
let defaultValue def option = match option with None -> def | Some v -> v
let defaultValue value option = match option with None -> value | Some v -> v
[<CompiledName("DefaultWith")>]
let defaultWith defThunk option = match option with None -> defThunk () | Some v -> v
......@@ -32,46 +32,46 @@ namespace Microsoft.FSharp.Core
let count option = match option with None -> 0 | Some _ -> 1
[<CompiledName("Fold")>]
let fold<'T,'State> f (s:'State) (inp: option<'T>) = match inp with None -> s | Some x -> f s x
let fold<'T,'State> folder (state:'State) (option: option<'T>) = match option with None -> state | Some x -> folder state x
[<CompiledName("FoldBack")>]
let foldBack<'T,'State> f (inp: option<'T>) (s:'State) = match inp with None -> s | Some x -> f x s
let foldBack<'T,'State> folder (option: option<'T>) (state:'State) = match option with None -> state | Some x -> folder x state
[<CompiledName("Exists")>]
let exists p inp = match inp with None -> false | Some x -> p x
let exists predicate option = match option with None -> false | Some x -> predicate x
[<CompiledName("ForAll")>]
let forall p inp = match inp with None -> true | Some x -> p x
let forall predicate option = match option with None -> true | Some x -> predicate x
[<CompiledName("Contains")>]
let inline contains x inp = match inp with None -> false | Some v -> v = x
let inline contains value option = match option with None -> false | Some v -> v = value
[<CompiledName("Iterate")>]
let iter f inp = match inp with None -> () | Some x -> f x
let iter action option = match option with None -> () | Some x -> action x
[<CompiledName("Map")>]
let map f inp = match inp with None -> None | Some x -> Some (f x)
let map mapping option = match option with None -> None | Some x -> Some (mapping x)
[<CompiledName("Map2")>]
let map2 f option1 option2 =
let map2 mapping option1 option2 =
match option1, option2 with
| Some x, Some y -> Some <| f x y
| Some x, Some y -> Some (mapping x y)
| _ -> None
[<CompiledName("Map3")>]
let map3 f option1 option2 option3 =
let map3 mapping option1 option2 option3 =
match option1, option2, option3 with
| Some x, Some y, Some z -> Some <| f x y z
| Some x, Some y, Some z -> Some (mapping x y z)
| _ -> None
[<CompiledName("Bind")>]
let bind f inp = match inp with None -> None | Some x -> f x
let bind binder option = match option with None -> None | Some x -> binder x
[<CompiledName("Flatten")>]
let flatten option = match option with None -> None | Some x -> x
[<CompiledName("Filter")>]
let filter f inp = match inp with None -> None | Some x -> if f x then Some x else None
let filter predicate option = match option with None -> None | Some x -> if predicate x then Some x else None
[<CompiledName("ToArray")>]
let toArray option = match option with None -> [| |] | Some x -> [| x |]
......
......@@ -35,6 +35,8 @@ module internal PrintfImpl =
/// 2. we can make combinable parts independent from particular printf implementation. Thus final result can be cached and shared.
/// i.e when first call to printf "%s %s" will trigger creation of the specialization. Subsequent calls will pick existing specialization
open System
open System.IO
open System.Text
open System.Collections.Generic
open System.Reflection
......@@ -518,41 +520,36 @@ module internal PrintfImpl =
// width=*, prec=*
box(fun v width prec ->
let fmt = getFormat (normalizePrecision prec)
pad fmt width v
)
pad fmt width v)
else
// width=*, prec=?
let prec = if spec.IsPrecisionSpecified then normalizePrecision spec.Precision else DefaultPrecision
let fmt = getFormat prec
box(fun v width ->
pad fmt width v
)
pad fmt width v)
elif spec.IsStarPrecision then
if spec.IsWidthSpecified then
// width=val, prec=*
box(fun v prec ->
let fmt = getFormat prec
pad fmt spec.Width v
)
pad fmt spec.Width v)
else
// width=X, prec=*
box(fun v prec ->
let fmt = getFormat prec
basic fmt v
)
basic fmt v)
else
let prec = if spec.IsPrecisionSpecified then normalizePrecision spec.Precision else DefaultPrecision
let fmt = getFormat prec
if spec.IsWidthSpecified then
// width=val, prec=*
box(fun v ->
pad fmt spec.Width v
)
pad fmt spec.Width v)
else
// width=X, prec=*
box(fun v ->
basic fmt v
)
basic fmt v)
/// pad here is function that converts T to string with respect of justification
/// basic - function that converts T to string without applying justification rules
......@@ -561,19 +558,16 @@ module internal PrintfImpl =
if spec.IsStarWidth then
// width=*, prec=?
box(fun v width ->
pad width v
)
pad width v)
else
if spec.IsWidthSpecified then
// width=val, prec=*
box(fun v ->
pad spec.Width v
)
pad spec.Width v)
else
// width=X, prec=*
box(fun v ->
basic v
)
basic v)
let inline withPaddingFormatted (spec : FormatSpecifier) getFormat (defaultFormat : string) (f : string -> 'T -> string) left right =
if not (spec.IsWidthSpecified || spec.IsPrecisionSpecified) then
......@@ -1306,11 +1300,14 @@ module internal PrintfImpl =
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module Printf =
open System
open System.IO
open System.Text
open PrintfImpl
type BuilderFormat<'T,'Result> = Format<'T, System.Text.StringBuilder, unit, 'Result>
type BuilderFormat<'T,'Result> = Format<'T, StringBuilder, unit, 'Result>
type StringFormat<'T,'Result> = Format<'T, unit, string, 'Result>
type TextWriterFormat<'T,'Result> = Format<'T, System.IO.TextWriter, unit, 'Result>
type TextWriterFormat<'T,'Result> = Format<'T, TextWriter, unit, 'Result>
type BuilderFormat<'T> = BuilderFormat<'T,unit>
type StringFormat<'T> = StringFormat<'T,string>
type TextWriterFormat<'T> = TextWriterFormat<'T,unit>
......@@ -1325,56 +1322,56 @@ module Printf =
let sprintf (format : StringFormat<'T>) = ksprintf id format
[<CompiledName("PrintFormatThen")>]
let kprintf f fmt = ksprintf f fmt
let kprintf continuation format = ksprintf continuation format
[<CompiledName("PrintFormatToStringBuilderThen")>]
let kbprintf f (buf: System.Text.StringBuilder) fmt =
doPrintf fmt (fun _ ->
StringBuilderPrintfEnv(f, buf) :> PrintfEnv<_, _, _>
let kbprintf continuation (builder: StringBuilder) format =
doPrintf format (fun _ ->
StringBuilderPrintfEnv(continuation, builder) :> PrintfEnv<_, _, _>
)
[<CompiledName("PrintFormatToTextWriterThen")>]
let kfprintf f os fmt =
doPrintf fmt (fun _ ->
TextWriterPrintfEnv(f, os) :> PrintfEnv<_, _, _>
let kfprintf continuation textWriter format =
doPrintf format (fun _ ->
TextWriterPrintfEnv(continuation, textWriter) :> PrintfEnv<_, _, _>
)
[<CompiledName("PrintFormatToStringBuilder")>]
let bprintf buf fmt = kbprintf ignore buf fmt
let bprintf builder format = kbprintf ignore builder format
[<CompiledName("PrintFormatToTextWriter")>]
let fprintf (os: System.IO.TextWriter) fmt = kfprintf ignore os fmt
let fprintf (textWriter: TextWriter) format = kfprintf ignore textWriter format
[<CompiledName("PrintFormatLineToTextWriter")>]
let fprintfn (os: System.IO.TextWriter) fmt = kfprintf (fun _ -> os.WriteLine()) os fmt
let fprintfn (textWriter: TextWriter) format = kfprintf (fun _ -> textWriter.WriteLine()) textWriter format
[<CompiledName("PrintFormatToStringThenFail")>]
let failwithf fmt = ksprintf failwith fmt
let failwithf format = ksprintf failwith format
#if !FX_NO_SYSTEM_CONSOLE
#if EXTRAS_FOR_SILVERLIGHT_COMPILER
[<CompiledName("PrintFormat")>]
let printf fmt = fprintf (!outWriter) fmt
let printf format = fprintf (!outWriter) format
[<CompiledName("PrintFormatToError")>]
let eprintf fmt = fprintf (!errorWriter) fmt
let eprintf format = fprintf (!errorWriter) format
[<CompiledName("PrintFormatLine")>]
let printfn fmt = fprintfn (!outWriter) fmt
let printfn format = fprintfn (!outWriter) format
[<CompiledName("PrintFormatLineToError")>]
let eprintfn fmt = fprintfn (!errorWriter) fmt
let eprintfn format = fprintfn (!errorWriter) format
#else
[<CompiledName("PrintFormat")>]
let printf fmt = fprintf System.Console.Out fmt
let printf format = fprintf Console.Out format
[<CompiledName("PrintFormatToError")>]
let eprintf fmt = fprintf System.Console.Error fmt
let eprintf format = fprintf Console.Error format
[<CompiledName("PrintFormatLine")>]
let printfn fmt = fprintfn System.Console.Out fmt
let printfn format = fprintfn Console.Out format
[<CompiledName("PrintFormatLineToError")>]
let eprintfn fmt = fprintfn System.Console.Error fmt
let eprintfn format = fprintfn Console.Error format
#endif
#endif
......@@ -3,21 +3,18 @@
// Reflection on F# values. Analyze an object to see if it the representation
// of an F# value.
namespace Microsoft.FSharp.Core
namespace Microsoft.FSharp.Reflection
open System
open System.Reflection
open System.Threading
open Microsoft.FSharp.Core
open Microsoft.FSharp.Core.Operators
open Microsoft.FSharp.Core.LanguagePrimitives.IntrinsicOperators
open Microsoft.FSharp.Collections
namespace Microsoft.FSharp.Reflection
open Microsoft.FSharp.Primitives.Basics
module internal ReflectionUtils =
open Microsoft.FSharp.Core.Operators
#if FX_NO_SYSTEM_BINDINGFLAGS
type BindingFlags = Microsoft.FSharp.Core.ReflectionAdapters.BindingFlags
#else
......@@ -30,14 +27,6 @@ module internal ReflectionUtils =
else
BindingFlags.Public
open System
open System.Globalization
open System.Reflection
open Microsoft.FSharp.Core
open Microsoft.FSharp.Core.Operators
open Microsoft.FSharp.Core.LanguagePrimitives.IntrinsicOperators
open Microsoft.FSharp.Collections
open Microsoft.FSharp.Primitives.Basics
module internal Impl =
......@@ -462,13 +451,11 @@ module internal Impl =
// Item1, Item2, ..., Item<maxTuple-1>
// Item1, Item2, ..., Item<maxTuple-1>, Rest
// The PropertyInfo may not come back in order, so ensure ordering here.
#if FX_PORTABLE_OR_NETSTANDARD
#else
#if !FX_PORTABLE_OR_NETSTANDARD
assert(maxTuple < 10) // Alphasort will only works for upto 9 items: Item1, Item10, Item2, Item3, ..., Item9, Rest
#endif
let props = props |> Array.sortBy (fun p -> p.Name) // they are not always in alphabetic order
#if FX_PORTABLE_OR_NETSTANDARD
#else
#if !FX_PORTABLE_OR_NETSTANDARD
assert(props.Length <= maxTuple)
assert(let haveNames = props |> Array.map (fun p -> p.Name)
let expectNames = Array.init props.Length (fun i -> let j = i+1 // index j = 1,2,..,props.Length <= maxTuple
......@@ -675,7 +662,6 @@ module internal Impl =
else
true)
let getTypeOfReprType (typ:Type,bindingFlags) =
if isExceptionRepr(typ,bindingFlags) then typ.BaseType
elif isConstructorRepr(typ,bindingFlags) then unionTypeOfUnionCaseType(typ,bindingFlags)
......@@ -684,7 +670,6 @@ module internal Impl =
get typ
else typ
//-----------------------------------------------------------------
// CHECKING ROUTINES
......@@ -837,10 +822,10 @@ type DynamicFunction<'T1,'T2>() =
[<AbstractClass; Sealed>]
type FSharpValue =
static member MakeRecord(recordType:Type,args,?bindingFlags) =
static member MakeRecord(recordType:Type,values,?bindingFlags) =
let bindingFlags = defaultArg bindingFlags BindingFlags.Public
Impl.checkRecordType("recordType",recordType,bindingFlags)
Impl.getRecordConstructor (recordType,bindingFlags) args
Impl.getRecordConstructor (recordType,bindingFlags) values
static member GetRecordField(record:obj,info:PropertyInfo) =
Impl.checkNonNull "info" info;
......@@ -936,7 +921,7 @@ type FSharpValue =
Impl.checkNonNull "unionCase" unionCase;
Impl.getUnionCaseConstructorMethod (unionCase.DeclaringType,unionCase.Tag,bindingFlags)
static member GetUnionFields(obj:obj,unionType:Type,?bindingFlags) =
static member GetUnionFields(value:obj,unionType:Type,?bindingFlags) =
let bindingFlags = defaultArg bindingFlags BindingFlags.Public
let ensureType (typ:Type,obj:obj) =
match typ with
......@@ -945,15 +930,15 @@ type FSharpValue =
| null -> invalidArg "obj" (SR.GetString(SR.objIsNullAndNoType))
| _ -> obj.GetType()
| _ -> typ
//System.Console.WriteLine("typ1 = {0}",box unionType)
let unionType = ensureType(unionType,obj)
//System.Console.WriteLine("typ2 = {0}",box unionType)
let unionType = ensureType(unionType,value)
Impl.checkNonNull "unionType" unionType
let unionType = Impl.getTypeOfReprType (unionType ,bindingFlags)
//System.Console.WriteLine("typ3 = {0}",box unionType)
Impl.checkUnionType(unionType,bindingFlags)
let tag = Impl.getUnionTagReader (unionType,bindingFlags) obj
let flds = Impl.getUnionCaseRecordReader (unionType,tag,bindingFlags) obj
let tag = Impl.getUnionTagReader (unionType,bindingFlags) value
let flds = Impl.getUnionCaseRecordReader (unionType,tag,bindingFlags) value
UnionCaseInfo(unionType,tag), flds
static member PreComputeUnionTagReader(unionType: Type,?bindingFlags) : (obj -> int) =
......@@ -963,7 +948,6 @@ type FSharpValue =
Impl.checkUnionType(unionType,bindingFlags)
Impl.getUnionTagReader (unionType ,bindingFlags)
static member PreComputeUnionTagMemberInfo(unionType: Type,?bindingFlags) =
let bindingFlags = defaultArg bindingFlags BindingFlags.Public
Impl.checkNonNull "unionType" unionType;
......@@ -1013,9 +997,9 @@ module FSharpReflectionExtensions =
FSharpType.IsRecord(typ, bindingFlags)
type FSharpValue with
static member MakeRecord(recordType:Type,args,?allowAccessToPrivateRepresentation) =
static member MakeRecord(recordType:Type,values,?allowAccessToPrivateRepresentation) =
let bindingFlags = Impl.getBindingFlags allowAccessToPrivateRepresentation
FSharpValue.MakeRecord(recordType, args, bindingFlags)
FSharpValue.MakeRecord(recordType, values, bindingFlags)
static member GetRecordFields(record:obj,?allowAccessToPrivateRepresentation) =
let bindingFlags = Impl.getBindingFlags allowAccessToPrivateRepresentation
......@@ -1049,9 +1033,9 @@ module FSharpReflectionExtensions =
let bindingFlags = Impl.getBindingFlags allowAccessToPrivateRepresentation
FSharpValue.PreComputeUnionTagMemberInfo(unionType, bindingFlags)
static member GetUnionFields(obj:obj,unionType:Type,?allowAccessToPrivateRepresentation) =
static member GetUnionFields(value:obj,unionType:Type,?allowAccessToPrivateRepresentation) =
let bindingFlags = Impl.getBindingFlags allowAccessToPrivateRepresentation
FSharpValue.GetUnionFields(obj, unionType, bindingFlags)
FSharpValue.GetUnionFields(value, unionType, bindingFlags)
static member PreComputeUnionTagReader(unionType: Type,?allowAccessToPrivateRepresentation) : (obj -> int) =
let bindingFlags = Impl.getBindingFlags allowAccessToPrivateRepresentation
......
......@@ -6,10 +6,10 @@ namespace Microsoft.FSharp.Core
module Result =
[<CompiledName("Map")>]
let map f inp = match inp with Error e -> Error e | Ok x -> Ok (f x)
let map mapping result = match result with Error e -> Error e | Ok x -> Ok (mapping x)
[<CompiledName("MapError")>]
let mapError f inp = match inp with Error e -> Error (f e) | Ok x -> Ok x
let mapError mapping result = match result with Error e -> Error (mapping e) | Ok x -> Ok x
[<CompiledName("Bind")>]
let bind f inp = match inp with Error e -> Error e | Ok x -> f x
let bind binder result = match result with Error e -> Error e | Ok x -> binder x
此差异已折叠。
......@@ -166,9 +166,9 @@ namespace Microsoft.FSharp.Core.CompilerServices
let GenerateUsing (openf : unit -> ('U :> System.IDisposable)) compute =
Generate openf compute (fun (s:'U) -> s.Dispose())
let EnumerateFromFunctions opener moveNext current =
let EnumerateFromFunctions create moveNext current =
Generate
opener
create
(fun x -> if moveNext x then Some(current x) else None)
(fun x -> match box(x) with :? System.IDisposable as id -> id.Dispose() | _ -> ())
......@@ -299,14 +299,14 @@ namespace Microsoft.FSharp.Core.CompilerServices
if not finished then
x.Finish()
let EnumerateUsing (resource : 'T :> System.IDisposable) (rest: 'T -> #seq<'U>) =
let EnumerateUsing (resource : 'T :> System.IDisposable) (source: 'T -> #seq<'U>) =
(FinallyEnumerable((fun () -> match box resource with null -> () | _ -> resource.Dispose()),
(fun () -> rest resource :> seq<_>)) :> seq<_>)
(fun () -> source resource :> seq<_>)) :> seq<_>)
let mkConcatSeq (sources: seq<'U :> seq<'T>>) =
mkSeq (fun () -> new ConcatEnumerator<_,_>(sources) :> IEnumerator<'T>)
let EnumerateWhile (g : unit -> bool) (b: seq<'T>) : seq<'T> =
let EnumerateWhile (guard: unit -> bool) (source: seq<'T>) : seq<'T> =
let started = ref false
let curr = ref None
let getCurr() =
......@@ -323,33 +323,33 @@ namespace Microsoft.FSharp.Core.CompilerServices
member x.Current = box (getCurr())
member x.MoveNext() =
start()
let keepGoing = (try g() with e -> finish (); reraise ()) in
let keepGoing = (try guard() with e -> finish (); reraise ()) in
if keepGoing then
curr := Some(b); true
curr := Some(source); true
else
finish(); false
member x.Reset() = IEnumerator.noReset()
interface System.IDisposable with
member x.Dispose() = () }))
let EnumerateThenFinally (rest : seq<'T>) (compensation : unit -> unit) =
(FinallyEnumerable(compensation, (fun () -> rest)) :> seq<_>)
let EnumerateThenFinally (source: seq<'T>) (compensation: unit -> unit) =
(FinallyEnumerable(compensation, (fun () -> source)) :> seq<_>)
let CreateEvent (add : 'Delegate -> unit) (remove : 'Delegate -> unit) (create : (obj -> 'Args -> unit) -> 'Delegate ) :IEvent<'Delegate,'Args> =
let CreateEvent (addHandler : 'Delegate -> unit) (removeHandler : 'Delegate -> unit) (createHandler : (obj -> 'Args -> unit) -> 'Delegate ) :IEvent<'Delegate,'Args> =
// Note, we implement each interface explicitly: this works around a bug in the CLR
// implementation on CompactFramework 3.7, used on Windows Phone 7
{ new obj() with
member x.ToString() = "<published event>"
interface IEvent<'Delegate,'Args>
interface IDelegateEvent<'Delegate> with
member x.AddHandler(h) = add h
member x.RemoveHandler(h) = remove h
member x.AddHandler(h) = addHandler h
member x.RemoveHandler(h) = removeHandler h
interface System.IObservable<'Args> with
member x.Subscribe(r:IObserver<'Args>) =
let h = create (fun _ args -> r.OnNext(args))
add h
let h = createHandler (fun _ args -> r.OnNext(args))
addHandler h
{ new System.IDisposable with
member x.Dispose() = remove h } }
member x.Dispose() = removeHandler h } }
[<AbstractClass>]
......@@ -358,7 +358,7 @@ namespace Microsoft.FSharp.Core.CompilerServices
let mutable redirect : bool = false
abstract GetFreshEnumerator : unit -> IEnumerator<'T>
abstract GenerateNext : next:byref<IEnumerable<'T>> -> int // 0 = Stop, 1 = Yield, 2 = Goto
abstract GenerateNext : result:byref<IEnumerable<'T>> -> int // 0 = Stop, 1 = Yield, 2 = Goto
abstract Close: unit -> unit
abstract CheckClose: bool
abstract LastGenerated : 'T
......
......@@ -15,7 +15,7 @@ namespace Microsoft.FSharp.Collections
[<CompilationRepresentation(CompilationRepresentationFlags.UseNullAsTrueValue)>]
[<NoEquality; NoComparison>]
type SetTree<'T> when 'T : comparison =
type SetTree<'T> when 'T: comparison =
| SetEmpty // height = 0
| SetNode of 'T * SetTree<'T> * SetTree<'T> * int // height = int
| SetOne of 'T // height = 1
......@@ -171,7 +171,7 @@ namespace Microsoft.FSharp.Collections
// case: a, h1 and h2 meet balance requirement
mk t1 k t2
let rec split (comparer : IComparer<'T>) pivot t =
let rec split (comparer: IComparer<'T>) pivot t =
// Given a pivot and a set t
// Return { x in t s.t. x < pivot }, pivot in t? , { x in t s.t. x > pivot }
match t with
......@@ -386,9 +386,9 @@ namespace Microsoft.FSharp.Collections
//--------------------------------------------------------------------------
[<NoEquality; NoComparison>]
type SetIterator<'T> when 'T : comparison =
type SetIterator<'T> when 'T: comparison =
{ mutable stack: SetTree<'T> list; // invariant: always collapseLHS result
mutable started : bool // true when MoveNext has been called
mutable started: bool // true when MoveNext has been called
}
// collapseLHS:
......@@ -498,12 +498,12 @@ namespace Microsoft.FSharp.Collections
let rec mkFromEnumerator comparer acc (e : IEnumerator<_>) =
let rec mkFromEnumerator comparer acc (e: IEnumerator<_>) =
if e.MoveNext() then
mkFromEnumerator comparer (add comparer e.Current acc) e
else acc
let ofSeq comparer (c : IEnumerable<_>) =
let ofSeq comparer (c: IEnumerable<_>) =
use ie = c.GetEnumerator()
mkFromEnumerator comparer SetEmpty ie
......@@ -515,7 +515,7 @@ namespace Microsoft.FSharp.Collections
[<DebuggerTypeProxy(typedefof<SetDebugView<_>>)>]
[<DebuggerDisplay("Count = {Count}")>]
[<CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")>]
type Set<[<EqualityConditionalOn>]'T when 'T : comparison >(comparer:IComparer<'T>, tree: SetTree<'T>) =
type Set<[<EqualityConditionalOn>]'T when 'T: comparison >(comparer:IComparer<'T>, tree: SetTree<'T>) =
#if !FX_NO_BINARY_SERIALIZATION
[<System.NonSerialized>]
......@@ -536,9 +536,9 @@ namespace Microsoft.FSharp.Collections
// We use .NET generics per-instantiation static fields to avoid allocating a new object for each empty
// set (it is just a lookup into a .NET table of type-instantiation-indexed static fields).
static let empty : Set<'T> =
static let empty: Set<'T> =
let comparer = LanguagePrimitives.FastGenericComparer<'T>
new Set<'T>(comparer, SetEmpty)
Set<'T>(comparer, SetEmpty)
#if !FX_NO_BINARY_SERIALIZATION
[<System.Runtime.Serialization.OnSerializingAttribute>]
......@@ -562,36 +562,38 @@ namespace Microsoft.FSharp.Collections
[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
member internal set.Comparer = comparer
member internal set.Tree : SetTree<'T> = tree
member internal set.Tree: SetTree<'T> = tree
[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
static member Empty : Set<'T> = empty
static member Empty: Set<'T> = empty
member s.Add(x) : Set<'T> =
member s.Add(value): Set<'T> =
#if TRACE_SETS_AND_MAPS
SetTree.report()
SetTree.numAdds <- SetTree.numAdds + 1
SetTree.totalSizeOnSetAdd <- SetTree.totalSizeOnSetAdd + float (SetTree.count s.Tree)
#endif
new Set<'T>(s.Comparer,SetTree.add s.Comparer x s.Tree )
Set<'T>(s.Comparer,SetTree.add s.Comparer value s.Tree )
member s.Remove(x) : Set<'T> =
member s.Remove(value): Set<'T> =
#if TRACE_SETS_AND_MAPS
SetTree.report()
SetTree.numRemoves <- SetTree.numRemoves + 1
#endif
new Set<'T>(s.Comparer,SetTree.remove s.Comparer x s.Tree)
Set<'T>(s.Comparer,SetTree.remove s.Comparer value s.Tree)
member s.Count = SetTree.count s.Tree
member s.Contains(x) =
member s.Contains(value) =
#if TRACE_SETS_AND_MAPS
SetTree.report()
SetTree.numLookups <- SetTree.numLookups + 1
SetTree.totalSizeOnSetLookup <- SetTree.totalSizeOnSetLookup + float (SetTree.count s.Tree)
#endif
SetTree.mem s.Comparer x s.Tree
SetTree.mem s.Comparer value s.Tree
member s.Iterate(x) = SetTree.iter x s.Tree
member s.Fold f z =
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(f)
SetTree.fold (fun x z -> f.Invoke(z, x)) z s.Tree
......@@ -599,45 +601,45 @@ namespace Microsoft.FSharp.Collections
[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
member s.IsEmpty = SetTree.isEmpty s.Tree
member s.Partition f : Set<'T> * Set<'T> =
member s.Partition f : Set<'T> * Set<'T> =
match s.Tree with
| SetEmpty -> s,s
| _ -> let t1,t2 = SetTree.partition s.Comparer f s.Tree in new Set<_>(s.Comparer,t1), new Set<_>(s.Comparer,t2)
| _ -> let t1,t2 = SetTree.partition s.Comparer f s.Tree in Set(s.Comparer,t1), Set(s.Comparer,t2)
member s.Filter f : Set<'T> =
member s.Filter f : Set<'T> =
match s.Tree with
| SetEmpty -> s
| _ -> new Set<_>(s.Comparer,SetTree.filter s.Comparer f s.Tree)
| _ -> Set(s.Comparer,SetTree.filter s.Comparer f s.Tree)
member s.Map f : Set<'U> =
member s.Map f : Set<'U> =
let comparer = LanguagePrimitives.FastGenericComparer<'U>
new Set<_>(comparer,SetTree.fold (fun acc k -> SetTree.add comparer (f k) acc) (SetTree<_>.SetEmpty) s.Tree)
Set(comparer,SetTree.fold (fun acc k -> SetTree.add comparer (f k) acc) (SetTree<_>.SetEmpty) s.Tree)
member s.Exists f = SetTree.exists f s.Tree
member s.ForAll f = SetTree.forall f s.Tree
[<System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2225:OperatorOverloadsHaveNamedAlternates")>]
static member (-) (a: Set<'T>, b: Set<'T>) =
match a.Tree with
| SetEmpty -> a (* 0 - B = 0 *)
static member (-) (set1: Set<'T>, set2: Set<'T>) =
match set1.Tree with
| SetEmpty -> set1 (* 0 - B = 0 *)
| _ ->
match b.Tree with
| SetEmpty -> a (* A - 0 = A *)
| _ -> new Set<_>(a.Comparer,SetTree.diff a.Comparer a.Tree b.Tree)
match set2.Tree with
| SetEmpty -> set1 (* A - 0 = A *)
| _ -> Set(set1.Comparer,SetTree.diff set1.Comparer set1.Tree set2.Tree)
[<System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2225:OperatorOverloadsHaveNamedAlternates")>]
static member (+) (a: Set<'T>, b: Set<'T>) =
static member (+) (set1: Set<'T>, set2: Set<'T>) =
#if TRACE_SETS_AND_MAPS
SetTree.report()
SetTree.numUnions <- SetTree.numUnions + 1
#endif
match b.Tree with
| SetEmpty -> a (* A U 0 = A *)
match set2.Tree with
| SetEmpty -> set1 (* A U 0 = A *)
| _ ->
match a.Tree with
| SetEmpty -> b (* 0 U B = B *)
| _ -> new Set<_>(a.Comparer,SetTree.union a.Comparer a.Tree b.Tree)
match set1.Tree with
| SetEmpty -> set2 (* 0 U B = B *)
| _ -> Set(set1.Comparer,SetTree.union set1.Comparer set1.Tree set2.Tree)
static member Intersection(a: Set<'T>, b: Set<'T>) : Set<'T> =
match b.Tree with
......@@ -645,13 +647,13 @@ namespace Microsoft.FSharp.Collections
| _ ->
match a.Tree with
| SetEmpty -> a (* 0 INTER B = 0 *)
| _ -> new Set<_>(a.Comparer,SetTree.intersection a.Comparer a.Tree b.Tree)
| _ -> Set(a.Comparer,SetTree.intersection a.Comparer a.Tree b.Tree)
static member Union(sets:seq<Set<'T>>) : Set<'T> =
Seq.fold (fun s1 s2 -> s1 + s2) Set<'T>.Empty sets
static member Intersection(sets:seq<Set<'T>>) : Set<'T> =
Seq.reduce (fun s1 s2 -> Set<_>.Intersection(s1,s2)) sets
Seq.reduce (fun s1 s2 -> Set.Intersection(s1,s2)) sets
static member Equality(a: Set<'T>, b: Set<'T>) = (SetTree.compare a.Comparer a.Tree b.Tree = 0)
......@@ -666,11 +668,16 @@ namespace Microsoft.FSharp.Collections
[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
member x.MaximumElement = SetTree.maximumElement x.Tree
member x.IsSubsetOf(y: Set<'T>) = SetTree.subset x.Comparer x.Tree y.Tree
member x.IsSupersetOf(y: Set<'T>) = SetTree.subset x.Comparer y.Tree x.Tree
member x.IsProperSubsetOf(y: Set<'T>) = SetTree.psubset x.Comparer x.Tree y.Tree
member x.IsProperSupersetOf(y: Set<'T>) = SetTree.psubset x.Comparer y.Tree x.Tree
member x.IsSubsetOf(otherSet: Set<'T>) = SetTree.subset x.Comparer x.Tree otherSet.Tree
member x.IsSupersetOf(otherSet: Set<'T>) = SetTree.subset x.Comparer otherSet.Tree x.Tree
member x.IsProperSubsetOf(otherSet: Set<'T>) = SetTree.psubset x.Comparer x.Tree otherSet.Tree
member x.IsProperSupersetOf(otherSet: Set<'T>) = SetTree.psubset x.Comparer otherSet.Tree x.Tree
member x.ToList () = SetTree.toList x.Tree
member x.ToArray () = SetTree.toArray x.Tree
member this.ComputeHashCode() =
......@@ -716,13 +723,13 @@ namespace Microsoft.FSharp.Collections
new (elements : seq<'T>) =
let comparer = LanguagePrimitives.FastGenericComparer<'T>
new Set<_>(comparer,SetTree.ofSeq comparer elements)
Set(comparer,SetTree.ofSeq comparer elements)
static member Create(elements : seq<'T>) = new Set<'T>(elements)
static member Create(elements : seq<'T>) = Set<'T>(elements)
static member FromArray(arr : 'T array) : Set<'T> =
let comparer = LanguagePrimitives.FastGenericComparer<'T>
new Set<_>(comparer,SetTree.ofArray comparer arr)
Set(comparer,SetTree.ofArray comparer arr)
override x.ToString() =
match List.ofSeq (Seq.truncate 4 x) with
......@@ -750,108 +757,106 @@ namespace Microsoft.FSharp.Collections
module Set =
[<CompiledName("IsEmpty")>]
let isEmpty (s : Set<'T>) = s.IsEmpty
let isEmpty (set: Set<'T>) = set.IsEmpty
[<CompiledName("Contains")>]
let contains x (s : Set<'T>) = s.Contains(x)
let contains element (set: Set<'T>) = set.Contains(element)
[<CompiledName("Add")>]
let add x (s : Set<'T>) = s.Add(x)
let add value (set: Set<'T>) = set.Add(value)
[<CompiledName("Singleton")>]
let singleton x = Set<'T>.Singleton(x)
let singleton value = Set<'T>.Singleton(value)
[<CompiledName("Remove")>]
let remove x (s : Set<'T>) = s.Remove(x)
let remove value (set: Set<'T>) = set.Remove(value)
[<CompiledName("Union")>]
let union (s1 : Set<'T>) (s2 : Set<'T>) = s1 + s2
let union (set1: Set<'T>) (set2: Set<'T>) = set1 + set2
[<CompiledName("UnionMany")>]
let unionMany sets = Set<_>.Union(sets)
let unionMany sets = Set.Union(sets)
[<CompiledName("Intersect")>]
let intersect (s1 : Set<'T>) (s2 : Set<'T>) = Set<'T>.Intersection(s1,s2)
let intersect (set1: Set<'T>) (set2: Set<'T>) = Set<'T>.Intersection(set1,set2)
[<CompiledName("IntersectMany")>]
let intersectMany sets = Set<_>.Intersection(sets)
let intersectMany sets = Set.Intersection(sets)
[<CompiledName("Iterate")>]
let iter f (s : Set<'T>) = s.Iterate(f)
let iter action (set: Set<'T>) = set.Iterate(action)
[<CompiledName("Empty")>]
let empty<'T when 'T : comparison> : Set<'T> = Set<'T>.Empty
[<CompiledName("ForAll")>]
let forall f (s : Set<'T>) = s.ForAll f
let forall predicate (set: Set<'T>) = set.ForAll predicate
[<CompiledName("Exists")>]
let exists f (s : Set<'T>) = s.Exists f
let exists predicate (set: Set<'T>) = set.Exists predicate
[<CompiledName("Filter")>]
let filter f (s : Set<'T>) = s.Filter f
let filter predicate (set: Set<'T>) = set.Filter predicate
[<CompiledName("Partition")>]
let partition f (s : Set<'T>) = s.Partition f
let partition predicate (set: Set<'T>) = set.Partition predicate
[<CompiledName("Fold")>]
let fold<'T,'State when 'T : comparison> f (z:'State) (s : Set<'T>) = SetTree.fold f z s.Tree
let fold<'T,'State when 'T : comparison> folder (state:'State) (set: Set<'T>) = SetTree.fold folder state set.Tree
[<CompiledName("FoldBack")>]
let foldBack<'T,'State when 'T : comparison> f (s : Set<'T>) (z:'State) = SetTree.foldBack f s.Tree z
let foldBack<'T,'State when 'T : comparison> folder (set: Set<'T>) (state:'State) = SetTree.foldBack folder set.Tree state
[<CompiledName("Map")>]
let map f (s : Set<'T>) = s.Map f
let map mapping (set: Set<'T>) = set.Map mapping
[<CompiledName("Count")>]
let count (s : Set<'T>) = s.Count
let count (set: Set<'T>) = set.Count
[<CompiledName("MinumumElement")>]
let minimumElement (s : Set<'T>) = s.MinimumElement
let minimumElement (set: Set<'T>) = set.MinimumElement
[<CompiledName("MaximumElement")>]
let maximumElement (s : Set<'T>) = s.MaximumElement
let maximumElement (set: Set<'T>) = set.MaximumElement
[<CompiledName("OfList")>]
let ofList l = new Set<_>(List.toSeq l)
let ofList elements = Set(List.toSeq elements)
[<CompiledName("OfArray")>]
let ofArray (l : 'T array) = Set<'T>.FromArray(l)
let ofArray (array: 'T array) = Set<'T>.FromArray(array)
[<CompiledName("ToList")>]
let toList (s : Set<'T>) = s.ToList()
let toList (set: Set<'T>) = set.ToList()
[<CompiledName("ToArray")>]
let toArray (s : Set<'T>) = s.ToArray()
let toArray (set: Set<'T>) = set.ToArray()
[<CompiledName("ToSeq")>]
let toSeq (s : Set<'T>) = (s :> seq<'T>)
let toSeq (set: Set<'T>) = (set:> seq<'T>)
[<CompiledName("OfSeq")>]
let ofSeq (c : seq<_>) = new Set<_>(c)
let ofSeq (elements: seq<_>) = Set(elements)
[<CompiledName("Difference")>]
let difference (s1: Set<'T>) (s2: Set<'T>) = s1 - s2
let difference (set1: Set<'T>) (set2: Set<'T>) = set1 - set2
[<CompiledName("IsSubset")>]
let isSubset (x:Set<'T>) (y: Set<'T>) = SetTree.subset x.Comparer x.Tree y.Tree
let isSubset (set1:Set<'T>) (set2: Set<'T>) = SetTree.subset set1.Comparer set1.Tree set2.Tree
[<CompiledName("IsSuperset")>]
let isSuperset (x:Set<'T>) (y: Set<'T>) = SetTree.subset x.Comparer y.Tree x.Tree
let isSuperset (set1:Set<'T>) (set2: Set<'T>) = SetTree.subset set1.Comparer set2.Tree set1.Tree
[<CompiledName("IsProperSubset")>]
let isProperSubset (x:Set<'T>) (y: Set<'T>) = SetTree.psubset x.Comparer x.Tree y.Tree
let isProperSubset (set1:Set<'T>) (set2: Set<'T>) = SetTree.psubset set1.Comparer set1.Tree set2.Tree
[<CompiledName("IsProperSuperset")>]
let isProperSuperset (x:Set<'T>) (y: Set<'T>) = SetTree.psubset x.Comparer y.Tree x.Tree
let isProperSuperset (set1:Set<'T>) (set2: Set<'T>) = SetTree.psubset set1.Comparer set2.Tree set1.Tree
[<CompiledName("MinElement")>]
let minElement (s : Set<'T>) = s.MinimumElement
let minElement (set: Set<'T>) = set.MinimumElement
[<CompiledName("MaxElement")>]
let maxElement (s : Set<'T>) = s.MaximumElement
let maxElement (set: Set<'T>) = set.MaximumElement
......@@ -23,45 +23,45 @@ namespace Microsoft.FSharp.Core
String.Join(sep, strings)
[<CompiledName("Iterate")>]
let iter (f : (char -> unit)) (str:string) =
let iter (action : (char -> unit)) (str:string) =
let str = emptyIfNull str
for i = 0 to str.Length - 1 do
f str.[i]
action str.[i]
[<CompiledName("IterateIndexed")>]
let iteri f (str:string) =
let iteri action (str:string) =
let str = emptyIfNull str
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(f)
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(action)
for i = 0 to str.Length - 1 do
f.Invoke(i, str.[i])
[<CompiledName("Map")>]
let map (f: char -> char) (str:string) =
let map (mapping: char -> char) (str:string) =
let str = emptyIfNull str
let res = StringBuilder str.Length
str |> iter (fun c -> res.Append(f c) |> ignore)
str |> iter (fun c -> res.Append(mapping c) |> ignore)
res.ToString()
[<CompiledName("MapIndexed")>]
let mapi (f: int -> char -> char) (str:string) =
let mapi (mapping: int -> char -> char) (str:string) =
let str = emptyIfNull str
let res = StringBuilder str.Length
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(f)
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(mapping)
str |> iteri (fun i c -> res.Append(f.Invoke(i, c)) |> ignore)
res.ToString()
[<CompiledName("Filter")>]
let filter (f: char -> bool) (str:string) =
let filter (predicate: char -> bool) (str:string) =
let str = emptyIfNull str
let res = StringBuilder str.Length
str |> iter (fun c -> if f c then res.Append c |> ignore)
str |> iter (fun c -> if predicate c then res.Append c |> ignore)
res.ToString()
[<CompiledName("Collect")>]
let collect (f: char -> string) (str:string) =
let collect (mapping: char -> string) (str:string) =
let str = emptyIfNull str
let res = StringBuilder str.Length
str |> iter (fun c -> res.Append(f c) |> ignore)
str |> iter (fun c -> res.Append(mapping c) |> ignore)
res.ToString()
[<CompiledName("Initialize")>]
......@@ -82,15 +82,15 @@ namespace Microsoft.FSharp.Core
res.ToString()
[<CompiledName("ForAll")>]
let forall f (str:string) =
let forall predicate (str:string) =
let str = emptyIfNull str
let rec check i = (i >= str.Length) || (f str.[i] && check (i+1))
let rec check i = (i >= str.Length) || (predicate str.[i] && check (i+1))
check 0
[<CompiledName("Exists")>]
let exists f (str:string) =
let exists predicate (str:string) =
let str = emptyIfNull str
let rec check i = (i < str.Length) && (f str.[i] || check (i+1))
let rec check i = (i < str.Length) && (predicate str.[i] || check (i+1))
check 0
[<CompiledName("Length")>]
......
此差异已折叠。
......@@ -249,7 +249,7 @@ namespace Microsoft.FSharp.Text.StructuredPrintfImpl
val sepListL : layout1:Layout -> layouts:Layout list -> Layout
/// Wrap round brackets around Layout.
val bracketL : Layout:Layout -> Layout
val bracketL : layout:Layout -> Layout
/// Wrap square brackets around layout.
val squareBracketL : layout:Layout -> Layout
/// Wrap braces around layout.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册