Guarded methods in OCaml

16 points by xvw


a5rocks

I don’t know of any mainstream languages that allow their definition.

Python’s type system does, actually! https://mypy.readthedocs.io/en/stable/more_types.html#advanced-uses-of-self-types

These are especially useful for mixins, IME.

tmcgilchrist

Nicely written @xvw.

How well does OCaml present the error messages when you're missing the right type equality witness? You'd probably want the type error to also include the bindings in scope, like merlin has.

Thinking about the other pieces OCaml has lying about, combining this with modular implicits might get you closer to Scala experience. The fun thing with Scala is the complex implicit discovery that usually trips me up when the types get more complex.

valenterry

Yes, Scala supports this as well and even more elegant I would argue. A language that goes even one step beyond and makes it a first-class concept is then Idris (and similar dependently-typed languages).