Skip to content
This repository has been archived by the owner on Mar 10, 2022. It is now read-only.

Possible Syntax Adjustment #1

Open
bristermitten opened this issue Oct 21, 2020 · 8 comments
Open

Possible Syntax Adjustment #1

bristermitten opened this issue Oct 21, 2020 · 8 comments

Comments

@bristermitten
Copy link
Member

This isn't anything fancy, just proposing a small tweak to function syntax

let print-hello = () => {
    print "Hello"
}

Would become

let print-hello = _ => {
    print "Hello"
}

And

let greet = (Person p) => {
    print "Hello " + p.name
}

Would become

let greet = Person p => {
    print "Hello " + p.name
}

Without parentheses

Just an idea, but it looks cleaner imo

@oppsec
Copy link

oppsec commented Nov 10, 2020

In my opinion, with parentheses looks better, and people are more familiar with the parentheses

@bristermitten
Copy link
Member Author

bristermitten commented Nov 11, 2020

In my opinion, with parentheses looks better, and people are more familiar with the parentheses

Perhaps. I think it's mainly personal preference.

On a similar note, what about this?

I think we should consider changing the function syntax significantly
I've been doing some research into FP and pretty much every functional language has much more concise function declaration

let square x = x * x

in F# for example

meanwhile in elara it would be

let square = (Int x) => x * x

which obviously is pretty verbose

If hypothetically we were to borrow F#'s syntax, we'd have a more concise syntax, functions and variables would still be declared in the same way, and we wouldn't need the hacky let blah => blah anymore

Thoughts?

@oppsec
Copy link

oppsec commented Nov 12, 2020

I still think that with let square x = x * x it would be better, more verbose languages are less attractive to new programmers, from what I see.

@bristermitten
Copy link
Member Author

Yeah I agree. As much as the current syntax is arguably clearer, the verbosity is going to be counter productive (especially considering that FP is all about small, repeatable functions)

Perhaps we could use the let square x = x * x for functions, and the current syntax for anonymous functions

@Vshnv
Copy link
Contributor

Vshnv commented Nov 12, 2020

How would the contract be defined for x in that example?

@bristermitten
Copy link
Member Author

bristermitten commented Nov 12, 2020

Well, in F# there's some pretty powerful type inference for parameters.

If Elara doesn't support that, we could do

let square Int x = x * x

perhaps

Eg

let add Int a, Int b = a + b

@bristermitten
Copy link
Member Author

Or of course something like

let add a: Int, b: Int = a + b

But I think parameter type inference is definitely something we should consider

@oppsec
Copy link

oppsec commented Nov 13, 2020

Or of course something like

let add a: Int, b: Int = a + b

But I think parameter type inference is definitely something we should consider

I liked this way

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants