encore
encore copied to clipboard
Currying Doesn't Work
It doesn't seem to be possible/easy to write curried functions (in development
97391442c465047b226935d397fdd66f458d8484 ).
I tried the following:
fun curry[a,b,c](f : (a,b) -> c) : a -> (b -> c)
fun (x : a)
fun (y : b)
f(a,b)
end
end
end
fun t(i : int, j : int) : int
i + j
end
class Main
def main() : unit
println(((curry(t))(1))(2))
end
end
which results in the error
*** Error during typechecking ***
"Curry.enc" (line 16, column 15)
Type 'int -> int -> int' is not indexable
In expression:
curry(t)
In expression:
curry(t)(1)
In expression:
curry(t)(1)(2)
In expression:
println(curry(t)(1)(2))
In method 'main' of type 'unit'
In class 'Main'
The compiler assumes that this is an array access, rather than passing arguments to a function.
The fundamental issue is that functions always have a name when they are called. A temporary workaround is to bind each partial application to a name and call that:
println(let g = (let f = curry(t) in f(1) end) in g(2) end)
Try breaking each step up in a different variable too see if that works
Thanks. It seems that the problem is fairly simple to fix, namely that -(arg)
is interpreted as array access when -
isn't a name. Some type directed resolution should fix it, eh?
I have more bug reports coming about local functions ... once I distill the examples (and the children).