Skip to content
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

λ to indicate anonymous functions #124

Open
ShalokShalom opened this issue Nov 27, 2020 · 13 comments
Open

λ to indicate anonymous functions #124

ShalokShalom opened this issue Nov 27, 2020 · 13 comments

Comments

@ShalokShalom
Copy link

\ is meant to indicate a λ

I know this is a little bit of a stretch since it is one character, that is converted into a ligature and not two.

But I think it is worth thinking about this since it makes the language prettier and it makes the symbol more clear in its intention.

Thanks a lot to consider this ☺

@anka-213
Copy link

Might be difficult, since \ can occur in other places as well and those probably shouldn't be rendered as λ, but I'm not super familiar with how fonts like these works, so maybe it's doable.

@ShalokShalom
Copy link
Author

Where does \ appear on its own without an additional character and does not mean an anonymous function?

@anka-213
Copy link

Mainly in strings. I don't know if that would count as "on its own", but this is an anonymous function

\n ->  n + 1

and this is a newline

"\n -> n + 1"

and I don't know if it is possible for a font to differentiate between these cases? Maybe we just ignore that case and make a ligature out of backslash followed by whitespace?

@ivanopagano
Copy link

and I don't know if it is possible for a font to differentiate between these cases? Maybe we just ignore that case and make a ligature out of backslash followed by whitespace?

Sorry to jump in, but wouldn't it be incorrect? Lambdas' definitions will usually follow the \ with the variable name, right?

@anka-213
Copy link

Yes, most of the time people won't have a whitespace between \ and the variable name, so it would cripple the feature significantly. But it is the only way I can think of to differentiate between lambdas and string escapes without knowing more context. But maybe I'm overthinking this.

@ivanopagano
Copy link

Yes, most of the time people won't have a whitespace between \ and the variable name, so it would cripple the feature significantly. But it is the only way I can think of to differentiate between lambdas and string escapes without knowing more context. But maybe I'm overthinking this.

No, I think your worries are reasonably founded.

@ShalokShalom
Copy link
Author

Well, the language can differentiate between strings and operators, while idk what Haskling can do.

Is it possible to make an exception for \n?
Is this enough, covers it all edge cases?

That would only disallow the anonymous function with the variable name n, all other cases could be covered.

@ShalokShalom
Copy link
Author

ShalokShalom commented Dec 31, 2020

I would like to add, that /n for a varible name that comes after a lambda, would be confusing.

\n kinda indicates a newline, if within a string or not, so this is a bit 'bad style' and is advised to be avoided anyway.

So if we can avoid \n for that reason, is there anything else that could be considered?

@anka-213
Copy link

anka-213 commented Dec 31, 2020 via email

@ShalokShalom
Copy link
Author

Yeah, I would fully agree on that

@ShalokShalom
Copy link
Author

ShalokShalom commented Mar 4, 2021

I did a little bit of research, and according to Tonksy, who is the developer of the contextual alternative code, which is used in Hasklig, is this possible to differentiate between comments and functions via the syntax highlighting.

tonsky/FiraCode#1207 (comment)

So you can turn ligatures off in comments, which is sensical anyway, in my opinion.

@anka-213
Copy link

anka-213 commented Mar 5, 2021

(and in strings)

Sweet!

@ShalokShalom
Copy link
Author

So can we do this now? 😄

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

No branches or pull requests

3 participants