科里化函数
This commit is contained in:
parent
66103942b7
commit
2e9d5613c5
|
@ -1,18 +1,18 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<RootNamespace>Basic_practice_of_FSharp</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="HelloWorld.fs" />
|
||||
<Compile Include="LetBinding.fs" />
|
||||
<Compile Include="SimpleFunction.fs" />
|
||||
<Compile Include="LambdaFunction.fs" />
|
||||
<Compile Include="HigherOrderFunction.fs" />
|
||||
<Compile Include="RecurseFunction.fs" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<RootNamespace>Basic_practice_of_FSharp</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="HelloWorld.fs" />
|
||||
<Compile Include="LambdaFunction.fs" />
|
||||
<Compile Include="LetBinding.fs" />
|
||||
<Compile Include="SimpleFunction.fs" />
|
||||
<Compile Include="HigherOrderFunction.fs" />
|
||||
<Compile Include="RecurseFunction.fs" />
|
||||
<Compile Include="FunctionSign.fs" />
|
||||
<Compile Include="CurryingFunction.fs" />
|
||||
<Compile Include="Loop.fs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,15 @@
|
|||
module CurryingFunction
|
||||
|
||||
// 科里化函数
|
||||
// 如果一个函数提供的参数数量少于指定的参数数量, 则可创建一个应采用其余参数的新函数
|
||||
// 这种处理参数的方法称为科里化, F#就提供了这种方法
|
||||
|
||||
// 提供一个二元函数add
|
||||
let add a b = a + b
|
||||
|
||||
// 假设你使用过程中,有明确的第二个参数的值,且是固定值,则可使用科里化
|
||||
let add_one = add 1
|
||||
|
||||
// 使用add_one只需提供一个参数
|
||||
|
||||
add_one 10 |> printfn "%d" // 将输出11
|
Loading…
Reference in New Issue