[ANN] Operator lookup tool for OCaml

I’m pleased to announce the initial release of craigfe.io/operator-lookup/, a search tool for OCaml operators and syntax elements:

For each operator, the tool provides a short explanation of its behaviour, examples of usage and warnings of common misuses and misunderstandings:

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.

38 Likes

It’s not obvious for me are these operators hardcoded or do you scan opam packages from time to time?

1 Like

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.

That’s a neat website!

<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¢>

2 Likes

Agreed :slightly_smiling_face:

The current state is mostly an artefact of that being the default font on my site – I’ll swap this out at some point to avoid unnecessary confusion.

2 Likes

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.

4 Likes

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)
1 Like

That’s a good idea.

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.

2 Likes

Thanks for the report. That’s an interesting one; I can’t reproduce it on my machine. What browser version are you using?

I’m using Chrome 81 on Mac. Tried in incognito mode as well (no extensions) and got the same issue.

1 Like

replaceAll is available after Chrome 85, so if the tool is compiled without polyfills it’s likely it’s not available

2 Likes

This is awesome! Thanks @CraigFe!

1 Like

Very nice website, both useful and pretty !

1 Like