Re: [Caml-list] "OCaml gives you only monomorphic methods in classes."

From: Jon Harrop <jon@ffconsultancy.com>
> I just read this quote and I do not understand what it means:
>
> "In particular, the Hindley/Milner style of type inference used in languages
> such as OCaml or Haskell is incompatible with lots of assumptions of OO
> languages. One incompatibility is with overloading. That's why OCaml does not
> let you write + for both integer and floating point addition. Another
> incompatibility is with higher order polymorphism. That's why OCaml gives you
> only monomorphic methods in classes." - Martin Odersky
>
> In what way must methods be monomorphic in OCaml classes?
They don't. With the restriction that the types of polymorphic
methods cannot be inferred. There is also another subtle
limitation, that object are only allowed to have regular
types. As a result, one cannot write a polymorphic map method in
ocaml, but this is possible in Java 2 or Scala.
> On Saturday 29 December 2007 06:30:48 brogoff wrote:
> > What's the date that quote was made?
>
> Yesterday, by the professor heading the group at Lausanne who are developing
> one of the most widely touted modern statically-typed functional programming
> languages (Scala).
>
> > It was probably made before polymorphic methods were added to OCaml from
> > OLabl.
>
> Looks like polymorphic methods have been in OCaml for 5 years now:
>
> http://caml.inria.fr/pub/ml-archives/caml-list/2002/07/0efd71474f4d41a39e4250aeddcf08e5.en.html
Actually, this is now close to 10 years if you include the OLabl
distribution... The original paper on adding semi-implicit first-class
polymorphism to HM was published in 1997.
I'm quite sure that Martin Odersky is aware of this. I would rather
interpret his quote as meaning that you have to extend HM in a
non-trivial way to allow this. He was co-author of two papers
about extending HM with first-class polymorphism ("putting type
annotations to work") and OO (the HM(X) framework), a long time
ago too. All these extensions (including the one used in ocaml) have
drawbacks, in particular they are either verbose or have bad error
messages, or both...
Anyway, you should not underestimate his contribution to this area of
work.
> This is really ossifying my impression that the Scala developers (let alone
> the community) are not aware of the current state-of-the-art in statically
> typed functional programming languages despite the fact that their sole
> purpose is to improve upon them.
>
> Unfortunately, this is rubbing off on the Scala community who keep publishing
> articles making silly claims like "Scala is the first impure functional
> programming language".
This is maybe not fully correct, but at least one can say that Scala
is "the most impure of functional languages" :-)
Cheers,
Jacques Garrigue