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

section syntax? #222

Open
gelisam opened this issue Oct 15, 2023 · 5 comments
Open

section syntax? #222

gelisam opened this issue Oct 15, 2023 · 5 comments

Comments

@gelisam
Copy link
Owner

gelisam commented Oct 15, 2023

I recently encountered a bug in which I had written:

(filter (< 10) (list 1 11 111 2 22 222 3 33 333))

to mean

(filter
  (lambda (x) (< x 10))
  (list 1 11 111 2 22 222 3 33 333))

But in Klister, (< 10) means (lambda (x) (< 10 x)), not (lambda (x) (< x 10)). I made that mistake because (< 10) means the latter in Haskell, but the former in Klister. Since target audience is Haskellers, I think our users are likely to make that mistake very often. Is there something we could do to make it less common?

@gelisam
Copy link
Owner Author

gelisam commented Oct 15, 2023

Hackett supports infix syntax as {x < 10}, but it doesn't look like it supports section syntax as {< 10}. It would be tricky to implement, because in the absence of Haskell's restriction on naming binary operators, it is not clear whether < or 10 is supposed to be the infix operator.

@gelisam
Copy link
Owner Author

gelisam commented Oct 15, 2023

The same issue prevents a user-defined the user from defining a user-defined macro (section (< 10)) which does the right thing, unless that macro hardcodes a few specific infix operators. Maybe that would be enough though?

@gelisam
Copy link
Owner Author

gelisam commented Oct 15, 2023

Some other languages support the syntax (_ < 10) for quickly defining lambdas. I don't like that syntax because in those languages, it's not clear whether 1 + (2 + _) means \x -> 1 + (2 + x) or 1 + (\x -> 2 + x).

Maybe we could introduce a limited version of that syntax which is only meant for sections, and thus the lambda is always introduced at the innermost parens? So (+ 1 (+ _ 2)) would unambiguously mean (+ 1 (lambda (x) (+ x 2))).

@gelisam
Copy link
Owner Author

gelisam commented Oct 15, 2023

Or, since we're not yet using curly parens for anything, the lambda could be bound at the closest enclosing curlies? So (+ 1 {+ 2 (+ _ 3)}) would mean (+ 1 (lambda (x) (+ 2 (+ x 3)))).

@david-christiansen
Copy link
Collaborator

The final option there would be a nice little macro to define :) I think Haskell-style sections don't fit well into a language with Lispy syntax and auto-currying, though - it's too much of a special case.

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

2 participants