Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET Platform
fsharp
提交
972c3cbf
F
fsharp
项目概览
dotNET Platform
/
fsharp
10 个月 前同步成功
通知
0
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
fsharp
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
972c3cbf
编写于
5月 18, 2022
作者:
D
Don Syme
提交者:
GitHub
5月 18, 2022
1
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
pre-formatting of FSHarp.Core (#13151)
上级
8ae6ba12
变更
19
展开全部
隐藏空白更改
内联
并排
Showing
19 changed file
with
6526 addition
and
6466 deletion
+6526
-6466
src/FSharp.Core/QueryExtensions.fs
src/FSharp.Core/QueryExtensions.fs
+3
-4
src/FSharp.Core/SI.fs
src/FSharp.Core/SI.fs
+163
-162
src/FSharp.Core/array2.fs
src/FSharp.Core/array2.fs
+141
-141
src/FSharp.Core/array3.fs
src/FSharp.Core/array3.fs
+155
-156
src/FSharp.Core/async.fs
src/FSharp.Core/async.fs
+1890
-1890
src/FSharp.Core/collections.fs
src/FSharp.Core/collections.fs
+43
-45
src/FSharp.Core/event.fs
src/FSharp.Core/event.fs
+149
-149
src/FSharp.Core/eventmodule.fs
src/FSharp.Core/eventmodule.fs
+64
-64
src/FSharp.Core/fslib-extra-pervasives.fs
src/FSharp.Core/fslib-extra-pervasives.fs
+139
-80
src/FSharp.Core/list.fs
src/FSharp.Core/list.fs
+766
-767
src/FSharp.Core/local.fs
src/FSharp.Core/local.fs
+2
-0
src/FSharp.Core/mailbox.fs
src/FSharp.Core/mailbox.fs
+395
-395
src/FSharp.Core/math/z.fs
src/FSharp.Core/math/z.fs
+58
-58
src/FSharp.Core/observable.fs
src/FSharp.Core/observable.fs
+170
-170
src/FSharp.Core/quotations.fs
src/FSharp.Core/quotations.fs
+9
-6
src/FSharp.Core/seq.fs
src/FSharp.Core/seq.fs
+1325
-1327
src/FSharp.Core/seqcore.fs
src/FSharp.Core/seqcore.fs
+542
-541
src/FSharp.Core/string.fs
src/FSharp.Core/string.fs
+174
-173
src/FSharp.Core/tasks.fs
src/FSharp.Core/tasks.fs
+338
-338
未找到文件。
src/FSharp.Core/QueryExtensions.fs
浏览文件 @
972c3cbf
...
...
@@ -21,14 +21,13 @@ open System.Linq.Expressions
/// on a result of a query.
type
Grouping
<
'
K
,
'
T
>(
key
:
'
K
,
values
:
seq
<
'
T
>)
=
interface
System
.
Linq
.
IGrouping
<
'
K
,
'
T
>
with
member
x
.
Key
=
key
member
_
.
Key
=
key
interface
System
.
Collections
.
IEnumerable
with
member
x
.
GetEnumerator
()
=
values
.
GetEnumerator
()
:>
System
.
Collections
.
IEnumerator
member
_
.
GetEnumerator
()
=
values
.
GetEnumerator
()
:>
System
.
Collections
.
IEnumerator
interface
System
.
Collections
.
Generic
.
IEnumerable
<
'
T
>
with
member
x
.
GetEnumerator
()
=
values
.
GetEnumerator
()
member
_.
GetEnumerator
()
=
values
.
GetEnumerator
()
module
internal
Adapters
=
...
...
src/FSharp.Core/SI.fs
浏览文件 @
972c3cbf
...
...
@@ -2,222 +2,223 @@
// The International System of Units (SI)
namespace
Microsoft
.
FSharp
.
Data
.
UnitSystems
.
SI
.
UnitNames
open
Microsoft
.
FSharp
.
Core
/// The SI unit of length
[<
Measure
>]
type
metre
open
Microsoft
.
FSharp
.
Core
/// The SI unit of length
[<
Measure
>]
type
meter
=
metre
/// The SI unit of length
[<
Measure
>]
type
metre
/// The SI unit of mass
[<
Measure
>]
type
kilogram
/// The SI unit of length
[<
Measure
>]
type
meter
=
metre
/// The SI unit of time
[<
Measure
>]
type
second
/// The SI unit of mass
[<
Measure
>]
type
kilogram
/// The SI unit of electric current
[<
Measure
>]
type
ampere
/// The SI unit of time
[<
Measure
>]
type
second
/// The SI unit of thermodynamic temperature
[<
Measure
>]
type
kelvin
/// The SI unit of electric current
[<
Measure
>]
type
ampere
/// The SI unit of amount of substanc
e
[<
Measure
>]
type
mole
/// The SI unit of thermodynamic temperatur
e
[<
Measure
>]
type
kelvin
/// The SI unit of luminous intensity
[<
Measure
>]
type
candela
/// The SI unit of amount of substance
[<
Measure
>]
type
mole
/// The SI unit of frequenc
y
[<
Measure
>]
type
hertz
=
/
second
/// The SI unit of luminous intensit
y
[<
Measure
>]
type
candela
/// The SI unit of force
[<
Measure
>]
type
newton
=
kilogram
metre
/
second
^
2
/// The SI unit of frequency
[<
Measure
>]
type
hertz
=
/
second
/// The SI unit of pressure, stress
[<
Measure
>]
type
pascal
=
newton
/
metre
^
2
/// The SI unit of force
[<
Measure
>]
type
newton
=
kilogram
metre
/
second
^
2
/// The SI unit of energy, work, amount of heat
[<
Measure
>]
type
joule
=
newton
metre
/// The SI unit of pressure, stress
[<
Measure
>]
type
pascal
=
newton
/
metre
^
2
/// The SI unit of power, radiant flux
[<
Measure
>]
type
watt
=
joule
/
second
/// The SI unit of energy, work, amount of heat
[<
Measure
>]
type
joule
=
newton
metre
/// The SI unit of electric charge, amount of electricity
[<
Measure
>]
type
coulomb
=
second
ampere
/// The SI unit of power, radiant flux
[<
Measure
>]
type
watt
=
joule
/
second
/// The SI unit of electric potential difference, electromotive force
[<
Measure
>]
type
volt
=
watt
/
ampere
/// The SI unit of electric charge, amount of electricity
[<
Measure
>]
type
coulomb
=
second
ampere
/// The SI unit of capacitan
ce
[<
Measure
>]
type
farad
=
coulomb
/
volt
/// The SI unit of electric potential difference, electromotive for
ce
[<
Measure
>]
type
volt
=
watt
/
ampere
/// The SI unit of electric resis
tance
[<
Measure
>]
type
ohm
=
volt
/
ampere
/// The SI unit of capaci
tance
[<
Measure
>]
type
farad
=
coulomb
/
volt
/// The SI unit of electric conduc
tance
[<
Measure
>]
type
siemens
=
ampere
/
volt
/// The SI unit of electric resis
tance
[<
Measure
>]
type
ohm
=
volt
/
ampere
/// The SI unit of magnetic flux
[<
Measure
>]
type
weber
=
volt
second
/// The SI unit of electric conductance
[<
Measure
>]
type
siemens
=
ampere
/
volt
/// The SI unit of magnetic flux density
[<
Measure
>]
type
tesla
=
weber
/
metre
^
2
/// The SI unit of magnetic flux
[<
Measure
>]
type
weber
=
volt
second
/// The SI unit of inductance
[<
Measure
>]
type
henry
=
weber
/
ampere
/// The SI unit of magnetic flux density
[<
Measure
>]
type
tesla
=
weber
/
metre
^
2
/// The SI unit of luminous flux
[<
Measure
>]
type
lumen
=
candela
/// The SI unit of inductance
[<
Measure
>]
type
henry
=
weber
/
ampere
/// The SI unit of illuminance
[<
Measure
>]
type
lux
=
lumen
/
metre
^
2
/// The SI unit of luminous flux
[<
Measure
>]
type
lumen
=
candela
/// The SI unit of activity referred to a radionuclid
e
[<
Measure
>]
type
becquerel
=
second
^-
1
/// The SI unit of illuminanc
e
[<
Measure
>]
type
lux
=
lumen
/
metre
^
2
/// The SI unit of absorbed dos
e
[<
Measure
>]
type
gray
=
joule
/
kilogram
/// The SI unit of activity referred to a radionuclid
e
[<
Measure
>]
type
becquerel
=
second
^-
1
/// The SI unit of does equivalent
[<
Measure
>]
type
sievert
=
joule
/
kilogram
/// The SI unit of absorbed dose
[<
Measure
>]
type
gray
=
joule
/
kilogram
/// The SI unit of catalytic activity
[<
Measure
>]
type
katal
=
mole
/
second
/// The SI unit of does equivalent
[<
Measure
>]
type
sievert
=
joule
/
kilogram
/// The SI unit of catalytic activity
[<
Measure
>]
type
katal
=
mole
/
second
// Common abbreviations for the International System of Units (SI)
namespace
Microsoft
.
FSharp
.
Data
.
UnitSystems
.
SI
.
UnitSymbols
open
Microsoft
.
FSharp
.
Core
open
Microsoft
.
FSharp
.
Data
.
UnitSystems
.
SI
.
UnitNames
/// A synonym for Metre, the SI unit of length
[<
Measure
>]
type
m
=
metre
open
Microsoft
.
FSharp
.
Core
open
Microsoft
.
FSharp
.
Data
.
UnitSystems
.
SI
.
UnitNames
/// A synonym for kilogram, the SI unit of mass
[<
Measure
>]
type
kg
=
kilogram
/// A synonym for Metre, the SI unit of length
[<
Measure
>]
type
m
=
metre
/// A synonym for second, the SI unit of time
[<
Measure
>]
type
s
=
second
/// A synonym for kilogram, the SI unit of mass
[<
Measure
>]
type
kg
=
kilogram
/// A synonym for ampere, the SI unit of electric current
[<
Measure
>]
type
A
=
ampere
/// A synonym for second, the SI unit of time
[<
Measure
>]
type
s
=
second
/// A synonym for kelvin, the SI unit of thermodynamic temperature
[<
Measure
>]
type
K
=
kelvin
/// A synonym for ampere, the SI unit of electric current
[<
Measure
>]
type
A
=
ampere
/// A synonym for mole, the SI unit of amount of substanc
e
[<
Measure
>]
type
mol
=
mole
/// A synonym for kelvin, the SI unit of thermodynamic temperatur
e
[<
Measure
>]
type
K
=
kelvin
/// A synonym for candela, the SI unit of luminous intensity
[<
Measure
>]
type
cd
=
candela
/// A synonym for mole, the SI unit of amount of substance
[<
Measure
>]
type
mol
=
mole
/// A synonym for hertz, the SI unit of frequenc
y
[<
Measure
>]
type
Hz
=
hertz
/// A synonym for candela, the SI unit of luminous intensit
y
[<
Measure
>]
type
cd
=
candela
/// A synonym for newton, the SI unit of force
[<
Measure
>]
type
N
=
newton
/// A synonym for hertz, the SI unit of frequency
[<
Measure
>]
type
Hz
=
hertz
/// A synonym for pascal, the SI unit of pressure, stress
[<
Measure
>]
type
Pa
=
pascal
/// A synonym for newton, the SI unit of force
[<
Measure
>]
type
N
=
newton
/// A synonym for joule, the SI unit of energy, work, amount of heat
[<
Measure
>]
type
J
=
joule
/// A synonym for pascal, the SI unit of pressure, stress
[<
Measure
>]
type
Pa
=
pascal
/// A synonym for watt, the SI unit of power, radiant flux
[<
Measure
>]
type
W
=
watt
/// A synonym for joule, the SI unit of energy, work, amount of heat
[<
Measure
>]
type
J
=
joule
/// A synonym for coulomb, the SI unit of electric charge, amount of electricity
[<
Measure
>]
type
C
=
coulomb
/// A synonym for watt, the SI unit of power, radiant flux
[<
Measure
>]
type
W
=
watt
/// A synonym for volt, the SI unit of electric potential difference, electromotive force
[<
Measure
>]
type
V
=
volt
/// A synonym for coulomb, the SI unit of electric charge, amount of electricity
[<
Measure
>]
type
C
=
coulomb
/// A synonym for farad, the SI unit of capacitan
ce
[<
Measure
>]
type
F
=
farad
/// A synonym for volt, the SI unit of electric potential difference, electromotive for
ce
[<
Measure
>]
type
V
=
volt
/// A synonym for siemens, the SI unit of electric conduc
tance
[<
Measure
>]
type
S
=
siemens
/// A synonym for farad, the SI unit of capaci
tance
[<
Measure
>]
type
F
=
farad
/// A synonym for UnitNames.ohm, the SI unit of electric resistance.
[<
Measure
>]
type
ohm
=
Microsoft
.
FSharp
.
Data
.
UnitSystems
.
SI
.
UnitNames
.
ohm
/// A synonym for siemens, the SI unit of electric conductance
[<
Measure
>]
type
S
=
siemens
/// A synonym for weber, the SI unit of magnetic flux
[<
Measure
>]
type
Wb
=
weber
/// A synonym for UnitNames.ohm, the SI unit of electric resistance.
[<
Measure
>]
type
ohm
=
Microsoft
.
FSharp
.
Data
.
UnitSystems
.
SI
.
UnitNames
.
ohm
/// A synonym for tesla, the SI unit of magnetic flux density
[<
Measure
>]
type
T
=
tesla
/// A synonym for weber, the SI unit of magnetic flux
[<
Measure
>]
type
Wb
=
weber
/// A synonym for lumen, the SI unit of luminous flux
[<
Measure
>]
type
lm
=
lumen
/// A synonym for tesla, the SI unit of magnetic flux density
[<
Measure
>]
type
T
=
tesla
/// A synonym for lux, the SI unit of illuminance
[<
Measure
>]
type
lx
=
lux
/// A synonym for lumen, the SI unit of luminous flux
[<
Measure
>]
type
lm
=
lumen
/// A synonym for becquerel, the SI unit of activity referred to a radionuclid
e
[<
Measure
>]
type
Bq
=
becquerel
/// A synonym for lux, the SI unit of illuminanc
e
[<
Measure
>]
type
lx
=
lux
/// A synonym for gray, the SI unit of absorbed dos
e
[<
Measure
>]
type
Gy
=
gray
/// A synonym for becquerel, the SI unit of activity referred to a radionuclid
e
[<
Measure
>]
type
Bq
=
becquerel
/// A synonym for sievert, the SI unit of does equivalent
[<
Measure
>]
type
Sv
=
sievert
/// A synonym for gray, the SI unit of absorbed dose
[<
Measure
>]
type
Gy
=
gray
/// A synonym for katal, the SI unit of catalytic activity
[<
Measure
>]
type
kat
=
katal
/// A synonym for sievert, the SI unit of does equivalent
[<
Measure
>]
type
Sv
=
sievert
/// A synonym for henry, the SI unit of inductance
[<
Measure
>]
type
H
=
henry
/// A synonym for katal, the SI unit of catalytic activity
[<
Measure
>]
type
kat
=
katal
/// A synonym for henry, the SI unit of inductance
[<
Measure
>]
type
H
=
henry
src/FSharp.Core/array2.fs
浏览文件 @
972c3cbf
...
...
@@ -2,159 +2,159 @@
namespace
Microsoft
.
FSharp
.
Collections
open
System
open
Microsoft
.
FSharp
.
Core
open
Microsoft
.
FSharp
.
Core
.
LanguagePrimitives
.
IntrinsicOperators
open
Microsoft
.
FSharp
.
Core
.
Operators
open
Microsoft
.
FSharp
.
Core
.
Operators
.
Checked
open
System
open
Microsoft
.
FSharp
.
Core
open
Microsoft
.
FSharp
.
Core
.
LanguagePrimitives
.
IntrinsicOperators
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
#
nowarn
"3218"
// mismatch of parameter name where 'count1' --> 'length1' would shadow function in module of same name
[<
CompilationRepresentation
(
CompilationRepresentationFlags
.
ModuleSuffix
)>]
[<
RequireQualifiedAccess
>]
module
Array2D
=
[<
CompilationRepresentation
(
CompilationRepresentationFlags
.
ModuleSuffix
)>]
[<
RequireQualifiedAccess
>]
module
Array2D
=
let
inline
checkNonNull
argName
arg
=
if
isNull
arg
then
nullArg
argName
let
inline
checkNonNull
argName
arg
=
if
isNull
arg
then
nullArg
argName
// Define the primitive operations.
// Note: the "type" syntax is for the type parameter for inline
// polymorphic IL. This helps the compiler inline these fragments,
// i.e. work out the correspondence between IL and F# type variables.
// Define the primitive operations.
// Note: the "type" syntax is for the type parameter for inline
// polymorphic IL. This helps the compiler inline these fragments,
// i.e. work out the correspondence between IL and F# type variables.
[<
CompiledName
(
"Length1"
)>]
let
length1
(
array
:
'
T
[,])
=
(#
"ldlen.multi 2 0"
array
:
int
#)
[<
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
(
"Length2"
)>]
let
length2
(
array
:
'
T
[,])
=
(#
"ldlen.multi 2 1"
array
:
int
#)
[<
CompiledName
(
"Base1"
)>]
let
base1
(
array
:
'
T
[,])
=
array
.
GetLowerBound
(
0
)
[<
CompiledName
(
"Base1"
)>]
let
base1
(
array
:
'
T
[,])
=
array
.
GetLowerBound
(
0
)
[<
CompiledName
(
"Base2"
)>]
let
base2
(
array
:
'
T
[,])
=
array
.
GetLowerBound
(
1
)
[<
CompiledName
(
"Base2"
)>]
let
base2
(
array
:
'
T
[,])
=
array
.
GetLowerBound
(
1
)
[<
CompiledName
(
"Get"
)>]
let
get
(
array
:
'
T
[,])
(
index1
:
int
)
(
index2
:
int
)
=
(#
"ldelem.multi 2 !0"
type
(
'
T
)
array
index1
index2
:
'
T
#)
[<
CompiledName
(
"Get"
)>]
let
get
(
array
:
'
T
[,])
(
index1
:
int
)
(
index2
:
int
)
=
(#
"ldelem.multi 2 !0"
type
(
'
T
)
array
index1
index2
:
'
T
#)
[<
CompiledName
(
"Set"
)>]
let
set
(
array
:
'
T
[,])
(
index1
:
int
)
(
index2
:
int
)
(
value
:
'
T
)
=
(#
"stelem.multi 2 !0"
type
(
'
T
)
array
index1
index2
value
#)
[<
CompiledName
(
"Set"
)>]
let
set
(
array
:
'
T
[,])
(
index1
:
int
)
(
index2
:
int
)
(
value
:
'
T
)
=
(#
"stelem.multi 2 !0"
type
(
'
T
)
array
index1
index2
value
#)
[<
CompiledName
(
"ZeroCreate"
)>]
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
(
"ZeroCreate"
)>]
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
(
base1
:
int
)
(
base2
:
int
)
(
length1
:
int
)
(
length2
:
int
)
=
if
base1
=
0
&&
base2
=
0
then
[<
CompiledName
(
"ZeroCreateBased"
)>]
let
zeroCreateBased
(
base1
:
int
)
(
base2
:
int
)
(
length1
:
int
)
(
length2
:
int
)
=
if
base1
=
0
&&
base2
=
0
then
#
if
NETSTANDARD
zeroCreate
length1
length2
zeroCreate
length1
length2
#
else
// Note: this overload is available on Compact Framework and Silverlight, but not Portable
(
System
.
Array
.
CreateInstance
(
typeof
<
'
T
>,
[|
length1
;
length2
|])
:?>
'
T
[,])
// Note: this overload is available on Compact Framework and Silverlight, but not Portable
(
System
.
Array
.
CreateInstance
(
typeof
<
'
T
>,
[|
length1
;
length2
|])
:?>
'
T
[,])
#
endif
else
(
Array
.
CreateInstance
(
typeof
<
'
T
>,
[|
length1
;
length2
|],
[|
base1
;
base2
|])
:?>
'
T
[,])
[<
CompiledName
(
"CreateBased"
)>]
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
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
length1
length2
(
value
:
'
T
)
=
createBased
0
0
length1
length2
value
[<
CompiledName
(
"Initialize"
)>]
let
init
length1
length2
initializer
=
initBased
0
0
length1
length2
initializer
[<
CompiledName
(
"Iterate"
)>]
let
iter
action
array
=
checkNonNull
"array"
array
let
count1
=
length1
array
let
count2
=
length2
array
let
b1
=
base1
array
let
b2
=
base2
array
for
i
=
b1
to
b1
+
count1
-
1
do
for
j
=
b2
to
b2
+
count2
-
1
do
action
array
.[
i
,
j
]
[<
CompiledName
(
"IterateIndexed"
)>]
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
(
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
mapping
array
=
checkNonNull
"array"
array
initBased
(
base1
array
)
(
base2
array
)
(
length1
array
)
(
length2
array
)
(
fun
i
j
->
mapping
array
.[
i
,
j
])
[<
CompiledName
(
"MapIndexed"
)>]
let
mapi
mapping
array
=
checkNonNull
"array"
array
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"
)>]
let
copy
array
=
checkNonNull
"array"
array
initBased
(
base1
array
)
(
base2
array
)
(
length1
array
)
(
length2
array
)
(
fun
i
j
->
array
.[
i
,
j
])
[<
CompiledName
(
"Rebase"
)>]
let
rebase
array
=
checkNonNull
"array"
array
let
b1
=
base1
array
let
b2
=
base2
array
init
(
length1
array
)
(
length2
array
)
(
fun
i
j
->
array
.[
b1
+
i
,
b2
+
j
])
[<
CompiledName
(
"CopyTo"
)>]
let
blit
(
source
:
'
T
[,])
sourceIndex1
sourceIndex2
(
target
:
'
T
[,])
targetIndex1
targetIndex2
count1
count2
=
checkNonNull
"source"
source
checkNonNull
"target"
target
let
sourceX0
,
sourceY0
=
source
.
GetLowerBound
0
,
source
.
GetLowerBound
1
let
sourceXN
,
sourceYN
=
(
length1
source
)
+
sourceX0
,
(
length2
source
)
+
sourceY0
let
targetX0
,
targetY0
=
target
.
GetLowerBound
0
,
target
.
GetLowerBound
1
let
targetXN
,
targetYN
=
(
length1
target
)
+
targetX0
,
(
length2
target
)
+
targetY0
if
sourceIndex1
<
sourceX0
then
invalidArgOutOfRange
"sourceIndex1"
sourceIndex1
"source axis-0 lower bound"
sourceX0
if
sourceIndex2
<
sourceY0
then
invalidArgOutOfRange
"sourceIndex2"
sourceIndex2
"source axis-1 lower bound"
sourceY0
if
targetIndex1
<
targetX0
then
invalidArgOutOfRange
"targetIndex1"
targetIndex1
"target axis-0 lower bound"
targetX0
if
targetIndex2
<
targetY0
then
invalidArgOutOfRange
"targetIndex2"
targetIndex2
"target axis-1 lower bound"
targetY0
if
sourceIndex1
+
count1
>
sourceXN
then
invalidArgOutOfRange
"count1"
count1
(
"source axis-0 end index = "
+
string
(
sourceIndex1
+
count1
)
+
" source axis-0 upper bound"
)
sourceXN
if
sourceIndex2
+
count2
>
sourceYN
then
invalidArgOutOfRange
"count2"
count2
(
"source axis-1 end index = "
+
string
(
sourceIndex2
+
count2
)
+
" source axis-1 upper bound"
)
sourceYN
if
targetIndex1
+
count1
>
targetXN
then
invalidArgOutOfRange
"count1"
count1
(
"target axis-0 end index = "
+
string
(
targetIndex1
+
count1
)
+
" target axis-0 upper bound"
)
targetXN
if
targetIndex2
+
count2
>
targetYN
then
invalidArgOutOfRange
"count2"
count2
(
"target axis-1 end index = "
+
string
(
targetIndex2
+
count2
)
+
" target axis-1 upper bound"
)
targetYN
for
i
=
0
to
count1
-
1
do
for
j
=
0
to
count2
-
1
do
target
.[
targetIndex1
+
i
,
targetIndex2
+
j
]
<-
source
.[
sourceIndex1
+
i
,
sourceIndex2
+
j
]
else
(
Array
.
CreateInstance
(
typeof
<
'
T
>,
[|
length1
;
length2
|],
[|
base1
;
base2
|])
:?>
'
T
[,])
[<
CompiledName
(
"CreateBased"
)>]
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
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
length1
length2
(
value
:
'
T
)
=
createBased
0
0
length1
length2
value
[<
CompiledName
(
"Initialize"
)>]
let
init
length1
length2
initializer
=
initBased
0
0
length1
length2
initializer
[<
CompiledName
(
"Iterate"
)>]
let
iter
action
array
=
checkNonNull
"array"
array
let
count1
=
length1
array
let
count2
=
length2
array
let
b1
=
base1
array
let
b2
=
base2
array
for
i
=
b1
to
b1
+
count1
-
1
do
for
j
=
b2
to
b2
+
count2
-
1
do
action
array
.[
i
,
j
]
[<
CompiledName
(
"IterateIndexed"
)>]
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
(
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
mapping
array
=
checkNonNull
"array"
array
initBased
(
base1
array
)
(
base2
array
)
(
length1
array
)
(
length2
array
)
(
fun
i
j
->
mapping
array
.[
i
,
j
])
[<
CompiledName
(
"MapIndexed"
)>]
let
mapi
mapping
array
=
checkNonNull
"array"
array
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"
)>]
let
copy
array
=
checkNonNull
"array"
array
initBased
(
base1
array
)
(
base2
array
)
(
length1
array
)
(
length2
array
)
(
fun
i
j
->
array
.[
i
,
j
])
[<
CompiledName
(
"Rebase"
)>]
let
rebase
array
=
checkNonNull
"array"
array
let
b1
=
base1
array
let
b2
=
base2
array
init
(
length1
array
)
(
length2
array
)
(
fun
i
j
->
array
.[
b1
+
i
,
b2
+
j
])
[<
CompiledName
(
"CopyTo"
)>]
let
blit
(
source
:
'
T
[,])
sourceIndex1
sourceIndex2
(
target
:
'
T
[,])
targetIndex1
targetIndex2
count1
count2
=
checkNonNull
"source"
source
checkNonNull
"target"
target
let
sourceX0
,
sourceY0
=
source
.
GetLowerBound
0
,
source
.
GetLowerBound
1
let
sourceXN
,
sourceYN
=
(
length1
source
)
+
sourceX0
,
(
length2
source
)
+
sourceY0
let
targetX0
,
targetY0
=
target
.
GetLowerBound
0
,
target
.
GetLowerBound
1
let
targetXN
,
targetYN
=
(
length1
target
)
+
targetX0
,
(
length2
target
)
+
targetY0
if
sourceIndex1
<
sourceX0
then
invalidArgOutOfRange
"sourceIndex1"
sourceIndex1
"source axis-0 lower bound"
sourceX0
if
sourceIndex2
<
sourceY0
then
invalidArgOutOfRange
"sourceIndex2"
sourceIndex2
"source axis-1 lower bound"
sourceY0
if
targetIndex1
<
targetX0
then
invalidArgOutOfRange
"targetIndex1"
targetIndex1
"target axis-0 lower bound"
targetX0
if
targetIndex2
<
targetY0
then
invalidArgOutOfRange
"targetIndex2"
targetIndex2
"target axis-1 lower bound"
targetY0
if
sourceIndex1
+
count1
>
sourceXN
then
invalidArgOutOfRange
"count1"
count1
(
"source axis-0 end index = "
+
string
(
sourceIndex1
+
count1
)
+
" source axis-0 upper bound"
)
sourceXN
if
sourceIndex2
+
count2
>
sourceYN
then
invalidArgOutOfRange
"count2"
count2
(
"source axis-1 end index = "
+
string
(
sourceIndex2
+
count2
)
+
" source axis-1 upper bound"
)
sourceYN
if
targetIndex1
+
count1
>
targetXN
then
invalidArgOutOfRange
"count1"
count1
(
"target axis-0 end index = "
+
string
(
targetIndex1
+
count1
)
+
" target axis-0 upper bound"
)
targetXN
if
targetIndex2
+
count2
>
targetYN
then
invalidArgOutOfRange
"count2"
count2
(
"target axis-1 end index = "
+
string
(
targetIndex2
+
count2
)
+
" target axis-1 upper bound"
)
targetYN
for
i
=
0
to
count1
-
1
do
for
j
=
0
to
count2
-
1
do
target
.[
targetIndex1
+
i
,
targetIndex2
+
j
]
<-
source
.[
sourceIndex1
+
i
,
sourceIndex2
+
j
]
src/FSharp.Core/array3.fs
浏览文件 @
972c3cbf
...
...
@@ -2,159 +2,158 @@
namespace
Microsoft
.
FSharp
.
Collections
open
System
.
Diagnostics
open
Microsoft
.
FSharp
.
Collections
open
Microsoft
.
FSharp
.
Core
open
Microsoft
.
FSharp
.
Core
.
LanguagePrimitives
.
IntrinsicOperators
open
Microsoft
.
FSharp
.
Core
.
Operators
open
Microsoft
.
FSharp
.
Core
.
Operators
.
Checked
[<
CompilationRepresentation
(
CompilationRepresentationFlags
.
ModuleSuffix
)>]
[<
RequireQualifiedAccess
>]
module
Array3D
=
let
inline
checkNonNull
argName
arg
=
if
isNull
arg
then
nullArg
argName
[<
CompiledName
(
"Length1"
)>]
let
length1
(
array
:
'
T
[,,])
=
(#
"ldlen.multi 3 0"
array
:
int
#)
[<
CompiledName
(
"Length2"
)>]
let
length2
(
array
:
'
T
[,,])
=
(#
"ldlen.multi 3 1"
array
:
int
#)
[<
CompiledName
(
"Length3"
)>]
let
length3
(
array
:
'
T
[,,])
=
(#
"ldlen.multi 3 2"
array
:
int
#)
[<
CompiledName
(
"Get"
)>]
let
get
(
array
:
'
T
[,,])
index1
index2
index3
=
array
.[
index1
,
index2
,
index3
]
[<
CompiledName
(
"Set"
)>]
let
set
(
array
:
'
T
[,,])
index1
index2
index3
value
=
array
.[
index1
,
index2
,
index3
]
<-
value
[<
CompiledName
(
"ZeroCreate"
)>]
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
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
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
action
array
=
checkNonNull
"array"
array
let
len1
=
length1
array
let
len2
=
length2
array
let
len3
=
length3
array
for
i
=
0
to
len1
-
1
do
for
j
=
0
to
len2
-
1
do
for
k
=
0
to
len3
-
1
do
action
array
.[
i
,
j
,
k
]
[<
CompiledName
(
"Map"
)>]
let
map
mapping
array
=
checkNonNull
"array"
array
let
len1
=
length1
array
let
len2
=
length2
array
let
len3
=
length3
array
let
res
=
(
zeroCreate
len1
len2
len3
:
'
b
[,,])
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
]
<-
mapping
array
.[
i
,
j
,
k
]
res
[<
CompiledName
(
"IterateIndexed"
)>]
let
iteri
action
array
=
checkNonNull
"array"
array
let
len1
=
length1
array
let
len2
=
length2
array
let
len3
=
length3
array
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
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
(
mapping
)
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
.
Invoke
(
i
,
j
,
k
,
array
.[
i
,
j
,
k
])
res
[<
CompilationRepresentation
(
CompilationRepresentationFlags
.
ModuleSuffix
)>]
[<
RequireQualifiedAccess
>]
module
Array4D
=
[<
CompiledName
(
"Length1"
)>]
let
length1
(
array
:
'
T
[,,,])
=
(#
"ldlen.multi 4 0"
array
:
int
#)
[<
CompiledName
(
"Length2"
)>]
let
length2
(
array
:
'
T
[,,,])
=
(#
"ldlen.multi 4 1"
array
:
int
#)
[<
CompiledName
(
"Length3"
)>]
let
length3
(
array
:
'
T
[,,,])
=
(#
"ldlen.multi 4 2"
array
:
int
#)
[<
CompiledName
(
"Length4"
)>]
let
length4
(
array
:
'
T
[,,,])
=
(#
"ldlen.multi 4 3"
array
:
int
#)
[<
CompiledName
(
"ZeroCreate"
)>]
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
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
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
[,,,])
index1
index2
index3
index4
=
array
.[
index1
,
index2
,
index3
,
index4
]
[<
CompiledName
(
"Set"
)>]
let
set
(
array
:
'
T
[,,,])
index1
index2
index3
index4
value
=
array
.[
index1
,
index2
,
index3
,
index4
]
<-
value
open
Microsoft
.
FSharp
.
Collections
open
Microsoft
.
FSharp
.
Core
open
Microsoft
.
FSharp
.
Core
.
LanguagePrimitives
.
IntrinsicOperators
open
Microsoft
.
FSharp
.
Core
.
Operators
open
Microsoft
.
FSharp
.
Core
.
Operators
.
Checked
[<
CompilationRepresentation
(
CompilationRepresentationFlags
.
ModuleSuffix
)>]
[<
RequireQualifiedAccess
>]
module
Array3D
=
let
inline
checkNonNull
argName
arg
=
if
isNull
arg
then
nullArg
argName
[<
CompiledName
(
"Length1"
)>]
let
length1
(
array
:
'
T
[,,])
=
(#
"ldlen.multi 3 0"
array
:
int
#)
[<
CompiledName
(
"Length2"
)>]
let
length2
(
array
:
'
T
[,,])
=
(#
"ldlen.multi 3 1"
array
:
int
#)
[<
CompiledName
(
"Length3"
)>]
let
length3
(
array
:
'
T
[,,])
=
(#
"ldlen.multi 3 2"
array
:
int
#)
[<
CompiledName
(
"Get"
)>]
let
get
(
array
:
'
T
[,,])
index1
index2
index3
=
array
.[
index1
,
index2
,
index3
]
[<
CompiledName
(
"Set"
)>]
let
set
(
array
:
'
T
[,,])
index1
index2
index3
value
=
array
.[
index1
,
index2
,
index3
]
<-
value
[<
CompiledName
(
"ZeroCreate"
)>]
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
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
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
action
array
=
checkNonNull
"array"
array
let
len1
=
length1
array
let
len2
=
length2
array
let
len3
=
length3
array
for
i
=
0
to
len1
-
1
do
for
j
=
0
to
len2
-
1
do
for
k
=
0
to
len3
-
1
do
action
array
.[
i
,
j
,
k
]
[<
CompiledName
(
"Map"
)>]
let
map
mapping
array
=
checkNonNull
"array"
array
let
len1
=
length1
array
let
len2
=
length2
array
let
len3
=
length3
array
let
res
=
(
zeroCreate
len1
len2
len3
:
'
b
[,,])
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
]
<-
mapping
array
.[
i
,
j
,
k
]
res
[<
CompiledName
(
"IterateIndexed"
)>]
let
iteri
action
array
=
checkNonNull
"array"
array
let
len1
=
length1
array
let
len2
=
length2
array
let
len3
=
length3
array
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
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
(
mapping
)
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
.
Invoke
(
i
,
j
,
k
,
array
.[
i
,
j
,
k
])
res
[<
CompilationRepresentation
(
CompilationRepresentationFlags
.
ModuleSuffix
)>]
[<
RequireQualifiedAccess
>]
module
Array4D
=
[<
CompiledName
(
"Length1"
)>]
let
length1
(
array
:
'
T
[,,,])
=
(#
"ldlen.multi 4 0"
array
:
int
#)
[<
CompiledName
(
"Length2"
)>]
let
length2
(
array
:
'
T
[,,,])
=
(#
"ldlen.multi 4 1"
array
:
int
#)
[<
CompiledName
(
"Length3"
)>]
let
length3
(
array
:
'
T
[,,,])
=
(#
"ldlen.multi 4 2"
array
:
int
#)
[<
CompiledName
(
"Length4"
)>]
let
length4
(
array
:
'
T
[,,,])
=
(#
"ldlen.multi 4 3"
array
:
int
#)
[<
CompiledName
(
"ZeroCreate"
)>]
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
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
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
[,,,])
index1
index2
index3
index4
=
array
.[
index1
,
index2
,
index3
,
index4
]
[<
CompiledName
(
"Set"
)>]
let
set
(
array
:
'
T
[,,,])
index1
index2
index3
index4
value
=
array
.[
index1
,
index2
,
index3
,
index4
]
<-
value
src/FSharp.Core/async.fs
浏览文件 @
972c3cbf
因为 它太大了无法显示 source diff 。你可以改为
查看blob
。
src/FSharp.Core/collections.fs
浏览文件 @
972c3cbf
...
...
@@ -2,49 +2,47 @@
namespace
Microsoft
.
FSharp
.
Collections
#
nowarn
"51"
open
Microsoft
.
FSharp
.
Core
open
Microsoft
.
FSharp
.
Core
.
Operators
open
System
.
Collections
.
Generic
module
HashIdentity
=
let
inline
Structural
<
'
T
when
'
T
:
equality
>
:
IEqualityComparer
<
'
T
>
=
LanguagePrimitives
.
FastGenericEqualityComparer
<
'
T
>
let
inline
LimitedStructural
<
'
T
when
'
T
:
equality
>(
limit
)
:
IEqualityComparer
<
'
T
>
=
LanguagePrimitives
.
FastLimitedGenericEqualityComparer
<
'
T
>(
limit
)
let
Reference
<
'
T
when
'
T
:
not
struct
>
:
IEqualityComparer
<
'
T
>
=
{
new
IEqualityComparer
<
'
T
>
with
member
_.
GetHashCode
(
x
)
=
LanguagePrimitives
.
PhysicalHash
(
x
)
member
_.
Equals
(
x
,
y
)
=
LanguagePrimitives
.
PhysicalEquality
x
y
}
let
inline
NonStructural
<
'
T
when
'
T
:
equality
and
'
T
:
(
static
member
(
=
)
:
'
T
*
'
T
->
bool
)
>
=
{
new
IEqualityComparer
<
'
T
>
with
member
_.
GetHashCode
(
x
)
=
NonStructuralComparison
.
hash
x
member
_.
Equals
(
x
,
y
)
=
NonStructuralComparison
.
(=)
x
y
}
let
inline
FromFunctions
hasher
equality
:
IEqualityComparer
<
'
T
>
=
let
eq
=
OptimizedClosures
.
FSharpFunc
<_,_,_>.
Adapt
(
equality
)
{
new
IEqualityComparer
<
'
T
>
with
member
_.
GetHashCode
(
x
)
=
hasher
x
member
_.
Equals
(
x
,
y
)
=
eq
.
Invoke
(
x
,
y
)
}
module
ComparisonIdentity
=
let
inline
Structural
<
'
T
when
'
T
:
comparison
>
:
IComparer
<
'
T
>
=
LanguagePrimitives
.
FastGenericComparer
<
'
T
>
let
inline
NonStructural
<
'
T
when
'
T
:
(
static
member
(
<
)
:
'
T
*
'
T
->
bool
)
and
'
T
:
(
static
member
(
>
)
:
'
T
*
'
T
->
bool
)
>
:
IComparer
<
'
T
>
=
{
new
IComparer
<
'
T
>
with
member
_.
Compare
(
x
,
y
)
=
NonStructuralComparison
.
compare
x
y
}
let
FromFunction
comparer
=
let
comparer
=
OptimizedClosures
.
FSharpFunc
<
'
T
,
'
T
,
int
>.
Adapt
(
comparer
)
{
new
IComparer
<
'
T
>
with
member
_.
Compare
(
x
,
y
)
=
comparer
.
Invoke
(
x
,
y
)
}
#
nowarn
"51"
open
Microsoft
.
FSharp
.
Core
open
Microsoft
.
FSharp
.
Core
.
Operators
open
System
.
Collections
.
Generic
module
HashIdentity
=
let
inline
Structural
<
'
T
when
'
T
:
equality
>
:
IEqualityComparer
<
'
T
>
=
LanguagePrimitives
.
FastGenericEqualityComparer
<
'
T
>
let
inline
LimitedStructural
<
'
T
when
'
T
:
equality
>(
limit
)
:
IEqualityComparer
<
'
T
>
=
LanguagePrimitives
.
FastLimitedGenericEqualityComparer
<
'
T
>(
limit
)
let
Reference
<
'
T
when
'
T
:
not
struct
>
:
IEqualityComparer
<
'
T
>
=
{
new
IEqualityComparer
<
'
T
>
with
member
_.
GetHashCode
(
x
)
=
LanguagePrimitives
.
PhysicalHash
(
x
)
member
_.
Equals
(
x
,
y
)
=
LanguagePrimitives
.
PhysicalEquality
x
y
}
let
inline
NonStructural
<
'
T
when
'
T
:
equality
and
'
T
:
(
static
member
(
=
)
:
'
T
*
'
T
->
bool
)
>
=
{
new
IEqualityComparer
<
'
T
>
with
member
_.
GetHashCode
(
x
)
=
NonStructuralComparison
.
hash
x
member
_.
Equals
(
x
,
y
)
=
NonStructuralComparison
.
(=)
x
y
}
let
inline
FromFunctions
hasher
equality
:
IEqualityComparer
<
'
T
>
=
let
eq
=
OptimizedClosures
.
FSharpFunc
<_,_,_>.
Adapt
(
equality
)
{
new
IEqualityComparer
<
'
T
>
with
member
_.
GetHashCode
(
x
)
=
hasher
x
member
_.
Equals
(
x
,
y
)
=
eq
.
Invoke
(
x
,
y
)
}
module
ComparisonIdentity
=
let
inline
Structural
<
'
T
when
'
T
:
comparison
>
:
IComparer
<
'
T
>
=
LanguagePrimitives
.
FastGenericComparer
<
'
T
>
let
inline
NonStructural
<
'
T
when
'
T
:
(
static
member
(
<
)
:
'
T
*
'
T
->
bool
)
and
'
T
:
(
static
member
(
>
)
:
'
T
*
'
T
->
bool
)
>
:
IComparer
<
'
T
>
=
{
new
IComparer
<
'
T
>
with
member
_.
Compare
(
x
,
y
)
=
NonStructuralComparison
.
compare
x
y
}
let
FromFunction
comparer
=
let
comparer
=
OptimizedClosures
.
FSharpFunc
<
'
T
,
'
T
,
int
>.
Adapt
(
comparer
)
{
new
IComparer
<
'
T
>
with
member
_.
Compare
(
x
,
y
)
=
comparer
.
Invoke
(
x
,
y
)
}
src/FSharp.Core/event.fs
浏览文件 @
972c3cbf
...
...
@@ -2,153 +2,153 @@
namespace
Microsoft
.
FSharp
.
Control
open
Microsoft
.
FSharp
.
Core
open
Microsoft
.
FSharp
.
Core
.
LanguagePrimitives
open
Microsoft
.
FSharp
.
Core
.
LanguagePrimitives
.
IntrinsicOperators
open
Microsoft
.
FSharp
.
Core
.
Operators
open
Microsoft
.
FSharp
.
Collections
open
Microsoft
.
FSharp
.
Control
open
System
.
Reflection
open
System
.
Diagnostics
module
private
Atomic
=
open
System
.
Threading
let
inline
setWith
(
thunk
:
'
a
->
'
a
)
(
value
:
byref
<
'
a
>)
=
let
mutable
exchanged
=
false
let
mutable
oldValue
=
value
while
not
exchanged
do
let
comparand
=
oldValue
let
newValue
=
thunk
comparand
oldValue
<-
Interlocked
.
CompareExchange
(&
value
,
newValue
,
comparand
)
if
obj
.
ReferenceEquals
(
comparand
,
oldValue
)
then
exchanged
<-
true
[<
CompiledName
(
"FSharpDelegateEvent`1"
)>]
type
DelegateEvent
<
'
Delegate
when
'
Delegate
:>
System
.
Delegate
>()
=
let
mutable
multicast
:
System
.
Delegate
=
null
member
x
.
Trigger
(
args
:
obj
[]
)
=
match
multicast
with
|
null
->
()
|
d
->
d
.
DynamicInvoke
(
args
)
|>
ignore
member
x
.
Publish
=
{
new
IDelegateEvent
<
'
Delegate
>
with
member
x
.
AddHandler
(
d
)
=
Atomic
.
setWith
(
fun
value
->
System
.
Delegate
.
Combine
(
value
,
d
))
&
multicast
member
x
.
RemoveHandler
(
d
)
=
Atomic
.
setWith
(
fun
value
->
System
.
Delegate
.
Remove
(
value
,
d
))
&
multicast
}
type
EventDelegee
<
'
Args
>(
observer
:
System
.
IObserver
<
'
Args
>)
=
static
let
makeTuple
=
if
Microsoft
.
FSharp
.
Reflection
.
FSharpType
.
IsTuple
(
typeof
<
'
Args
>)
then
Microsoft
.
FSharp
.
Reflection
.
FSharpValue
.
PreComputeTupleConstructor
(
typeof
<
'
Args
>)
else
fun
_
->
assert
false
;
null
// should not be called, one-argument case don't use makeTuple function
member
x
.
Invoke
(_
sender
:
obj
,
args
:
'
Args
)
=
observer
.
OnNext
args
member
x
.
Invoke
(_
sender
:
obj
,
a
,
b
)
=
let
args
=
makeTuple
([|
a
;
b
|])
:?>
'
Args
observer
.
OnNext
args
member
x
.
Invoke
(_
sender
:
obj
,
a
,
b
,
c
)
=
let
args
=
makeTuple
([|
a
;
b
;
c
|])
:?>
'
Args
observer
.
OnNext
args
member
x
.
Invoke
(_
sender
:
obj
,
a
,
b
,
c
,
d
)
=
let
args
=
makeTuple
([|
a
;
b
;
c
;
d
|])
:?>
'
Args
observer
.
OnNext
args
member
x
.
Invoke
(_
sender
:
obj
,
a
,
b
,
c
,
d
,
e
)
=
let
args
=
makeTuple
([|
a
;
b
;
c
;
d
;
e
|])
:?>
'
Args
observer
.
OnNext
args
member
x
.
Invoke
(_
sender
:
obj
,
a
,
b
,
c
,
d
,
e
,
f
)
=
let
args
=
makeTuple
([|
a
;
b
;
c
;
d
;
e
;
f
|])
:?>
'
Args
observer
.
OnNext
args
type
EventWrapper
<
'
Delegate
,
'
Args
>
=
delegate
of
'
Delegate
*
obj
*
'
Args
->
unit
[<
CompiledName
(
"FSharpEvent`2"
)>]
type
Event
<
'
Delegate
,
'
Args
when
'
Delegate
:
delegate
<
'
Args
,
unit
>
and
'
Delegate
:>
System
.
Delegate
and
'
Delegate
:
not
struct
>()
=
let
mutable
multicast
:
'
Delegate
=
Unchecked
.
defaultof
<_>
static
let
mi
,
argTypes
=
let
instanceBindingFlags
=
BindingFlags
.
Instance
|||
BindingFlags
.
Public
|||
BindingFlags
.
NonPublic
|||
BindingFlags
.
DeclaredOnly
let
mi
=
typeof
<
'
Delegate
>.
GetMethod
(
"Invoke"
,
instanceBindingFlags
)
let
actualTypes
=
mi
.
GetParameters
()
|>
Array
.
map
(
fun
p
->
p
.
ParameterType
)
mi
,
actualTypes
.[
1
..]
// For the one-argument case, use an optimization that allows a fast call.
// CreateDelegate creates a delegate that is fast to invoke.
static
let
invoker
=
if
argTypes
.
Length
=
1
then
(
System
.
Delegate
.
CreateDelegate
(
typeof
<
EventWrapper
<
'
Delegate
,
'
Args
>>,
mi
)
:?>
EventWrapper
<
'
Delegate
,
'
Args
>)
else
null
// For the multi-arg case, use a slower DynamicInvoke.
static
let
invokeInfo
=
let
instanceBindingFlags
=
BindingFlags
.
Instance
|||
BindingFlags
.
Public
|||
BindingFlags
.
NonPublic
|||
BindingFlags
.
DeclaredOnly
let
mi
=
typeof
<
EventDelegee
<
'
Args
>>.
GetMethods
(
instanceBindingFlags
)
|>
Seq
.
filter
(
fun
mi
->
mi
.
Name
=
"Invoke"
&&
mi
.
GetParameters
()
.
Length
=
argTypes
.
Length
+
1
)
|>
Seq
.
exactlyOne
if
mi
.
IsGenericMethodDefinition
then
mi
.
MakeGenericMethod
argTypes
else
mi
member
x
.
Trigger
(
sender
:
obj
,
args
:
'
Args
)
=
// Copy multicast value into local variable to avoid changing during member call.
let
multicast
=
multicast
match
box
multicast
with
|
null
->
()
open
Microsoft
.
FSharp
.
Core
open
Microsoft
.
FSharp
.
Core
.
LanguagePrimitives
open
Microsoft
.
FSharp
.
Core
.
LanguagePrimitives
.
IntrinsicOperators
open
Microsoft
.
FSharp
.
Core
.
Operators
open
Microsoft
.
FSharp
.
Collections
open
Microsoft
.
FSharp
.
Control
open
System
.
Reflection
open
System
.
Diagnostics
module
private
Atomic
=
open
System
.
Threading
let
inline
setWith
(
thunk
:
'
a
->
'
a
)
(
value
:
byref
<
'
a
>)
=
let
mutable
exchanged
=
false
let
mutable
oldValue
=
value
while
not
exchanged
do
let
comparand
=
oldValue
let
newValue
=
thunk
comparand
oldValue
<-
Interlocked
.
CompareExchange
(&
value
,
newValue
,
comparand
)
if
obj
.
ReferenceEquals
(
comparand
,
oldValue
)
then
exchanged
<-
true
[<
CompiledName
(
"FSharpDelegateEvent`1"
)>]
type
DelegateEvent
<
'
Delegate
when
'
Delegate
:>
System
.
Delegate
>()
=
let
mutable
multicast
:
System
.
Delegate
=
null
member
x
.
Trigger
(
args
:
obj
[]
)
=
match
multicast
with
|
null
->
()
|
d
->
d
.
DynamicInvoke
(
args
)
|>
ignore
member
x
.
Publish
=
{
new
IDelegateEvent
<
'
Delegate
>
with
member
x
.
AddHandler
(
d
)
=
Atomic
.
setWith
(
fun
value
->
System
.
Delegate
.
Combine
(
value
,
d
))
&
multicast
member
x
.
RemoveHandler
(
d
)
=
Atomic
.
setWith
(
fun
value
->
System
.
Delegate
.
Remove
(
value
,
d
))
&
multicast
}
type
EventDelegee
<
'
Args
>(
observer
:
System
.
IObserver
<
'
Args
>)
=
static
let
makeTuple
=
if
Microsoft
.
FSharp
.
Reflection
.
FSharpType
.
IsTuple
(
typeof
<
'
Args
>)
then
Microsoft
.
FSharp
.
Reflection
.
FSharpValue
.
PreComputeTupleConstructor
(
typeof
<
'
Args
>)
else
fun
_
->
assert
false
;
null
// should not be called, one-argument case don't use makeTuple function
member
x
.
Invoke
(_
sender
:
obj
,
args
:
'
Args
)
=
observer
.
OnNext
args
member
x
.
Invoke
(_
sender
:
obj
,
a
,
b
)
=
let
args
=
makeTuple
([|
a
;
b
|])
:?>
'
Args
observer
.
OnNext
args
member
x
.
Invoke
(_
sender
:
obj
,
a
,
b
,
c
)
=
let
args
=
makeTuple
([|
a
;
b
;
c
|])
:?>
'
Args
observer
.
OnNext
args
member
x
.
Invoke
(_
sender
:
obj
,
a
,
b
,
c
,
d
)
=
let
args
=
makeTuple
([|
a
;
b
;
c
;
d
|])
:?>
'
Args
observer
.
OnNext
args
member
x
.
Invoke
(_
sender
:
obj
,
a
,
b
,
c
,
d
,
e
)
=
let
args
=
makeTuple
([|
a
;
b
;
c
;
d
;
e
|])
:?>
'
Args
observer
.
OnNext
args
member
x
.
Invoke
(_
sender
:
obj
,
a
,
b
,
c
,
d
,
e
,
f
)
=
let
args
=
makeTuple
([|
a
;
b
;
c
;
d
;
e
;
f
|])
:?>
'
Args
observer
.
OnNext
args
type
EventWrapper
<
'
Delegate
,
'
Args
>
=
delegate
of
'
Delegate
*
obj
*
'
Args
->
unit
[<
CompiledName
(
"FSharpEvent`2"
)>]
type
Event
<
'
Delegate
,
'
Args
when
'
Delegate
:
delegate
<
'
Args
,
unit
>
and
'
Delegate
:>
System
.
Delegate
and
'
Delegate
:
not
struct
>()
=
let
mutable
multicast
:
'
Delegate
=
Unchecked
.
defaultof
<_>
static
let
mi
,
argTypes
=
let
instanceBindingFlags
=
BindingFlags
.
Instance
|||
BindingFlags
.
Public
|||
BindingFlags
.
NonPublic
|||
BindingFlags
.
DeclaredOnly
let
mi
=
typeof
<
'
Delegate
>.
GetMethod
(
"Invoke"
,
instanceBindingFlags
)
let
actualTypes
=
mi
.
GetParameters
()
|>
Array
.
map
(
fun
p
->
p
.
ParameterType
)
mi
,
actualTypes
.[
1
..]
// For the one-argument case, use an optimization that allows a fast call.
// CreateDelegate creates a delegate that is fast to invoke.
static
let
invoker
=
if
argTypes
.
Length
=
1
then
(
System
.
Delegate
.
CreateDelegate
(
typeof
<
EventWrapper
<
'
Delegate
,
'
Args
>>,
mi
)
:?>
EventWrapper
<
'
Delegate
,
'
Args
>)
else
null
// For the multi-arg case, use a slower DynamicInvoke.
static
let
invokeInfo
=
let
instanceBindingFlags
=
BindingFlags
.
Instance
|||
BindingFlags
.
Public
|||
BindingFlags
.
NonPublic
|||
BindingFlags
.
DeclaredOnly
let
mi
=
typeof
<
EventDelegee
<
'
Args
>>.
GetMethods
(
instanceBindingFlags
)
|>
Seq
.
filter
(
fun
mi
->
mi
.
Name
=
"Invoke"
&&
mi
.
GetParameters
()
.
Length
=
argTypes
.
Length
+
1
)
|>
Seq
.
exactlyOne
if
mi
.
IsGenericMethodDefinition
then
mi
.
MakeGenericMethod
argTypes
else
mi
member
x
.
Trigger
(
sender
:
obj
,
args
:
'
Args
)
=
// Copy multicast value into local variable to avoid changing during member call.
let
multicast
=
multicast
match
box
multicast
with
|
null
->
()
|
_
->
match
invoker
with
|
null
->
let
args
=
Array
.
append
[|
sender
|]
(
Microsoft
.
FSharp
.
Reflection
.
FSharpValue
.
GetTupleFields
(
box
args
))
multicast
.
DynamicInvoke
(
args
)
|>
ignore
|
_
->
match
invoker
with
|
null
->
let
args
=
Array
.
append
[|
sender
|]
(
Microsoft
.
FSharp
.
Reflection
.
FSharpValue
.
GetTupleFields
(
box
args
))
multicast
.
DynamicInvoke
(
args
)
|>
ignore
|
_
->
// For the one-argument case, use an optimization that allows a fast call.
// CreateDelegate creates a delegate that is fast to invoke.
invoker
.
Invoke
(
multicast
,
sender
,
args
)
|>
ignore
member
x
.
Publish
=
{
new
obj
()
with
member
x
.
ToString
()
=
"<published event>"
interface
IEvent
<
'
Delegate
,
'
Args
>
with
member
e
.
AddHandler
(
d
)
=
Atomic
.
setWith
(
fun
value
->
System
.
Delegate
.
Combine
(
value
,
d
)
:?>
'
Delegate
)
&
multicast
member
e
.
RemoveHandler
(
d
)
=
Atomic
.
setWith
(
fun
value
->
System
.
Delegate
.
Remove
(
value
,
d
)
:?>
'
Delegate
)
&
multicast
interface
System
.
IObservable
<
'
Args
>
with
member
e
.
Subscribe
(
observer
)
=
let
obj
=
new
EventDelegee
<
'
Args
>(
observer
)
let
h
=
System
.
Delegate
.
CreateDelegate
(
typeof
<
'
Delegate
>,
obj
,
invokeInfo
)
:?>
'
Delegate
(
e
:?>
IDelegateEvent
<
'
Delegate
>).
AddHandler
(
h
)
{
new
System
.
IDisposable
with
member
x
.
Dispose
()
=
(
e
:?>
IDelegateEvent
<
'
Delegate
>).
RemoveHandler
(
h
)
}
}
[<
CompiledName
(
"FSharpEvent`1"
)>]
type
Event
<
'
T
>
=
val
mutable
multicast
:
Handler
<
'
T
>
new
()
=
{
multicast
=
null
}
member
x
.
Trigger
(
arg
:
'
T
)
=
match
x
.
multicast
with
|
null
->
()
|
d
->
d
.
Invoke
(
null
,
arg
)
|>
ignore
member
x
.
Publish
=
{
new
obj
()
with
member
x
.
ToString
()
=
"<published event>"
interface
IEvent
<
'
T
>
with
member
e
.
AddHandler
(
d
)
=
Atomic
.
setWith
(
fun
value
->
System
.
Delegate
.
Combine
(
value
,
d
)
:?>
Handler
<
'
T
>)
&
x
.
multicast
member
e
.
RemoveHandler
(
d
)
=
Atomic
.
setWith
(
fun
value
->
System
.
Delegate
.
Remove
(
value
,
d
)
:?>
Handler
<
'
T
>)
&
x
.
multicast
interface
System
.
IObservable
<
'
T
>
with
member
e
.
Subscribe
(
observer
)
=
let
h
=
new
Handler
<_>(
fun
sender
args
->
observer
.
OnNext
(
args
))
(
e
:?>
IEvent
<_,_>).
AddHandler
(
h
)
{
new
System
.
IDisposable
with
member
x
.
Dispose
()
=
(
e
:?>
IEvent
<_,_>).
RemoveHandler
(
h
)
}
}
// For the one-argument case, use an optimization that allows a fast call.
// CreateDelegate creates a delegate that is fast to invoke.
invoker
.
Invoke
(
multicast
,
sender
,
args
)
|>
ignore
member
x
.
Publish
=
{
new
obj
()
with
member
x
.
ToString
()
=
"<published event>"
interface
IEvent
<
'
Delegate
,
'
Args
>
with
member
e
.
AddHandler
(
d
)
=
Atomic
.
setWith
(
fun
value
->
System
.
Delegate
.
Combine
(
value
,
d
)
:?>
'
Delegate
)
&
multicast
member
e
.
RemoveHandler
(
d
)
=
Atomic
.
setWith
(
fun
value
->
System
.
Delegate
.
Remove
(
value
,
d
)
:?>
'
Delegate
)
&
multicast
interface
System
.
IObservable
<
'
Args
>
with
member
e
.
Subscribe
(
observer
)
=
let
obj
=
new
EventDelegee
<
'
Args
>(
observer
)
let
h
=
System
.
Delegate
.
CreateDelegate
(
typeof
<
'
Delegate
>,
obj
,
invokeInfo
)
:?>
'
Delegate
(
e
:?>
IDelegateEvent
<
'
Delegate
>).
AddHandler
(
h
)
{
new
System
.
IDisposable
with
member
x
.
Dispose
()
=
(
e
:?>
IDelegateEvent
<
'
Delegate
>).
RemoveHandler
(
h
)
}
}
[<
CompiledName
(
"FSharpEvent`1"
)>]
type
Event
<
'
T
>
=
val
mutable
multicast
:
Handler
<
'
T
>
new
()
=
{
multicast
=
null
}
member
x
.
Trigger
(
arg
:
'
T
)
=
match
x
.
multicast
with
|
null
->
()
|
d
->
d
.
Invoke
(
null
,
arg
)
|>
ignore
member
x
.
Publish
=
{
new
obj
()
with
member
x
.
ToString
()
=
"<published event>"
interface
IEvent
<
'
T
>
with
member
e
.
AddHandler
(
d
)
=
Atomic
.
setWith
(
fun
value
->
System
.
Delegate
.
Combine
(
value
,
d
)
:?>
Handler
<
'
T
>)
&
x
.
multicast
member
e
.
RemoveHandler
(
d
)
=
Atomic
.
setWith
(
fun
value
->
System
.
Delegate
.
Remove
(
value
,
d
)
:?>
Handler
<
'
T
>)
&
x
.
multicast
interface
System
.
IObservable
<
'
T
>
with
member
e
.
Subscribe
(
observer
)
=
let
h
=
new
Handler
<_>(
fun
sender
args
->
observer
.
OnNext
(
args
))
(
e
:?>
IEvent
<_,_>).
AddHandler
(
h
)
{
new
System
.
IDisposable
with
member
x
.
Dispose
()
=
(
e
:?>
IEvent
<_,_>).
RemoveHandler
(
h
)
}
}
src/FSharp.Core/eventmodule.fs
浏览文件 @
972c3cbf
...
...
@@ -2,80 +2,80 @@
namespace
Microsoft
.
FSharp
.
Control
open
Microsoft
.
FSharp
.
Core
open
Microsoft
.
FSharp
.
Control
open
Microsoft
.
FSharp
.
Core
open
Microsoft
.
FSharp
.
Control
[<
CompilationRepresentation
(
CompilationRepresentationFlags
.
ModuleSuffix
)>]
[<
RequireQualifiedAccess
>]
module
Event
=
[<
CompiledName
(
"Create"
)>]
let
create
<
'
T
>()
=
let
ev
=
new
Event
<
'
T
>()
ev
.
Trigger
,
ev
.
Publish
[<
CompilationRepresentation
(
CompilationRepresentationFlags
.
ModuleSuffix
)>]
[<
RequireQualifiedAccess
>]
module
Event
=
[<
CompiledName
(
"Create"
)>]
let
create
<
'
T
>()
=
let
ev
=
new
Event
<
'
T
>()
ev
.
Trigger
,
ev
.
Publish
[<
CompiledName
(
"Map"
)>]
let
map
mapping
(
sourceEvent
:
IEvent
<
'
Delegate
,
'
T
>)
=
let
ev
=
new
Event
<_>()
sourceEvent
.
Add
(
fun
x
->
ev
.
Trigger
(
mapping
x
))
ev
.
Publish
[<
CompiledName
(
"Map"
)>]
let
map
mapping
(
sourceEvent
:
IEvent
<
'
Delegate
,
'
T
>)
=
let
ev
=
new
Event
<_>()
sourceEvent
.
Add
(
fun
x
->
ev
.
Trigger
(
mapping
x
))
ev
.
Publish
[<
CompiledName
(
"Filter"
)>]
let
filter
predicate
(
sourceEvent
:
IEvent
<
'
Delegate
,
'
T
>)
=
let
ev
=
new
Event
<_>()
sourceEvent
.
Add
(
fun
x
->
if
predicate
x
then
ev
.
Trigger
x
)
ev
.
Publish
[<
CompiledName
(
"Filter"
)>]
let
filter
predicate
(
sourceEvent
:
IEvent
<
'
Delegate
,
'
T
>)
=
let
ev
=
new
Event
<_>()
sourceEvent
.
Add
(
fun
x
->
if
predicate
x
then
ev
.
Trigger
x
)
ev
.
Publish
[<
CompiledName
(
"Partition"
)>]
let
partition
predicate
(
sourceEvent
:
IEvent
<
'
Delegate
,
'
T
>)
=
let
ev1
=
new
Event
<_>()
let
ev2
=
new
Event
<_>()
sourceEvent
.
Add
(
fun
x
->
if
predicate
x
then
ev1
.
Trigger
x
else
ev2
.
Trigger
x
)
ev1
.
Publish
,
ev2
.
Publish
[<
CompiledName
(
"Partition"
)>]
let
partition
predicate
(
sourceEvent
:
IEvent
<
'
Delegate
,
'
T
>)
=
let
ev1
=
new
Event
<_>()
let
ev2
=
new
Event
<_>()
sourceEvent
.
Add
(
fun
x
->
if
predicate
x
then
ev1
.
Trigger
x
else
ev2
.
Trigger
x
)
ev1
.
Publish
,
ev2
.
Publish
[<
CompiledName
(
"Choose"
)>]
let
choose
chooser
(
sourceEvent
:
IEvent
<
'
Delegate
,
'
T
>)
=
let
ev
=
new
Event
<_>()
sourceEvent
.
Add
(
fun
x
->
match
chooser
x
with
None
->
()
|
Some
r
->
ev
.
Trigger
r
)
ev
.
Publish
[<
CompiledName
(
"Choose"
)>]
let
choose
chooser
(
sourceEvent
:
IEvent
<
'
Delegate
,
'
T
>)
=
let
ev
=
new
Event
<_>()
sourceEvent
.
Add
(
fun
x
->
match
chooser
x
with
None
->
()
|
Some
r
->
ev
.
Trigger
r
)
ev
.
Publish
[<
CompiledName
(
"Scan"
)>]
let
scan
collector
state
(
sourceEvent
:
IEvent
<
'
Delegate
,
'
T
>)
=
let
mutable
state
=
state
let
ev
=
new
Event
<_>()
sourceEvent
.
Add
(
fun
msg
->
let
z
=
state
let
z
=
collector
z
msg
state
<-
z
;
ev
.
Trigger
(
z
))
ev
.
Publish
[<
CompiledName
(
"Scan"
)>]
let
scan
collector
state
(
sourceEvent
:
IEvent
<
'
Delegate
,
'
T
>)
=
let
mutable
state
=
state
let
ev
=
new
Event
<_>()
sourceEvent
.
Add
(
fun
msg
->
let
z
=
state
let
z
=
collector
z
msg
state
<-
z
;
ev
.
Trigger
(
z
))
ev
.
Publish
[<
CompiledName
(
"Add"
)>]
let
add
callback
(
sourceEvent
:
IEvent
<
'
Delegate
,
'
T
>)
=
sourceEvent
.
Add
(
callback
)
[<
CompiledName
(
"Add"
)>]
let
add
callback
(
sourceEvent
:
IEvent
<
'
Delegate
,
'
T
>)
=
sourceEvent
.
Add
(
callback
)
[<
CompiledName
(
"Pairwise"
)>]
let
pairwise
(
sourceEvent
:
IEvent
<
'
Delegate
,
'
T
>)
:
IEvent
<
'
T
*
'
T
>
=
let
ev
=
new
Event
<
'
T
*
'
T
>()
let
mutable
lastArgs
=
None
sourceEvent
.
Add
(
fun
args2
->
(
match
lastArgs
with
|
None
->
()
|
Some
args1
->
ev
.
Trigger
(
args1
,
args2
))
lastArgs
<-
Some
args2
)
[<
CompiledName
(
"Pairwise"
)>]
let
pairwise
(
sourceEvent
:
IEvent
<
'
Delegate
,
'
T
>)
:
IEvent
<
'
T
*
'
T
>
=
let
ev
=
new
Event
<
'
T
*
'
T
>()
let
mutable
lastArgs
=
None
sourceEvent
.
Add
(
fun
args2
->
(
match
lastArgs
with
|
None
->
()
|
Some
args1
->
ev
.
Trigger
(
args1
,
args2
))
lastArgs
<-
Some
args2
)
ev
.
Publish
ev
.
Publish
[<
CompiledName
(
"Merge"
)>]
let
merge
(
event1
:
IEvent
<
'
Del1
,
'
T
>)
(
event2
:
IEvent
<
'
Del2
,
'
T
>)
=
let
ev
=
new
Event
<_>()
event1
.
Add
(
fun
x
->
ev
.
Trigger
(
x
))
event2
.
Add
(
fun
x
->
ev
.
Trigger
(
x
))
ev
.
Publish
[<
CompiledName
(
"Merge"
)>]
let
merge
(
event1
:
IEvent
<
'
Del1
,
'
T
>)
(
event2
:
IEvent
<
'
Del2
,
'
T
>)
=
let
ev
=
new
Event
<_>()
event1
.
Add
(
fun
x
->
ev
.
Trigger
(
x
))
event2
.
Add
(
fun
x
->
ev
.
Trigger
(
x
))
ev
.
Publish
[<
CompiledName
(
"Split"
)>]
let
split
(
splitter
:
'
T
->
Choice
<
'
U1
,
'
U2
>)
(
sourceEvent
:
IEvent
<
'
Delegate
,
'
T
>)
=
let
ev1
=
new
Event
<_>()
let
ev2
=
new
Event
<_>()
sourceEvent
.
Add
(
fun
x
->
match
splitter
x
with
Choice1Of2
y
->
ev1
.
Trigger
(
y
)
|
Choice2Of2
z
->
ev2
.
Trigger
(
z
))
ev1
.
Publish
,
ev2
.
Publish
[<
CompiledName
(
"Split"
)>]
let
split
(
splitter
:
'
T
->
Choice
<
'
U1
,
'
U2
>)
(
sourceEvent
:
IEvent
<
'
Delegate
,
'
T
>)
=
let
ev1
=
new
Event
<_>()
let
ev2
=
new
Event
<_>()
sourceEvent
.
Add
(
fun
x
->
match
splitter
x
with
Choice1Of2
y
->
ev1
.
Trigger
(
y
)
|
Choice2Of2
z
->
ev2
.
Trigger
(
z
))
ev1
.
Publish
,
ev2
.
Publish
src/FSharp.Core/fslib-extra-pervasives.fs
浏览文件 @
972c3cbf
...
...
@@ -8,11 +8,9 @@ module ExtraTopLevelOperators =
open
System
.
Collections
.
Generic
open
System
.
IO
open
System
.
Diagnostics
open
System
.
Reflection
open
Microsoft
.
FSharp
open
Microsoft
.
FSharp
.
Core
open
Microsoft
.
FSharp
.
Core
.
Operators
open
Microsoft
.
FSharp
.
Text
open
Microsoft
.
FSharp
.
Collections
open
Microsoft
.
FSharp
.
Control
open
Microsoft
.
FSharp
.
Primitives
.
Basics
...
...
@@ -46,70 +44,96 @@ module ExtraTopLevelOperators =
#
if
NETSTANDARD
static
let
emptyEnumerator
=
(
Array
.
empty
<
KeyValuePair
<
'
Key
,
'
T
>>
:>
seq
<_>).
GetEnumerator
()
#
endif
member
x
.
Count
=
t
.
Count
member
_
.
Count
=
t
.
Count
// Give a read-only view of the dictionary
interface
IDictionary
<
'
Key
,
'
T
>
with
member
s
.
Item
member
_
.
Item
with
get
x
=
dont_tail_call
(
fun
()
->
t
.[
makeSafeKey
x
])
and
set
_
_
=
raise
(
NotSupportedException
(
SR
.
GetString
(
SR
.
thisValueCannotBeMutated
)))
member
s
.
Keys
=
member
_.
Keys
=
let
keys
=
t
.
Keys
{
new
ICollection
<
'
Key
>
with
member
s
.
Add
(
x
)
=
raise
(
NotSupportedException
(
SR
.
GetString
(
SR
.
thisValueCannotBeMutated
)))
member
s
.
Clear
()
=
raise
(
NotSupportedException
(
SR
.
GetString
(
SR
.
thisValueCannotBeMutated
)))
member
s
.
Remove
(
x
)
=
raise
(
NotSupportedException
(
SR
.
GetString
(
SR
.
thisValueCannotBeMutated
)))
member
s
.
Contains
(
x
)
=
t
.
ContainsKey
(
makeSafeKey
x
)
member
s
.
CopyTo
(
arr
,
i
)
=
member
_.
Add
(
x
)
=
raise
(
NotSupportedException
(
SR
.
GetString
(
SR
.
thisValueCannotBeMutated
)))
member
_.
Clear
()
=
raise
(
NotSupportedException
(
SR
.
GetString
(
SR
.
thisValueCannotBeMutated
)))
member
_.
Remove
(
x
)
=
raise
(
NotSupportedException
(
SR
.
GetString
(
SR
.
thisValueCannotBeMutated
)))
member
_.
Contains
(
x
)
=
t
.
ContainsKey
(
makeSafeKey
x
)
member
_.
CopyTo
(
arr
,
i
)
=
let
mutable
n
=
0
for
k
in
keys
do
arr
.[
i
+
n
]
<-
getKey
k
n
<-
n
+
1
member
s
.
IsReadOnly
=
true
member
s
.
Count
=
keys
.
Count
member
_.
IsReadOnly
=
true
member
_.
Count
=
keys
.
Count
interface
IEnumerable
<
'
Key
>
with
member
s
.
GetEnumerator
()
=
(
keys
|>
Seq
.
map
getKey
).
GetEnumerator
()
member
_.
GetEnumerator
()
=
(
keys
|>
Seq
.
map
getKey
).
GetEnumerator
()
interface
System
.
Collections
.
IEnumerable
with
member
s
.
GetEnumerator
()
=
((
keys
|>
Seq
.
map
getKey
)
:>
System
.
Collections
.
IEnumerable
).
GetEnumerator
()
}
member
_
.
GetEnumerator
()
=
((
keys
|>
Seq
.
map
getKey
)
:>
System
.
Collections
.
IEnumerable
).
GetEnumerator
()
}
member
s
.
Values
=
upcast
t
.
Values
member
s
.
Add
(_,_)
=
raise
(
NotSupportedException
(
SR
.
GetString
(
SR
.
thisValueCannotBeMutated
)))
member
s
.
ContainsKey
(
k
)
=
dont_tail_call
(
fun
()
->
t
.
ContainsKey
(
makeSafeKey
k
))
member
s
.
TryGetValue
(
k
,
r
)
=
member
_.
Values
=
upcast
t
.
Values
member
_.
Add
(_,_)
=
raise
(
NotSupportedException
(
SR
.
GetString
(
SR
.
thisValueCannotBeMutated
)))
member
_.
ContainsKey
(
k
)
=
dont_tail_call
(
fun
()
->
t
.
ContainsKey
(
makeSafeKey
k
))
member
_.
TryGetValue
(
k
,
r
)
=
let
safeKey
=
makeSafeKey
k
if
t
.
ContainsKey
(
safeKey
)
then
(
r
<-
t
.[
safeKey
];
true
)
else
false
member
s
.
Remove
(_
:
'
Key
)
=
(
raise
(
NotSupportedException
(
SR
.
GetString
(
SR
.
thisValueCannotBeMutated
)))
:
bool
)
member
_.
Remove
(_
:
'
Key
)
=
(
raise
(
NotSupportedException
(
SR
.
GetString
(
SR
.
thisValueCannotBeMutated
)))
:
bool
)
interface
IReadOnlyDictionary
<
'
Key
,
'
T
>
with
member
_.
Item
with
get
key
=
t
.[
makeSafeKey
key
]
member
_.
Keys
=
t
.
Keys
|>
Seq
.
map
getKey
member
_.
TryGetValue
(
key
,
r
)
=
match
t
.
TryGetValue
(
makeSafeKey
key
)
with
|
false
,
_
->
false
|
true
,
value
->
r
<-
value
true
member
_.
Values
=
(
t
:>
IReadOnlyDictionary
<_,_>).
Values
member
_.
ContainsKey
k
=
t
.
ContainsKey
(
makeSafeKey
k
)
interface
ICollection
<
KeyValuePair
<
'
Key
,
'
T
>>
with
member
s
.
Add
(_)
=
raise
(
NotSupportedException
(
SR
.
GetString
(
SR
.
thisValueCannotBeMutated
)))
member
s
.
Clear
()
=
raise
(
NotSupportedException
(
SR
.
GetString
(
SR
.
thisValueCannotBeMutated
)))
member
s
.
Remove
(_)
=
raise
(
NotSupportedException
(
SR
.
GetString
(
SR
.
thisValueCannotBeMutated
)))
member
s
.
Contains
(
KeyValue
(
k
,
v
))
=
ICollection_Contains
t
(
KeyValuePair
<_,_>(
makeSafeKey
k
,
v
))
member
s
.
CopyTo
(
arr
,
i
)
=
member
_.
Add
(_)
=
raise
(
NotSupportedException
(
SR
.
GetString
(
SR
.
thisValueCannotBeMutated
)))
member
_.
Clear
()
=
raise
(
NotSupportedException
(
SR
.
GetString
(
SR
.
thisValueCannotBeMutated
)))
member
_.
Remove
(_)
=
raise
(
NotSupportedException
(
SR
.
GetString
(
SR
.
thisValueCannotBeMutated
)))
member
_.
Contains
(
KeyValue
(
k
,
v
))
=
ICollection_Contains
t
(
KeyValuePair
<_,_>(
makeSafeKey
k
,
v
))
member
_.
CopyTo
(
arr
,
i
)
=
let
mutable
n
=
0
for
(
KeyValue
(
k
,
v
))
in
t
do
arr
.[
i
+
n
]
<-
KeyValuePair
<_,_>(
getKey
k
,
v
)
n
<-
n
+
1
member
s
.
IsReadOnly
=
true
member
s
.
Count
=
t
.
Count
member
_.
IsReadOnly
=
true
member
_.
Count
=
t
.
Count
interface
IReadOnlyCollection
<
KeyValuePair
<
'
Key
,
'
T
>>
with
member
_.
Count
=
t
.
Count
interface
IEnumerable
<
KeyValuePair
<
'
Key
,
'
T
>>
with
member
s
.
GetEnumerator
()
=
member
_.
GetEnumerator
()
=
// We use an array comprehension here instead of seq {} as otherwise we get incorrect
// IEnumerator.Reset() and IEnumerator.Current semantics.
// Coreclr has a bug with SZGenericEnumerators --- implement a correct enumerator. On desktop use the desktop implementation because it's ngened.
...
...
@@ -129,20 +153,24 @@ module ExtraTopLevelOperators =
{
new
IEnumerator
<_>
with
member
_.
Current
=
current
()
interface
System
.
Collections
.
IEnumerator
with
member
_.
Current
=
box
(
current
()
)
member
_.
MoveNext
()
=
if
index
<
endIndex
then
index
<-
index
+
1
index
<
endIndex
else
false
member
_.
Reset
()
=
index
<-
-
1
interface
System
.
IDisposable
with
member
self
.
Dispose
()
=
()
}
member
_
.
Dispose
()
=
()
}
#
endif
interface
System
.
Collections
.
IEnumerable
with
member
s
.
GetEnumerator
()
=
member
_
.
GetEnumerator
()
=
// We use an array comprehension here instead of seq {} as otherwise we get incorrect
// IEnumerator.Reset() and IEnumerator.Current semantics.
let
kvps
=
[|
for
(
KeyValue
(
k
,
v
))
in
t
->
KeyValuePair
(
getKey
k
,
v
)
|]
:>
System
.
Collections
.
IEnumerable
...
...
@@ -150,7 +178,7 @@ module ExtraTopLevelOperators =
and
DictDebugView
<
'
SafeKey
,
'
Key
,
'
T
>(
d
:
DictImpl
<
'
SafeKey
,
'
Key
,
'
T
>)
=
[<
DebuggerBrowsable
(
DebuggerBrowsableState
.
RootHidden
)>]
member
x
.
Items
=
Array
.
ofSeq
d
member
_
.
Items
=
Array
.
ofSeq
d
let
inline
dictImpl
(
comparer
:
IEqualityComparer
<
'
SafeKey
>)
(
makeSafeKey
:
'
Key
->
'
SafeKey
)
(
getKey
:
'
SafeKey
->
'
Key
)
(
l
:
seq
<
'
Key
*
'
T
>)
=
let
t
=
Dictionary
comparer
...
...
@@ -159,22 +187,26 @@ module ExtraTopLevelOperators =
DictImpl
(
t
,
makeSafeKey
,
getKey
)
// We avoid wrapping a StructBox, because under 64 JIT we get some "hard" tailcalls which affect performance
let
dictValueType
(
l
:
seq
<
'
Key
*
'
T
>)
=
dictImpl
HashIdentity
.
Structural
<
'
Key
>
id
id
l
let
dictValueType
(
l
:
seq
<
'
Key
*
'
T
>)
=
dictImpl
HashIdentity
.
Structural
<
'
Key
>
id
id
l
// Wrap a StructBox around all keys in case the key type is itself a type using null as a representation
let
dictRefType
(
l
:
seq
<
'
Key
*
'
T
>)
=
dictImpl
RuntimeHelpers
.
StructBox
<
'
Key
>.
Comparer
(
fun
k
->
RuntimeHelpers
.
StructBox
k
)
(
fun
sb
->
sb
.
Value
)
l
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
(
keyValuePairs
:
seq
<
'
Key
*
'
T
>)
:
IDictionary
<
'
Key
,
'
T
>
=
if
typeof
<
'
Key
>.
IsValueType
then
dictValueType
keyValuePairs
:>
_
else
dictRefType
keyValuePairs
:>
_
if
typeof
<
'
Key
>.
IsValueType
then
dictValueType
keyValuePairs
else
dictRefType
keyValuePairs
[<
CompiledName
(
"CreateReadOnlyDictionary"
)>]
let
readOnlyDict
(
keyValuePairs
:
seq
<
'
Key
*
'
T
>)
:
IReadOnlyDictionary
<
'
Key
,
'
T
>
=
if
typeof
<
'
Key
>.
IsValueType
then
dictValueType
keyValuePairs
:>
_
else
dictRefType
keyValuePairs
:>
_
if
typeof
<
'
Key
>.
IsValueType
then
dictValueType
keyValuePairs
else
dictRefType
keyValuePairs
let
getArray
(
vals
:
seq
<
'
T
>)
=
match
vals
with
...
...
@@ -203,36 +235,41 @@ module ExtraTopLevelOperators =
res
.[
i
,
j
]
<-
rowiArr
.[
j
]
res
// --------------------------------------------------------------------
// Printf
// --------------------------------------------------------------------
[<
CompiledName
(
"PrintFormatToString"
)>]
let
sprintf
format
=
Printf
.
sprintf
format
let
sprintf
format
=
Printf
.
sprintf
format
[<
CompiledName
(
"PrintFormatToStringThenFail"
)>]
let
failwithf
format
=
Printf
.
failwithf
format
let
failwithf
format
=
Printf
.
failwithf
format
[<
CompiledName
(
"PrintFormatToTextWriter"
)>]
let
fprintf
(
textWriter
:
TextWriter
)
format
=
Printf
.
fprintf
textWriter
format
let
fprintf
(
textWriter
:
TextWriter
)
format
=
Printf
.
fprintf
textWriter
format
[<
CompiledName
(
"PrintFormatLineToTextWriter"
)>]
let
fprintfn
(
textWriter
:
TextWriter
)
format
=
Printf
.
fprintfn
textWriter
format
let
fprintfn
(
textWriter
:
TextWriter
)
format
=
Printf
.
fprintfn
textWriter
format
[<
CompiledName
(
"PrintFormat"
)>]
let
printf
format
=
Printf
.
printf
format
let
printf
format
=
Printf
.
printf
format
[<
CompiledName
(
"PrintFormatToError"
)>]
let
eprintf
format
=
Printf
.
eprintf
format
let
eprintf
format
=
Printf
.
eprintf
format
[<
CompiledName
(
"PrintFormatLine"
)>]
let
printfn
format
=
Printf
.
printfn
format
let
printfn
format
=
Printf
.
printfn
format
[<
CompiledName
(
"PrintFormatLineToError"
)>]
let
eprintfn
format
=
Printf
.
eprintfn
format
let
eprintfn
format
=
Printf
.
eprintfn
format
[<
CompiledName
(
"FailWith"
)>]
let
failwith
s
=
raise
(
Failure
s
)
let
failwith
s
=
raise
(
Failure
s
)
[<
CompiledName
(
"DefaultAsyncBuilder"
)>]
let
async
=
AsyncBuilder
()
...
...
@@ -282,7 +319,8 @@ module ExtraTopLevelOperators =
do
()
[<
CompiledName
(
"LazyPattern"
)>]
let
(|
Lazy
|)
(
input
:
Lazy
<_>)
=
input
.
Force
()
let
(|
Lazy
|)
(
input
:
Lazy
<_>)
=
input
.
Force
()
let
query
=
Microsoft
.
FSharp
.
Linq
.
QueryBuilder
()
...
...
@@ -291,9 +329,9 @@ namespace Microsoft.FSharp.Core.CompilerServices
open
System
open
System
.
Reflection
open
System
.
Linq
.
Expressions
open
System
.
Collections
.
Generic
open
Microsoft
.
FSharp
.
Core
open
Microsoft
.
FSharp
.
Control
open
Microsoft
.
FSharp
.
Quotations
/// <summary>Represents the product of two measure expressions when returned as a generic argument of a provided type.</summary>
[<
Sealed
>]
...
...
@@ -315,11 +353,13 @@ namespace Microsoft.FSharp.Core.CompilerServices
type
TypeProviderAssemblyAttribute
(
assemblyName
:
string
)
=
inherit
System
.
Attribute
()
new
()
=
TypeProviderAssemblyAttribute
(
null
)
member
_.
AssemblyName
=
assemblyName
[<
AttributeUsage
(
AttributeTargets
.
All
,
AllowMultiple
=
false
)>]
type
TypeProviderXmlDocAttribute
(
commentText
:
string
)
=
inherit
System
.
Attribute
()
member
_.
CommentText
=
commentText
[<
AttributeUsage
(
AttributeTargets
.
All
,
AllowMultiple
=
false
)>]
...
...
@@ -328,8 +368,11 @@ namespace Microsoft.FSharp.Core.CompilerServices
let
mutable
filePath
:
string
=
null
let
mutable
line
:
int
=
0
let
mutable
column
:
int
=
0
member
_.
FilePath
with
get
()
=
filePath
and
set
v
=
filePath
<-
v
member
_.
Line
with
get
()
=
line
and
set
v
=
line
<-
v
member
_.
Column
with
get
()
=
column
and
set
v
=
column
<-
v
[<
AttributeUsage
(
AttributeTargets
.
Class
|||
AttributeTargets
.
Interface
|||
AttributeTargets
.
Struct
|||
AttributeTargets
.
Delegate
,
AllowMultiple
=
false
)>]
...
...
@@ -342,41 +385,57 @@ namespace Microsoft.FSharp.Core.CompilerServices
|
IsErased
=
0x40000000
type
TypeProviderConfig
(
systemRuntimeContainsType
:
string
->
bool
)
=
let
mutable
resolutionFolder
:
string
=
null
let
mutable
runtimeAssembly
:
string
=
null
let
mutable
referencedAssemblies
:
string
[]
=
null
let
mutable
temporaryFolder
:
string
=
null
let
mutable
isInvalidationSupported
:
bool
=
false
let
mutable
useResolutionFolderAtRuntime
:
bool
=
false
let
mutable
systemRuntimeAssemblyVersion
:
System
.
Version
=
null
member
_.
ResolutionFolder
with
get
()
=
resolutionFolder
and
set
v
=
resolutionFolder
<-
v
member
_.
RuntimeAssembly
with
get
()
=
runtimeAssembly
and
set
v
=
runtimeAssembly
<-
v
member
_.
ReferencedAssemblies
with
get
()
=
referencedAssemblies
and
set
v
=
referencedAssemblies
<-
v
member
_.
TemporaryFolder
with
get
()
=
temporaryFolder
and
set
v
=
temporaryFolder
<-
v
member
_.
IsInvalidationSupported
with
get
()
=
isInvalidationSupported
and
set
v
=
isInvalidationSupported
<-
v
let
mutable
resolutionFolder
:
string
=
null
let
mutable
runtimeAssembly
:
string
=
null
let
mutable
referencedAssemblies
:
string
[]
=
null
let
mutable
temporaryFolder
:
string
=
null
let
mutable
isInvalidationSupported
:
bool
=
false
let
mutable
useResolutionFolderAtRuntime
:
bool
=
false
let
mutable
systemRuntimeAssemblyVersion
:
System
.
Version
=
null
member
_.
ResolutionFolder
with
get
()
=
resolutionFolder
and
set
v
=
resolutionFolder
<-
v
member
_.
RuntimeAssembly
with
get
()
=
runtimeAssembly
and
set
v
=
runtimeAssembly
<-
v
member
_.
ReferencedAssemblies
with
get
()
=
referencedAssemblies
and
set
v
=
referencedAssemblies
<-
v
member
_.
TemporaryFolder
with
get
()
=
temporaryFolder
and
set
v
=
temporaryFolder
<-
v
member
_.
IsInvalidationSupported
with
get
()
=
isInvalidationSupported
and
set
v
=
isInvalidationSupported
<-
v
member
_.
IsHostedExecution
with
get
()
=
useResolutionFolderAtRuntime
and
set
v
=
useResolutionFolderAtRuntime
<-
v
member
_.
SystemRuntimeAssemblyVersion
with
get
()
=
systemRuntimeAssemblyVersion
and
set
v
=
systemRuntimeAssemblyVersion
<-
v
member
_.
SystemRuntimeContainsType
(
typeName
:
string
)
=
systemRuntimeContainsType
typeName
member
_.
SystemRuntimeAssemblyVersion
with
get
()
=
systemRuntimeAssemblyVersion
and
set
v
=
systemRuntimeAssemblyVersion
<-
v
member
_.
SystemRuntimeContainsType
(
typeName
:
string
)
=
systemRuntimeContainsType
typeName
type
IProvidedNamespace
=
abstract
NamespaceName
:
string
abstract
GetNestedNamespaces
:
unit
->
IProvidedNamespace
[]
abstract
GetTypes
:
unit
->
Type
[]
abstract
ResolveTypeName
:
typeName
:
string
->
Type
abstract
NamespaceName
:
string
abstract
GetNestedNamespaces
:
unit
->
IProvidedNamespace
[]
abstract
GetTypes
:
unit
->
Type
[]
abstract
ResolveTypeName
:
typeName
:
string
->
Type
type
ITypeProvider
=
inherit
System
.
IDisposable
abstract
GetNamespaces
:
unit
->
IProvidedNamespace
[]
abstract
GetStaticParameters
:
typeWithoutArguments
:
Type
->
ParameterInfo
[]
abstract
ApplyStaticArguments
:
typeWithoutArguments
:
Type
*
typePathWithArguments
:
string
[]
*
staticArguments
:
obj
[]
->
Type
abstract
GetInvokerExpression
:
syntheticMethodBase
:
MethodBase
*
parameters
:
Microsoft
.
FSharp
.
Quotations
.
Expr
[]
->
Microsoft
.
FSharp
.
Quotations
.
Expr
abstract
GetNamespaces
:
unit
->
IProvidedNamespace
[]
abstract
GetStaticParameters
:
typeWithoutArguments
:
Type
->
ParameterInfo
[]
abstract
ApplyStaticArguments
:
typeWithoutArguments
:
Type
*
typePathWithArguments
:
string
[]
*
staticArguments
:
obj
[]
->
Type
abstract
GetInvokerExpression
:
syntheticMethodBase
:
MethodBase
*
parameters
:
Expr
[]
->
Expr
[<
CLIEvent
>]
abstract
Invalidate
:
Microsoft
.
FSharp
.
Control
.
IEvent
<
System
.
EventHandler
,
System
.
EventArgs
>
abstract
GetGeneratedAssemblyContents
:
assembly
:
System
.
Reflection
.
Assembly
->
byte
[]
abstract
Invalidate
:
IEvent
<
System
.
EventHandler
,
System
.
EventArgs
>
abstract
GetGeneratedAssemblyContents
:
assembly
:
System
.
Reflection
.
Assembly
->
byte
[]
type
ITypeProvider2
=
abstract
GetStaticParametersForMethod
:
methodWithoutArguments
:
MethodBase
->
ParameterInfo
[]
abstract
ApplyStaticArgumentsForMethod
:
methodWithoutArguments
:
MethodBase
*
methodNameWithArguments
:
string
*
staticArguments
:
obj
[]
->
MethodBase
abstract
GetStaticParametersForMethod
:
methodWithoutArguments
:
MethodBase
->
ParameterInfo
[]
abstract
ApplyStaticArgumentsForMethod
:
methodWithoutArguments
:
MethodBase
*
methodNameWithArguments
:
string
*
staticArguments
:
obj
[]
->
MethodBase
src/FSharp.Core/list.fs
浏览文件 @
972c3cbf
此差异已折叠。
点击以展开。
src/FSharp.Core/local.fs
浏览文件 @
972c3cbf
...
...
@@ -2,8 +2,10 @@
namespace
Microsoft
.
FSharp
.
Core
[<
AutoOpen
>]
module
internal
DetailedExceptions
=
open
System
open
Microsoft
.
FSharp
.
Core
...
...
src/FSharp.Core/mailbox.fs
浏览文件 @
972c3cbf
此差异已折叠。
点击以展开。
src/FSharp.Core/math/z.fs
浏览文件 @
972c3cbf
...
...
@@ -14,72 +14,72 @@ namespace Microsoft.FSharp.Math
namespace
Microsoft
.
FSharp
.
Core
type
bigint
=
System
.
Numerics
.
BigInteger
type
bigint
=
System
.
Numerics
.
BigInteger
open
System
open
System
.
Diagnostics
.
CodeAnalysis
open
System
.
Globalization
open
Microsoft
.
FSharp
.
Core
.
Operators
open
Microsoft
.
FSharp
.
Core
.
LanguagePrimitives
.
IntrinsicOperators
open
System
.
Numerics
open
System
open
System
.
Diagnostics
.
CodeAnalysis
open
System
.
Globalization
open
Microsoft
.
FSharp
.
Core
.
Operators
open
Microsoft
.
FSharp
.
Core
.
LanguagePrimitives
.
IntrinsicOperators
open
System
.
Numerics
[<
AutoOpen
>]
module
NumericLiterals
=
[<
AutoOpen
>]
module
NumericLiterals
=
module
NumericLiteralI
=
module
NumericLiteralI
=
let
tab64
=
new
System
.
Collections
.
Generic
.
Dictionary
<
int64
,
obj
>()
let
tabParse
=
new
System
.
Collections
.
Generic
.
Dictionary
<
string
,
obj
>()
let
FromInt64Dynamic
(
value
:
int64
)
:
obj
=
lock
tab64
(
fun
()
->
let
mutable
res
=
Unchecked
.
defaultof
<_>
let
ok
=
tab64
.
TryGetValue
(
value
,&
res
)
if
ok
then
res
else
res
<-
BigInteger
(
value
)
tab64
.[
value
]
<-
res
res
)
let
tab64
=
new
System
.
Collections
.
Generic
.
Dictionary
<
int64
,
obj
>()
let
tabParse
=
new
System
.
Collections
.
Generic
.
Dictionary
<
string
,
obj
>()
let
FromInt64Dynamic
(
value
:
int64
)
:
obj
=
lock
tab64
(
fun
()
->
let
mutable
res
=
Unchecked
.
defaultof
<_>
let
ok
=
tab64
.
TryGetValue
(
value
,&
res
)
if
ok
then
res
else
res
<-
BigInteger
(
value
)
tab64
.[
value
]
<-
res
res
)
let
inline
get32
(
x32
:
int32
)
=
FromInt64Dynamic
(
int64
x32
)
let
inline
get32
(
x32
:
int32
)
=
FromInt64Dynamic
(
int64
x32
)
let
inline
isOX
s
=
not
(
System
.
String
.
IsNullOrEmpty
(
s
))
&&
s
.
Length
>
2
&&
s
.[
0
]
=
'
0
'
&&
s
.[
1
]
=
'
x'
let
FromZero
()
:
'
T
=
(
get32
0
:?>
'
T
)
when
'
T
:
BigInteger
=
BigInteger
.
Zero
let
inline
isOX
s
=
not
(
System
.
String
.
IsNullOrEmpty
(
s
))
&&
s
.
Length
>
2
&&
s
.[
0
]
=
'
0
'
&&
s
.[
1
]
=
'
x'
let
FromZero
()
:
'
T
=
(
get32
0
:?>
'
T
)
when
'
T
:
BigInteger
=
BigInteger
.
Zero
let
FromOne
()
:
'
T
=
(
get32
1
:?>
'
T
)
when
'
T
:
BigInteger
=
BigInteger
.
One
let
FromOne
()
:
'
T
=
(
get32
1
:?>
'
T
)
when
'
T
:
BigInteger
=
BigInteger
.
One
let
FromInt32
(
value
:
int32
):
'
T
=
(
get32
value
:?>
'
T
)
when
'
T
:
BigInteger
=
new
BigInteger
(
value
)
let
FromInt32
(
value
:
int32
):
'
T
=
(
get32
value
:?>
'
T
)
when
'
T
:
BigInteger
=
new
BigInteger
(
value
)
let
FromInt64
(
value
:
int64
):
'
T
=
(
FromInt64Dynamic
value
:?>
'
T
)
when
'
T
:
BigInteger
=
new
BigInteger
(
value
)
let
FromInt64
(
value
:
int64
):
'
T
=
(
FromInt64Dynamic
value
:?>
'
T
)
when
'
T
:
BigInteger
=
new
BigInteger
(
value
)
let
getParse
s
=
lock
tabParse
(
fun
()
->
let
mutable
res
=
Unchecked
.
defaultof
<_>
let
ok
=
tabParse
.
TryGetValue
(
s
,&
res
)
if
ok
then
res
else
let
v
=
if
isOX
s
then
BigInteger
.
Parse
(
s
.[
2
..],
NumberStyles
.
AllowHexSpecifier
,
CultureInfo
.
InvariantCulture
)
else
BigInteger
.
Parse
(
s
,
NumberStyles
.
AllowLeadingSign
,
CultureInfo
.
InvariantCulture
)
res
<-
v
tabParse
.[
s
]
<-
res
res
)
let
getParse
s
=
lock
tabParse
(
fun
()
->
let
mutable
res
=
Unchecked
.
defaultof
<_>
let
ok
=
tabParse
.
TryGetValue
(
s
,&
res
)
if
ok
then
res
else
let
v
=
if
isOX
s
then
BigInteger
.
Parse
(
s
.[
2
..],
NumberStyles
.
AllowHexSpecifier
,
CultureInfo
.
InvariantCulture
)
else
BigInteger
.
Parse
(
s
,
NumberStyles
.
AllowLeadingSign
,
CultureInfo
.
InvariantCulture
)
res
<-
v
tabParse
.[
s
]
<-
res
res
)
let
FromStringDynamic
(
text
:
string
)
:
obj
=
getParse
text
let
FromString
(
text
:
string
)
:
'
T
=
(
FromStringDynamic
text
:?>
'
T
)
when
'
T
:
BigInteger
=
getParse
text
let
FromStringDynamic
(
text
:
string
)
:
obj
=
getParse
text
let
FromString
(
text
:
string
)
:
'
T
=
(
FromStringDynamic
text
:?>
'
T
)
when
'
T
:
BigInteger
=
getParse
text
src/FSharp.Core/observable.fs
浏览文件 @
972c3cbf
...
...
@@ -2,176 +2,176 @@
namespace
Microsoft
.
FSharp
.
Control
open
System
open
Microsoft
.
FSharp
.
Core
open
Microsoft
.
FSharp
.
Core
.
LanguagePrimitives
.
IntrinsicOperators
open
Microsoft
.
FSharp
.
Control
[<
CompilationRepresentation
(
CompilationRepresentationFlags
.
ModuleSuffix
)>]
[<
RequireQualifiedAccess
>]
module
Observable
=
let
inline
protect
f
succeed
fail
=
match
(
try
Choice1Of2
(
f
()
)
with
e
->
Choice2Of2
e
)
with
|
Choice1Of2
x
->
(
succeed
x
)
|
Choice2Of2
e
->
(
fail
e
)
[<
AbstractClass
>]
type
BasicObserver
<
'
T
>()
=
let
mutable
stopped
=
false
abstract
Next
:
value
:
'
T
->
unit
abstract
Error
:
error
:
exn
->
unit
abstract
Completed
:
unit
->
unit
interface
IObserver
<
'
T
>
with
member
x
.
OnNext
value
=
if
not
stopped
then
x
.
Next
value
member
x
.
OnError
e
=
if
not
stopped
then
stopped
<-
true
x
.
Error
e
member
x
.
OnCompleted
()
=
if
not
stopped
then
stopped
<-
true
x
.
Completed
()
[<
CompiledName
(
"Map"
)>]
let
map
mapping
(
source
:
IObservable
<
'
T
>)
=
{
new
IObservable
<
'
U
>
with
member
x
.
Subscribe
(
observer
)
=
source
.
Subscribe
{
new
BasicObserver
<
'
T
>()
with
member
x
.
Next
(
v
)
=
protect
(
fun
()
->
mapping
v
)
observer
.
OnNext
observer
.
OnError
member
x
.
Error
(
e
)
=
observer
.
OnError
(
e
)
member
x
.
Completed
()
=
observer
.
OnCompleted
()
}
}
[<
CompiledName
(
"Choose"
)>]
let
choose
chooser
(
source
:
IObservable
<
'
T
>)
=
{
new
IObservable
<
'
U
>
with
member
x
.
Subscribe
(
observer
)
=
source
.
Subscribe
{
new
BasicObserver
<
'
T
>()
with
member
x
.
Next
(
v
)
=
protect
(
fun
()
->
chooser
v
)
(
function
None
->
()
|
Some
v2
->
observer
.
OnNext
v2
)
observer
.
OnError
member
x
.
Error
(
e
)
=
observer
.
OnError
(
e
)
member
x
.
Completed
()
=
observer
.
OnCompleted
()
}
}
[<
CompiledName
(
"Filter"
)>]
let
filter
predicate
(
source
:
IObservable
<
'
T
>)
=
choose
(
fun
x
->
if
predicate
x
then
Some
x
else
None
)
source
[<
CompiledName
(
"Partition"
)>]
let
partition
predicate
(
source
:
IObservable
<
'
T
>)
=
filter
predicate
source
,
filter
(
predicate
>>
not
)
source
[<
CompiledName
(
"Scan"
)>]
let
scan
collector
state
(
source
:
IObservable
<
'
T
>)
=
{
new
IObservable
<
'
U
>
with
member
x
.
Subscribe
(
observer
)
=
let
mutable
state
=
state
source
.
Subscribe
{
new
BasicObserver
<
'
T
>()
with
member
x
.
Next
(
v
)
=
let
z
=
state
protect
(
fun
()
->
collector
z
v
)
(
fun
z
->
state
<-
z
observer
.
OnNext
z
)
observer
.
OnError
member
x
.
Error
(
e
)
=
observer
.
OnError
(
e
)
member
x
.
Completed
()
=
observer
.
OnCompleted
()
}
}
[<
CompiledName
(
"Add"
)>]
let
add
callback
(
source
:
IObservable
<
'
T
>)
=
source
.
Add
(
callback
)
[<
CompiledName
(
"Subscribe"
)>]
let
subscribe
(
callback
:
'
T
->
unit
)
(
source
:
IObservable
<
'
T
>)
=
source
.
Subscribe
(
callback
)
[<
CompiledName
(
"Pairwise"
)>]
let
pairwise
(
source
:
IObservable
<
'
T
>)
:
IObservable
<
'
T
*
'
T
>
=
{
new
IObservable
<_>
with
member
x
.
Subscribe
(
observer
)
=
let
mutable
lastArgs
=
None
source
.
Subscribe
{
new
BasicObserver
<
'
T
>()
with
member
x
.
Next
(
args2
)
=
match
lastArgs
with
|
None
->
()
|
Some
args1
->
observer
.
OnNext
(
args1
,
args2
)
lastArgs
<-
Some
args2
member
x
.
Error
(
e
)
=
observer
.
OnError
(
e
)
member
x
.
Completed
()
=
observer
.
OnCompleted
()
}
}
[<
CompiledName
(
"Merge"
)>]
let
merge
(
source1
:
IObservable
<
'
T
>)
(
source2
:
IObservable
<
'
T
>)
=
{
new
IObservable
<_>
with
member
x
.
Subscribe
(
observer
)
=
let
mutable
stopped
=
false
let
mutable
completed1
=
false
let
mutable
completed2
=
false
let
h1
=
source1
.
Subscribe
{
new
IObserver
<
'
T
>
with
member
x
.
OnNext
(
v
)
=
if
not
stopped
then
observer
.
OnNext
v
member
x
.
OnError
(
e
)
=
if
not
stopped
then
open
System
open
Microsoft
.
FSharp
.
Core
open
Microsoft
.
FSharp
.
Core
.
LanguagePrimitives
.
IntrinsicOperators
open
Microsoft
.
FSharp
.
Control
[<
CompilationRepresentation
(
CompilationRepresentationFlags
.
ModuleSuffix
)>]
[<
RequireQualifiedAccess
>]
module
Observable
=
let
inline
protect
f
succeed
fail
=
match
(
try
Choice1Of2
(
f
()
)
with
e
->
Choice2Of2
e
)
with
|
Choice1Of2
x
->
(
succeed
x
)
|
Choice2Of2
e
->
(
fail
e
)
[<
AbstractClass
>]
type
BasicObserver
<
'
T
>()
=
let
mutable
stopped
=
false
abstract
Next
:
value
:
'
T
->
unit
abstract
Error
:
error
:
exn
->
unit
abstract
Completed
:
unit
->
unit
interface
IObserver
<
'
T
>
with
member
x
.
OnNext
value
=
if
not
stopped
then
x
.
Next
value
member
x
.
OnError
e
=
if
not
stopped
then
stopped
<-
true
x
.
Error
e
member
x
.
OnCompleted
()
=
if
not
stopped
then
stopped
<-
true
x
.
Completed
()
[<
CompiledName
(
"Map"
)>]
let
map
mapping
(
source
:
IObservable
<
'
T
>)
=
{
new
IObservable
<
'
U
>
with
member
x
.
Subscribe
(
observer
)
=
source
.
Subscribe
{
new
BasicObserver
<
'
T
>()
with
member
x
.
Next
(
v
)
=
protect
(
fun
()
->
mapping
v
)
observer
.
OnNext
observer
.
OnError
member
x
.
Error
(
e
)
=
observer
.
OnError
(
e
)
member
x
.
Completed
()
=
observer
.
OnCompleted
()
}
}
[<
CompiledName
(
"Choose"
)>]
let
choose
chooser
(
source
:
IObservable
<
'
T
>)
=
{
new
IObservable
<
'
U
>
with
member
x
.
Subscribe
(
observer
)
=
source
.
Subscribe
{
new
BasicObserver
<
'
T
>()
with
member
x
.
Next
(
v
)
=
protect
(
fun
()
->
chooser
v
)
(
function
None
->
()
|
Some
v2
->
observer
.
OnNext
v2
)
observer
.
OnError
member
x
.
Error
(
e
)
=
observer
.
OnError
(
e
)
member
x
.
Completed
()
=
observer
.
OnCompleted
()
}
}
[<
CompiledName
(
"Filter"
)>]
let
filter
predicate
(
source
:
IObservable
<
'
T
>)
=
choose
(
fun
x
->
if
predicate
x
then
Some
x
else
None
)
source
[<
CompiledName
(
"Partition"
)>]
let
partition
predicate
(
source
:
IObservable
<
'
T
>)
=
filter
predicate
source
,
filter
(
predicate
>>
not
)
source
[<
CompiledName
(
"Scan"
)>]
let
scan
collector
state
(
source
:
IObservable
<
'
T
>)
=
{
new
IObservable
<
'
U
>
with
member
x
.
Subscribe
(
observer
)
=
let
mutable
state
=
state
source
.
Subscribe
{
new
BasicObserver
<
'
T
>()
with
member
x
.
Next
(
v
)
=
let
z
=
state
protect
(
fun
()
->
collector
z
v
)
(
fun
z
->
state
<-
z
observer
.
OnNext
z
)
observer
.
OnError
member
x
.
Error
(
e
)
=
observer
.
OnError
(
e
)
member
x
.
Completed
()
=
observer
.
OnCompleted
()
}
}
[<
CompiledName
(
"Add"
)>]
let
add
callback
(
source
:
IObservable
<
'
T
>)
=
source
.
Add
(
callback
)
[<
CompiledName
(
"Subscribe"
)>]
let
subscribe
(
callback
:
'
T
->
unit
)
(
source
:
IObservable
<
'
T
>)
=
source
.
Subscribe
(
callback
)
[<
CompiledName
(
"Pairwise"
)>]
let
pairwise
(
source
:
IObservable
<
'
T
>)
:
IObservable
<
'
T
*
'
T
>
=
{
new
IObservable
<_>
with
member
x
.
Subscribe
(
observer
)
=
let
mutable
lastArgs
=
None
source
.
Subscribe
{
new
BasicObserver
<
'
T
>()
with
member
x
.
Next
(
args2
)
=
match
lastArgs
with
|
None
->
()
|
Some
args1
->
observer
.
OnNext
(
args1
,
args2
)
lastArgs
<-
Some
args2
member
x
.
Error
(
e
)
=
observer
.
OnError
(
e
)
member
x
.
Completed
()
=
observer
.
OnCompleted
()
}
}
[<
CompiledName
(
"Merge"
)>]
let
merge
(
source1
:
IObservable
<
'
T
>)
(
source2
:
IObservable
<
'
T
>)
=
{
new
IObservable
<_>
with
member
x
.
Subscribe
(
observer
)
=
let
mutable
stopped
=
false
let
mutable
completed1
=
false
let
mutable
completed2
=
false
let
h1
=
source1
.
Subscribe
{
new
IObserver
<
'
T
>
with
member
x
.
OnNext
(
v
)
=
if
not
stopped
then
observer
.
OnNext
v
member
x
.
OnError
(
e
)
=
if
not
stopped
then
stopped
<-
true
observer
.
OnError
(
e
)
member
x
.
OnCompleted
()
=
if
not
stopped
then
completed1
<-
true
if
completed1
&&
completed2
then
stopped
<-
true
observer
.
On
Error
(
e
)
member
x
.
OnCompleted
()
=
if
not
stopped
then
completed1
<-
true
if
completed1
&&
completed2
then
stopped
<-
true
observer
.
OnCompleted
()
}
let
h2
=
source2
.
Subscribe
{
new
IObserver
<
'
T
>
with
member
x
.
OnNext
(
v
)
=
if
not
stopped
then
observer
.
OnNext
v
member
x
.
OnError
(
e
)
=
if
not
stopped
then
observer
.
On
Completed
()
}
let
h2
=
source2
.
Subscribe
{
new
IObserver
<
'
T
>
with
member
x
.
OnNext
(
v
)
=
if
not
stopped
then
observer
.
OnNext
v
member
x
.
OnError
(
e
)
=
if
not
stopped
then
stopped
<-
true
observer
.
OnError
(
e
)
member
x
.
OnCompleted
()
=
if
not
stopped
then
completed2
<-
true
if
completed1
&&
completed2
then
stopped
<-
true
observer
.
OnError
(
e
)
member
x
.
OnCompleted
()
=
if
not
stopped
then
completed2
<-
true
if
completed1
&&
completed2
then
stopped
<-
true
observer
.
OnCompleted
()
}
{
new
IDisposable
with
member
x
.
Dispose
()
=
h1
.
Dispose
()
h2
.
Dispose
()
}
}
[<
CompiledName
(
"Split"
)>]
let
split
(
splitter
:
'
T
->
Choice
<
'
U1
,
'
U2
>)
(
source
:
IObservable
<
'
T
>)
=
choose
(
fun
v
->
match
splitter
v
with
Choice1Of2
x
->
Some
x
|
_
->
None
)
source
,
choose
(
fun
v
->
match
splitter
v
with
Choice2Of2
x
->
Some
x
|
_
->
None
)
source
observer
.
OnCompleted
()
}
{
new
IDisposable
with
member
x
.
Dispose
()
=
h1
.
Dispose
()
h2
.
Dispose
()
}
}
[<
CompiledName
(
"Split"
)>]
let
split
(
splitter
:
'
T
->
Choice
<
'
U1
,
'
U2
>)
(
source
:
IObservable
<
'
T
>)
=
choose
(
fun
v
->
match
splitter
v
with
Choice1Of2
x
->
Some
x
|
_
->
None
)
source
,
choose
(
fun
v
->
match
splitter
v
with
Choice2Of2
x
->
Some
x
|
_
->
None
)
source
src/FSharp.Core/quotations.fs
浏览文件 @
972c3cbf
...
...
@@ -91,10 +91,13 @@ type Var(name: string, typ: Type, ?isMutable: bool) =
let
stamp
=
getStamp
()
let
isMutable
=
defaultArg
isMutable
false
member
v
.
Name
=
name
member
v
.
IsMutable
=
isMutable
member
v
.
Type
=
typ
member
v
.
Stamp
=
stamp
member
_.
Name
=
name
member
_.
IsMutable
=
isMutable
member
_.
Type
=
typ
member
_.
Stamp
=
stamp
static
member
Global
(
name
,
typ
:
Type
)
=
checkNonNull
"name"
name
...
...
@@ -107,9 +110,9 @@ type Var(name: string, typ: Type, ?isMutable: bool) =
globals
.[(
name
,
typ
)]
<-
res
res
)
override
v
.
ToString
()
=
name
override
_
.
ToString
()
=
name
override
v
.
GetHashCode
()
=
base
.
GetHashCode
()
override
_
.
GetHashCode
()
=
base
.
GetHashCode
()
override
v
.
Equals
(
obj
:
obj
)
=
match
obj
with
...
...
src/FSharp.Core/seq.fs
浏览文件 @
972c3cbf
此差异已折叠。
点击以展开。
src/FSharp.Core/seqcore.fs
浏览文件 @
972c3cbf
此差异已折叠。
点击以展开。
src/FSharp.Core/string.fs
浏览文件 @
972c3cbf
此差异已折叠。
点击以展开。
src/FSharp.Core/tasks.fs
浏览文件 @
972c3cbf
此差异已折叠。
点击以展开。
麦壳饼
@mysticboy
mentioned in commit
a29c9eec
·
7月 25, 2022
mentioned in commit
a29c9eec
mentioned in commit a29c9eec1781d7f341a15fef74c73a812c4399f2
开关提交列表
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录