English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
What is a future of ocaml?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2009-01-15 (12:13)
From: Jacques Garrigue <garrigue@m...>
Subject: Re: [Caml-list] What is a future of ocaml?
From: "David Allsopp" <dra-news@metastack.com>
> Dawid Toton wrote:
> > Could anybody explain why it's impossible to have type classes in OCaml?
> I don't think it's impossible - but I believe that if you introduce type
> classes then you "damage" Hindley-Milner type inference and you can no
> longer derive a principal typing for an arbitrary ML expression without
> resorting to type annotations. Whether this is a problem or not is a matter
> of taste - but it does make the language harder to call "ML" if you lose one
> of its central features! That said, there are of course two big features
> (objects and polymorphic variants) in OCaml already which do require
> annotations.

The reason is mostly wrong :-)
One can have both type classes and principal types; the problem with
principal types in Haskell is more subtle thant that.
And neither polymorphic variants nor object require type anotations in
ocaml; they just make it much more painful to understand error
Principality is only broken by optional arguments and polymorphic
methods, and there is a -principal flag that recovers some form of
principality (requiring type annotations).

This said, type classes have a lot of common features with modules or
objects, so this would be yet another way to do some similar things.
More problematic, type classes depend on the nominality of the type
systems, while ocaml has a rich language of structural types. For
instance, it is not completely clear how one could select instances of
type classes for polymorphic variants, without introducing conflicts.
I'm afraid the combination of type classes with modules and functors
is not trivial either.

Jacques Garrigue