Sha*_*ean 4 compiler-construction currying
这是一个家庭作业问题:
解释例程类型在部分参数化中经历的转换。
到目前为止我理解柯里化。但我找不到任何关于编译器如何在内存中实现这样的函数的资源。我能否指出正确的方向,也许是要搜索的关键字或资源链接,或者可能是编译器如何生成类型和符号表以及与问题相关的其他内容的解释。
谢谢。
柯里化是将 n 个参数函数转换为 n 个一元函数:
例如,如果您有一个三元函数 f :: t1 x t2 x t3 -> t 您可以将该函数表示为
f1 :: t1 -> (t2 -> (t3 -> t))
Run Code Online (Sandbox Code Playgroud)
换句话说,f1 是一个函数,它接受类型 t1 的参数并返回类型 f2 的函数。
f2 :: t2 -> (t3 -> t)
Run Code Online (Sandbox Code Playgroud)
f2 是一个函数,它接受类型 t2 的参数并返回类型 f3 的函数。
f3 :: t3 -> t
Run Code Online (Sandbox Code Playgroud)
f3 是一个函数,它接受类型 t3 的参数并返回类型 t。
例如,如果 f(a,b,c) = a+b*c 则:
f3(C) == c1+c2*C where c1 and c2 are constant.
f2(B) == f3(C) where c1 is constant and c2 is replaced with B.
f1(A) == f2(B) where c1 is replaced with A.
Run Code Online (Sandbox Code Playgroud)
在函数式语言中,函数是一等公民,因此通常将它们作为返回类型。