next up previous contents
Next: Typesystem Up: Gont for C programmers Previous: Exceptions   Contents

Constructing functional values

There are two ways to build functional value in Gont. First comes from C:

        int add(int a, int b) { return a + b; }

and the second from ML:

        *(int, int) -> int add = 
                fun (int a, int b) -> int is { return a + b; };

The second way might seem odd to C programmer. Of course, because it is odd when used to define simple C-like function. But it is not when you need to pass function to another function, let's say:

        void fputs(file f, string s);
        ...
        void do_sth(int foo, *(string) -> void err_report);
        ...
        do_sth(16, fun (string s) -> void is { fputs(f, s); } );

People familiar with ML might recognize that despite the type information for (fun ...) statement can be obtained from itself, it still has to be given (even twice). I guess it is place for experiments.

I also would like to have some support for named arguments, so functions can be called as:

        Window::create(width => 20, height => 23, color => red);

This should come with default values.



Micha³ Moskal 2001-11-27