views:

127

answers:

2

This is a homework question:

Explain the transformations the type of a routine undergoes in partial parameterization.

So far I understand currying. But I cannot find any resources on how a function like this is implemented by the compiler in memory. Could I be pointed in the right direction, maybe keywords to search for or links to resources or possibly an explanation here of how the compiler generates the type and symbol table among other things thats related to the question.

Thanks.

A: 

Currying is like fixing a parameter of the function. What you really need to modify is the prototype of the function called.. if you have for example retn_type function(param1, param2) and you currying it on first parameter you set it to a fixed value and you obtain a new function retn_type(param2) that can be called and passed in a different way from the original one.

Actually you can obtain it in a compiler in many ways or hacks but the core of everything to its simplicity is just to redefine a new version that is linked to first one. So when you call retn_type(param2) you execute the same code of first fuction assuming that parameter1 is specified by curryfication.

Jack
+2  A: 

Currying is the conversion of n argument functions into n unary functions:

Example, if you have a ternary function f :: t1 x t2 x t3 -> t you can represent this function as

f1 :: t1 -> (t2 -> (t3 -> t))

In other words, f1 is a function which takes an argument of type t1 and returns a function of type f2.

f2 :: t2 -> (t3 -> t)

f2 is a function which takes an argument of type t2 and returns a function of type f3.

f3 :: t3 -> t

f3 is a function which takes an argument of type t3 and returns type t.

Example, if f(a,b,c) = a+b*c then:

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.

In functional languages, functions are first class citizens so its common to have them as return type.

Gamecat