On Thu, Oct 9, 2008 at 8:55 AM, Francois Maltey wrote:
>
> Your example shows that axiom allows to "currify" 2 variables with
> this syntax, but how do you create a 3-variable function ?
>
> fct := x +-> (y +-> (z +-> gcd (x,y,z)))
>
> fct 4    is a 2-variable function.
> fct 4 6 is a 1-variable function
> fct 4 6 8 = 2
>

Perhaps it looks like it, but there are no Curry operations shown
above. Each of these is a function of only one variable. The
expression 'fct 4 6 8' is interpreted as ((fct(4))(6))(8).

Curry applies if I am given a function with several inputs, e.g.

(1) -> fct(x:Integer,y:Integer,z:Integer):Integer == gcd( [x,y,z] )
                                                        Type: Void

and create new higher-order function with fewer inputs which only
"partially evaluates" the original function, returning a function as
output.

(2) -> fct''(x:Integer,y:Integer):(Integer->Integer) == z +-> fct(x,y,z)
   Function declaration fct'' : (Integer,Integer) -> (Integer ->
      Integer) has been added to workspace.
                                                        Type: Void

In other words the value of the function fct''(2,4) is itself a
function of one argument.

(3) -> fct''(2,4)
   Compiling function fct with type (Integer,Integer,Integer) ->
      Integer
   Compiling function fct'' with type (Integer,Integer) -> (Integer ->
      Integer)

   (3)  theMap(#<COMPILED-FUNCTION *2;fct'';1;frame1-1>,679)
                                                   Type: (Integer -> Integer)

Evaluating this function

(4) -> fct''(2,4)(8)

   (4)  2
                                                        Type: PositiveInteger

Is exactly equivalent to fct(2,4,8).

Similarly if we wish to partially evaluate on only one input:

(5) -> fct'(x:Integer):((Integer,Integer)->Integer) == (y,z) +-> fct(x,y,z)
   Function declaration fct' : Integer -> ((Integer,Integer) -> Integer
      ) has been added to workspace.
                                                                   Type: Void
(6) -> fct'(2)
   Compiling function fct' with type Integer -> ((Integer,Integer) ->
      Integer)

   (6)  theMap(#<COMPILED-FUNCTION *1;fct';1;frame1-1>,678)
                                         Type: ((Integer,Integer) -> Integer)
(7) -> fct'(2)(4,8)

   (7)  2
                                                        Type: PositiveInteger

Axiom has some higher-order Curry operations in MappingPackage2 and
MappingPackage3 but these are not quite as flexible as the notation
above.

Regards,
Bill Page.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
open-axiom-devel mailing list
open-axiom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/open-axiom-devel

Reply via email to