Closed bobzhang closed 2 weeks ago
You mean no custom infix? What would we do to translate existing ocaml codebases over?
@chenglou You can always parse, print, and use infix operators like this:
let result = ( +++ ) a b;
If you wanted to be super opinionated, you could just create a white-list for which operators should have the privilege of being printed "in between".
Do we see people going overboard with infix operators?
@jordwalke potentially with the monadic ones, which we can tastefully whitelist, if needed. I'm down with this approach btw. It'll also free us from ocaml's infix precedence rule. We could just say "we have 10 operators, their order is predetermined".
No custom infix would bind my hands a little. I know we want to avoid the haskell problem of nameless weird symbols being the public interface, but they turn let liftA4 f a b c d => A.apply (A.apply (A.apply (A.fmap f a) b) c) d;
into let liftA4 f a b c d => f <$> a <@> b <@> c <@> d;
. They can make a pretty big improvement to readability.
as an aside, if we replaced operators with the ability to call functions from an infix position (I'm sure this is incredibly hard) that would solve both problems too. the above could be comfortable written as:
let liftA4 f a b c d = f `fmap` a `ap` b `ap` c `ap` d;
Is it possible to use ppx or camlp4 to rewrite
a `f` b
as
(f a b)
?
follow up the bikeshedding on discord, it would be nice that we provide several operators but do it really well (formatting, precedence),
|>
,<|
, arithmetic.Bonus: we can also solve the jsx issue easily
><