elan-language / Documentation

0 stars 0 forks source link

Change lambda syntax, so types are fully specified #176

Closed richardpawson closed 4 months ago

richardpawson commented 4 months ago

Proposed new syntax something like

lambda(a: Int) as Int -> a * a

(I was considering suggesting returninstead of -> - because generally Elan favours words over symbols. However, lambdas are definitely an advanced technique (at school level) and by that stage it is probably useful and important to get pupils more used to symbols, especially those they are likely to encounter in other programming environments.

This would get rid of the huge burden of type inference - though it does currently work. But the additional, significant, benefit would be that we can now assign a lambda to a variable e.g.

var myLam set to lambda(a: Int) as Int -> a * a

I also think we should be able to define a functiontype - for a parameter, or an object property. Syntax? Possibly:

Func<of Int, String -> Int>

(My reason for suggesting Func rather than Function, here, is not just brevity in-line, but also to keep the two words verbally distinct: functionis a keyword for defining a function, Funcis a type.)