Closed aljazerzen closed 2 years ago
Related issues:
Thanks. Those issue numbers you linked to at the bottom were particularly helpful. I had long wondered where derive
came from and whether let
had been considered. I see there was discussion on that topic in #6 and #24.
Thanks for adding all the discussion @aljazerzen !
For type annotations there are (a far as I know) only two standards: int a and a: int.
At least Haskell uses ::
and @
.
Java uses @
, though maybe not the muse we're looking for.
Edit: Snowflake also uses ::
I'm not sure whether using ::
would be confusing for the parser given how heavily we use :
— my guess is that it would be fine, but a interactive tool might be confused when typing foo:
before completing to foo::bar_type
.
WDYT about that?
What about
func (add x to=1) = x + to
? This is similar to how you (often must) call a function.
That could work; we could also have func add (x to=1)
to separate the name from the params.
There was an elegance to not having punctuation, but it might be something that's more for people who find Ocaml elegant, rather than something intuitive for the average user. :) I'm also much less concerned about having the syntax clean for things like func definitions than for core pipeline code.
Oh, with type annotations I meant specifying the type of variables/functions, and not actual annotations (@NotNull Integer myInt;
). Java uses @
for annotations, but has not punctuation for types (in newer versions there is var a: Integer
).
::
may work, but it may fail the visual check in function definitions:
func add x::number to::number:1 ::number = ...
or
func (add x::number to::number=1)::number = ...
How about putting the return type at the start of the function, like in C, rather than an the end like in rust:
-func add x::number to::number:1 ::number = ...
+func::number add x::number to::number:1 = ...
(or the same operation for the other option)
Maybe after the name of the function:
func add::number x::number to::number:1 = ...
To be honest that is the thing I dislike the most about the C-style syntax. Having just int foo(bool bar)
is much less readable than having an additional func
at the front.
But now thats just my personal preferences speaking.
Of all the options, I like this one the most:
func (equals x:number to:number=1):bool = ...
with parenthesis required, but all type annotations optional. That's because a call will look like (equals y to=4)
and will have the type of bool
.
Maybe after the name of the function:
func add::number x::number to::number:1 = ...
Yes, this would work too. One reason for the previous one is that it more clearly discriminates add
as a name rather than a parameter. But no strong view; your option sounds good.
func (equals x:number to:number=1):bool = ...
I agree the parentheses have a nice equivalence with the function call. I'm ambivalent between this and putting the parentheses just around the args, to more clearly discriminate equals:
-func (equals x:number to:number=1):bool = ...
+func equals (x:number to:number=1):bool = ...
And to confirm, you're not a fan of <>
, like:
func<bool> (equals x<number> to<number>=1) = ...
(or with the parentheses / return type moved around)
No, <bool>
seem too much as generic parameters.
It's true that function name should standout more, but that may be corrected by highlighting. In any case, I'm fine with both of these cases:
func (equals x:number to:number=1):bool = ...
func equals (x:number to:number=1):bool = ...
Great, me too — the implementor decides :)
Yeah, agree re it looking like generics, that is a downside
For future readers:
In issues #444 and #447 we decided on the following:
:
for named args; interp lower:0 1600 sat_score
=
for assigns; derive temp_c = (temp_f | celsius_of_fahrenheit)
, from e = employees
==
for equality comparison join s=salaries [s.employee_id == employees.id]
->
for function mapping; func interp lower:0 higher x -> (x - lower) / (higher - lower)
<>
annotations
Current syntax:
On discord, we are having the following discussion:
aljazerzen:
snth:
max-sixty:
aljazerzen:
What about
func (add x to=1) = x + to
? This is similar to how you (often must) call a function.Or
func add x (to=1) = x + to
?I also agree that function definitions have to be easy to parse visually, which means that
~
andis
are not good separators.