ikigai-go / compiler

Ikigai compiler
MIT License
0 stars 0 forks source link

Make parens optional for single argument #7

Closed alfonsogarciacaro closed 5 years ago

alfonsogarciacaro commented 5 years ago

In #5 we've decided to use parens for functions with multiple arguments. However, and even if I want to avoid multiple alternatives for the same thing (especially at the beginning), given that the syntax will be ML-like, it may help to make the parens optional when there's only a single argument.

let add(x, y) = x + y // Two arguments, parens are enforced
let square x = x * x // One argument, parens are optional
let test() =
    square 4 // Also for application

Disadvantages:

alfonsogarciacaro commented 5 years ago

If we don't have type inference or auto-generalization for arguments, most of the times you will need to add the parens in the declaration though:

let square (x: number) = x * x
alfonsogarciacaro commented 5 years ago

Upon reflection, maybe it's better not to do this a it can create a very inconsistent style: 0 arguments, empty parens; one argument, no parens; two or more arguments, parens...

MangelMaxime commented 5 years ago

I would prefer to make the parens mandatory so the syntax is consistent. When you have a function it will all be written using let myFunc (....) = ....