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.

Type constraints
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
 Date: 2004-12-07 (19:26) From: Boris Yakobowski Subject: Re: [Caml-list] Type constraints
```On Tue, Dec 07, 2004 at 06:44:36PM +0100, Damien Doligez wrote:
>
> On 7 Dec 2004, at 15:57, Andreas Rossberg wrote:
>
> >Is this really a counter-example? I don't see any problem with making
> >it polymorphic - it evaluates to ref, and ref can happily be
> >polymorphic.
>
> Yes, well I simplified it a bit too much.  Try this instead:
>
>   let module M = struct let v = ref [] end in M.v;;

The question remains : why not generalize type variables which would be
generalized at the end of a non local module? :

# module M = struct let v = ref [] end;;
module M : sig val v : '_a list ref end
# module M = struct let v x = x end;;
module M : sig val v : 'a -> 'a end
# let module M = struct let v = ref [] end in M.v;;
- : '_a list ref = {contents = []}
# let module M = struct let v x = x end in M.v
(* This seems overly restrictive *);;
- : '_a -> '_a = <fun>

Besides:
# type t = {t : 'a. 'a -> 'a};;
type t = { t : 'a. 'a -> 'a; }
# let module M = struct let v x = x end in { t = M.v };;
- : t = {t = <fun>}

--
Boris

```