Closed AnthonyJacob closed 6 years ago
Two problems:
What exactly are infixr
and infixl
in terms of ADT? If they're not ADT additions, just part of a syntax, then how do you recover the original syntax after translating to binary Moon?
Are they global modifications of the syntax (i.e., as soon as they're typed, the whole syntax changes)? There is no similar mechanism for that in Moon currently. Is it OK? Will it mix well with the self-contained imports we currently have? How to implement it safely?
I think it should be just syntactic sugar. Moon also does not keep new lines, so your pretty formatted file ends up as one liner. Unless you add some pretty printer which puts every expression on new line - this pretty printer should also rewrite ((:>) 2 ((:>) 1 nil))
as (2 :> 1 :> nil)
.
I am not exactly sure what you mean. We would just need to change the parser to read (/ 2)
as (x => x / 2)
instead of current (x => 2 / x)
which can be expressed as ((/) 2)
or (2 /)
.
Infix functions as a syntactic sugar can be burden for the compiler. On the other hand they make code much more readable.
So what if we allowed only
infixr
,infixl
andinfix
(you could not specify precedence) and the type would be inferred by compiler (you cannot specify it yourself):>
=> it isinfixr
<
=> it isinfixl
infix
So for example
$>
and>>=
isinfixr
,<$
isinfixl
,<$>
and==
isinfix
.