Custom OCaml (=>) operator and Reason


#1

Is there a way to use OCaml code (e.g. converting via reason-tools, refmt, or other approach) that defines a custom fat arrow (=>) operator? Since Reason redefines => as function-arrow, refmt conversion of code that defines this operator is silently invalid. (I filed an issue on that over on the reason-cli repo.) I’m a relatively new Reason/Bucklescript user and I’m currently a bit stumped by this. AFAICT, the Reason docs don’t mention any obvious syntactic workarounds, ala Haskell’s backtick-operator for using a function as infix. Specific, real world code that uses this is the small parser combinator library, opal: https://github.com/pyrocat101/opal/blob/master/opal.ml#L81

I naively tried swapping => for -> in opal, but the definition of a custom thin-arrow operator -> produces a syntax error.


#2

You can rename it in a separate OCaml module. And for convenience re-export the original module by include-ing it. For example, if you create MyOpal.ml with this:

include Opal

let (==>) = (=>)

Then you should be able to just substitute MyOpal wherever you would use Opal and use ==> instead of =>.


#3

Thanks, that’s helpful!

For posterity, there’s this in-progress PR aimed at addressing exactly this kind of operator issue more globally: https://github.com/facebook/reason/pull/1944