柯里化 n 个参数创建 n 个函数
Currying n arguments create n functions
我有一个功能
//normal version
let addTwoParameters x y =
x + y
翻译成 curry 版本看起来像:
//explicitly curried version
let addTwoParameters x = // only one parameter!
let subFunction y =
x + y // new function with one param
subFunction // return the subfunction
当我有一个带有 4 个参数的函数时会怎样:
let addTwoParameters a b c d =
a + b + c + d
柯里化版本会怎样?
看起来像这样:
let addTwoParameters a =
let subFunction1 b =
let subFuction2 c =
let subFuction3 d =
a + b + c + d
subFuction3
subFuction2
subFunction1
我有一个功能
//normal version
let addTwoParameters x y =
x + y
翻译成 curry 版本看起来像:
//explicitly curried version
let addTwoParameters x = // only one parameter!
let subFunction y =
x + y // new function with one param
subFunction // return the subfunction
当我有一个带有 4 个参数的函数时会怎样:
let addTwoParameters a b c d =
a + b + c + d
柯里化版本会怎样?
看起来像这样:
let addTwoParameters a =
let subFunction1 b =
let subFuction2 c =
let subFuction3 d =
a + b + c + d
subFuction3
subFuction2
subFunction1