-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optional Haskell/Elm style lambdas next to the existing syntax #1231
Comments
Should be ‘unchecked’. As discussed in the other thread, this is the main problem with this idea. We typically don’t introduce new syntax for something that already has syntax. There may be exceptions, but it’ll need a very strong use case. I know you submitted this because in the linked thread there’s an old comment describing this, that got 20 upvotes and zero downvotes, and we floated the idea of what the community would thin about it now. Re ‘implicit’: we usually use that word for something that’s truly implicit (like implicit type conversions), having (fwiw, I don’t really know a better alternative term, but just wanted to stress this point)
I’m not sure about that. If it can be done in lexing/parsing, where the change belongs, it may be much, much simpler than we think. But let’s try to keep these discussions separate, it’s good that you split it up. This one is about proposing new syntax |
I have removed the estimated cost for the other one (making |
I agree this has already been decided - we won't be introducing new syntax - tbh removing the |
Exactly. This is the one, that I thought.
Perhaps you are right.
Fine with me, if everything is considered, I'm just looking forward to having the removing the |
Commenting so that people looking at this know what to do. Use prettify-symbols-mode or a ligature to convert it to λ (vscode) and add yourself a shortcut for typing "fun". There's even a reference to F# in the extension. You may need to fix/fork the vscode extension, but it works well on emacs. |
Must mention your Feature request: prettify symbols mode microsoft/vscode#171074 |
I propose Optional Haskell/Elm style lambdas next to the existing syntax.
The existing way of approaching this problem in F# is Lambda Expressions: The fun Keyword (F#)
We can rewrite
to
The latter corresponds to the type definition:
int -> int -> int -> int
well; however, thefun_
(_
meansSPACE
) keyword looks redundant/verbose.Note:
\
is from λ (lambda)Simply replacing the code text with
fun_
to\
,The code becomes much more concise and corresponds to the type annotation well.
Typing amount and readability imporves.
Interestingly enough, the code above corresponds to the syntax for lambda expression in Haskell and Elm pretty well.
https://wiki.haskell.org/Anonymous_function
https://elm-lang.org/docs/syntax#functions
Background
Implicit style lambda
we treat the first
x
as the "argument", "parameter" or "placeholder" implicitlyx -> x + 1
(Make thefun
keyword optional #168 F# suggestion)x => x + 1
(C#, JavaScript)Explicit style lambda
the "argument", "parameter" or "placeholder" is explicitly defined with
\
orfun_
keyword\x -> x + 1
(Haskell, Elm)fun x -> x + 1
(OCaml, F#)The explicit style used in Haskell/Elm and F# is identical and just syntax letter is different and replaceable.
Make the
fun
keyword optional #168The status is approved-in-principle
Actually, the difference between Implicit style and Explicit style is not trivial at all.
Some informative comments in the thread are:
Haskell like
abelbraaksma commented on Nov 23, 2020
abelbraaksma commented on Nov 23, 2020
abelbraaksma commented on Nov 23, 2020
dsyme commented on Oct 28, 2022
dsyme commented on Oct 28, 2022
I'm pretty sure the primary developer works hard, but currently no one established the RFC, and so far, it seems that the consequence of the optional
fun
keyword is that usage offun
keyword is necessary in some complicated cases.#168 is the mixed style of lambda expression; Maybe, it's possible to write lambda expressions without
fun
in any complicated cases, but as long as I've read, no one is so sure.This is a very complicated approach and probably will end up with having both Implicit style most of the time, then Explicit style sometimes.
On the other hand,
\x -> …
is always Explicit style.Sure you have 2 ways to write the identical mathematical instance/identical lambda expression in
fun_
or\
, but this is a much simpler approach.will become to
or
as shown above, in complicated lambda expressions, explicitly defining which are arguments/parameters with
\
prefix orfun_
keyword keeps the expression structure clear and readable, so it is not trivial at all.At the outermost, there are 2 kinds of people.
A) We like
fun
syntax and don't feel it's redundant or verbose, so keep it.B) We don't like
fun
syntax and feel it's redundant and verbose, remove it.In B type, there are 2 kinds of people.
B1) Removing
fun
is Good, but replacing it to\
prefix is NG, then it's good for us to have C# like lambda style in F#. (Implicit style advocator) Having another syntax for the identical code is bad practice even it's concise and wanted. The complicated approach is justified by this principle.B2) Removing
fun
is Good, and replacing it to\
prefix, then it's good for us to have Haskell-like lambda style in F#. (Explicit style advocator) It is totally fine to have a shorter concise syntax next to the existing syntax. Compared to the simple rule and clear readability, the complicated approach does not look like a smart move. Having the option to write in shorter/concise syntax is much better than keep usingfun
sometimes when it would be needed in complicated situations. After all, we would like to avoid using mixed style lambda in my code. It's not like denying their effort but just give us the third option. It's easy to implement anyway.Pros and Cons
Pros
The advantages of making this adjustment to F# are ...
fun_
syntax)fun
even in the most complicated caseRickasaurus commented on Jul 22, 2017 20 upvotes
benjamin-thomas commented on Nov 4, 2022
Cons
The disadvantages of making this adjustment to F# are ...
TIHan commented on Nov 27, 2017
(the comment seems to be written against #168)
abelbraaksma commented 16 hours ago
There are people who don't like Haskell like syntax much and do not want to allow this, and they only prefer C# like syntax for beginner's reach.
The same people tend to deny the improvement of readability.
The main developer probably does not like it
dsyme commented on Nov 16, 2017
Extra information
Just the parser-level implementation.
I already developed a proof of concept with the VSCode extension.
https://marketplace.visualstudio.com/items?itemName=KenOkabe.lambda-for-fun-fsharp
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
For Readers
If you would like to see this issue implemented, please click the 👍 emoji on this issue. These counts are used to generally order the suggestions by engagement.
The text was updated successfully, but these errors were encountered: