Custom OCaml (=>) operator and Reason


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:

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


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 with this:

include Opal

let (==>) = (=>)

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


Thanks, that’s helpful!

For posterity, there’s this in-progress PR aimed at addressing exactly this kind of operator issue more globally: