Hello Chapel developers,
I was using first-class functions recently and had a few issues. I know
that first-class function support is rather preliminary
<http://chapel.cray.com/docs/latest/technotes/firstClassFns.html>, so I'm
noting these more as feature requests for the future.
*Issue #1: Cannot extract type arguments from first-class function*
I had a recursive function that was calling a first-class function, the
output of which was determining the return type of the recursive function.
Here's a simplified and contrived example:
> proc foo(f, x) {
>
if x < 0 then halt();
>
if x < 2 then return x;
>
else return f(foo(f, x-2), foo(f, x-1));
>
}
>
writeln(foo(lambda(x: int, y:int) { return x + y; }, 7));
>
Unfortunately, this doesn't compile because foo() is called recursively and
the output type cannot be resolved.
Since first-class functions must be fully qualified with no generic
arguments, I was hoping to be able to extract the return type of the
function in the calling signature. This might look something like:
> proc foo(f: func(?eltType, eltType, ?retType), x: eltType): retType { ... }
>
or
> proc foo(f: ?funcType, x): funcType.rettype { ... };
>
but neither approach is currently supported.
*(Minor) Issue #2: Anonymous lambdas leak memory*
In the course of this experimentation, I noticed that lambdas that are not
deleted (e.g., anonymous lambdas) leak memory. I suspect something like
reference-counting would be a solution here, but also wanted to note this
issue.
Thanks,
Nick
------------------------------------------------------------------------------
Presto, an open source distributed SQL query engine for big data, initially
developed by Facebook, enables you to easily query your data on Hadoop in a
more interactive manner. Teradata is also now providing full enterprise
support for Presto. Download a free open source copy now.
http://pubads.g.doubleclick.net/gampad/clk?id=250295911&iu=/4140
_______________________________________________
Chapel-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-developers