gpt4 book ai didi

function - 柯里化(Currying)一个函数来获取另一个函数 : unit -> 'a

转载 作者:行者123 更新时间:2023-12-04 06:34:20 24 4
gpt4 key购买 nike

给定一个高阶函数,如下所示:

let call (f : unit -> 'a) = f()

还有另一个功能:
let incr i = i + 1

有没有办法通过 incrcall ,不使用 lambda: (fun () -> incr 1) ?

显然,通过 (incr 1)不起作用,因为该功能随后“完全应用”。

编辑

澄清一下:我想知道是否有办法对函数进行柯里化(Currying),使其成为函数: unit -> 'a .

最佳答案

您可以自己定义这样的快捷方式:

let ap f x = fun () -> f x

call (ap incr 1)

如果要转换的函数恰好是纯函数,则可以改为定义常量函数:
let ct x _ = x  (* const is reserved for future use :( *)

call (ct (incr 1))

关于function - 柯里化(Currying)一个函数来获取另一个函数 : unit -> 'a,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5031299/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com