News for hackers. Stuff that matters.
Re:ReasonML: Strict, powerful and forgiving by int_19h on Saturday November 10, 2018 @10:41PM (#18424915)
I'm not familiar with Reason, but OCaml does have virtual methods and dynamic dispatch, and therefore ad-hoc polymorphism.

http://dev.realworldocaml.org/classes.html#virtual-classes-a...

Now, you can't downcast or cross-cast or do a runtime typecheck easily, but that doesn't mean it's impossible - you just have to use roundabout ways like variants to do so (which also means that you can control which class hierarchies it is available for, and which ones it's not). A class hierarchy combined with an polymorphic variant type to allow runtime type queries can be made as powerful as a runtime typecheck/cast in Java - if more verbose - for those rare cases where you actually need it.

http://dev.realworldocaml.org/variants.html#polymorphic-vari...

Of course, in practice, most cases where you'd use a downcast or a typecheck in a language like Java, map more naturally to regular variants and matching on them in OCaml.

There are no comments on this comment yet.