3 ms·
> From the demo program it looks like a function with two int arguments returning an int, but why the -> signs? This is standard syntax in functional languages
by naasking 11y ago
> From the demo program it looks like a function with two int arguments returning an int, but why the -> signs?
This is standard syntax in functional languages. A->B is a function from A to B. A->B->C is a function from A that returns a function B->C. This is the standard curried function application, like used in OCaml, and it enables you to easily partially apply and compose functions.
addCandidate's type is indeed Int->Int->Int, it's simply not declared that way. In OCaml, the following two syntaxes are equivalent:
let addCandidate = fun A:Int B:Int -> ...body...
let addCandidate A:Int B:Int = ...body...
I imagine this language is similar.
- artagnon 11y agoYes, I'd implemented the syntax with the intention of doing currying, but haven't gotten around to doing that yet. If you want to do any "partial application", you need to write a lambda, and explicitly pass its function pointer now. The next step is to automatically generate the lambda.