The intent of writing this tool was to give OCaml beginners a quick way to find the standard / conventional operators in the language and to disambiguate “operator-like” syntax that can be hard to search for otherwise. It currently supports:
all standard library operators,
conventional infix operators (>>=, >>|, >|=),
binding operators (let+, let*, and+, etc.),
syntax that is often confused for an operator (#, ;;).
Please let me know if you have any suggestions for improvements. I hope you find it useful!
Acknowledgements
This tool is heavily based on the JavaScript operator lookup utility by Josh Comeau. Thanks to him for the initial idea and for allowing me to re-use his design elements.
They’re hardcoded. The operators fall into three classes:
The vast majority of them are from the Stdlib module, so I don’t expect those to change very regularly.
A small number of “conventional” operators used in the community (>>=, let*, etc.). Even for that small set there is some divergence in Opam – c.f. >>| vs >|= for a map operator – so I suspect there are not many other candidates for this group.
There are a few regexes behind the scenes for catching valid operator names that don’t fall into the first two categories. e.g. many search terms are classified as “a left-associative operator” with a correspondingly vague description.
<2¢> The font setup makes |> appear as ⊳, and -> as → which is mimics some known editor themes but is somewhat less vanilla. It might be good to at least mention it to avoid confusion when this is cross-referenced with the official manual or some other such documentation. </2¢>
Really neat. Precedence and associativity of OCaml’s infix operators are determined by their prefix and they are hard to remember, so this is useful. You could think about including information about precedence, like: @@@ is right associative and has higher precedence than … and lower precedence than … . Not sure how best to do it.
Hi Craig, this is really cool. A small bug report: it’s crashing when I enter the | pipe in the search box. Error message in the console:
react-dom.production.min.js:209 TypeError: o.replaceAll is not a function
at operator-lookup.js:111
at ro (react-dom.production.min.js:211)
at vu (react-dom.production.min.js:257)
at t.unstable_runWithPriority (scheduler.production.min.js:19)
at Ql (react-dom.production.min.js:122)
at hu (react-dom.production.min.js:257)
at Zo (react-dom.production.min.js:239)
at react-dom.production.min.js:123
at t.unstable_runWithPriority (scheduler.production.min.js:19)
at Ql (react-dom.production.min.js:122)
At some point, I had a plan to build a dynamic “operator precedence” table that would highlight the currently-active row to show the user which operators are above / below this one in terms of precedence; I gave that up in favour of getting something published, but it might be a good fit for a second iteration.
In a similar vein, I think it’d be nice to find some natural way to display which characters are available for the various operator classes; e.g. the current tool will validate a choice of operator, but won’t help you design one.