hackett
hackett copied to clipboard
Precedence for infix operators
Is it possible implement Haskell syntax for infix operators?
Example :
(infixr 4 +)
(1 + 2)
In this sense (infixr 4 +)
is just a shorthand macro definition that gets globally applied to all expressions.
Infix operators are planned, in some way or another. The exact details are not squared away yet. However, you will need to use {
curly braces }
to enter “infix mode”, since there won’t be a syntactic distinction between infix operators and prefix operators like Haskell has (based on characters in identifiers). You will be able to assign associativity and precedence, though.
Could you elaborate why there will be no distinction between prefix and infix?
I would like to avoid assigning meaning to the names of identifiers. Lisp identifiers are traditionally much more lax about which characters you can use in an identifier, so you can name an identifier do-it!
if you want, or even a!b@c#d$
. This also avoids needing a syntax for converting prefix operators to infix ones and vice versa, since the (<>)
and `elem`
syntaxes wouldn’t work so well in a Lisp.
Associativity is now implemented in the new implementation in e7767ad0ecbb5ccafef3adb2c15ee8f04d0e31c5, but precedence is still unimplemented. You can now specify associativity when writing a definition by writing #:fixity left
or #:fixity right
. left
is the default.
This means type signatures can get a bit cleaner, since ->
is now properly right-associative. You can now write {Integer -> Integer -> Integer}
, and it will parse the way you would expect.