News for hackers. Stuff that matters.
Re:Hindley-Milner Type Inference (2012) by iaabtpbtpnn on Friday July 10, 2020 @03:58PM (#23795700)
The HM type inference used by OCaml breaks down when you add in nominal subtyping, which is common in mainstream static languages like Java. OCaml handles this by giving up subtyping; there is none in the core language, and the (rarely-used) object system uses a form of structural subtyping based on row types.
Re:Hindley-Milner Type Inference (2012) by yawaramin on Saturday July 11, 2020 @01:29AM (#23799781)
OCaml also has a really good subtyping implementation in the often-used polymorphic variant system. I'll just quote from http://roscidus.com/blog/blog/2014/02/13/ocaml-what-you-gain... :

> Their real purpose is to support subsets and supersets, which are useful all over the place.

And indeed they are super useful, e.g. I am using them to implement functions that deal with web responses: some can deal with only HTTP responses, some with only WebSocket responses, and some with either. All completely type-safe and extensible.

Re:Hindley-Milner Type Inference (2012) by xvilka on Friday July 10, 2020 @10:47PM (#23799031)
I once wondered about subtyping[1] too. Looks like there's a possible solution - MLsub[2][3]. But it will require significant amount of work to modify OCaml inference engine to work that way. For now I just use functors for types with the shared fields. It doesn't add too much lines of code either.

[1] https://discuss.ocaml.org/t/function-argument-polymorphism/3...

[2] https://www.cl.cam.ac.uk/~sd601/papers/mlsub-preprint.pdf

[3] https://github.com/stedolan/mlsub

Re:Hindley-Milner Type Inference (2012) by ohadrau on Friday July 10, 2020 @06:38PM (#23797395)
While the object system is pretty rarely used [1], polymorphic variants see quite a bit of use and are also based on row types.

[1] Recently have been seeing a lot more use in BuckleScript because of the JS object representation