|
|
|
Constructing functional values
|
|
6 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); } );
Oh well... it's probably still odd ;)
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.
|
|
|
Constructing functional values
|
|