caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Ref polymorphism restriction
@ 2000-12-25  7:34 Ohad Rodeh
  2000-12-25 22:09 ` Pierre Weis
  0 siblings, 1 reply; 2+ messages in thread
From: Ohad Rodeh @ 2000-12-25  7:34 UTC (permalink / raw)
  To: Caml List

List,
  The following program does not compile, with a 
rather strange error message. 

module type SIG = 
  sig
    val l : '_a list ref
    val f : '_a -> unit
  end

module M : SIG = 
  struct
    let l = ref [] 
      
    let f a = l:= a::!l
  end


Modules do not match:
  sig val l : '_a list ref val f : '_a -> unit end
is not included in
  SIG
Values do not match:
  val l : '_a list ref
is not included in
  val l : 'a list ref

Note that the signature for list l IS '_a list ref. 

I suppose this is due to the restriction on polymorphic references. 
Is the OCaml restriction such that references may only be local to
a single module? Is there a different restriction? 

	Ohad.

----------------------------------------------------------
orodeh@cs.huji.ac.il
www.cs.huji.ac.il/~orodeh





^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Ref polymorphism restriction
  2000-12-25  7:34 Ref polymorphism restriction Ohad Rodeh
@ 2000-12-25 22:09 ` Pierre Weis
  0 siblings, 0 replies; 2+ messages in thread
From: Pierre Weis @ 2000-12-25 22:09 UTC (permalink / raw)
  To: Ohad Rodeh; +Cc: caml-list

> List,
>   The following program does not compile, with a 
> rather strange error message. 
> 
> module type SIG = 
>   sig
>     val l : '_a list ref
>     val f : '_a -> unit
>   end

Warning, there is a strange feature here that makes your '_a as type
schemes paramters (generalized variables) and not type variables:

        Objective Caml version 3.00

#  module type SIG = sig
     val l : '_a list ref
     val f : '_a -> unit
   end;;
module type SIG = sig val l : 'a list ref val f : 'a -> unit end
#

In effect 'ident means a type scheme parameters. When we introduced
type variables, we denote them by an _ prefix, that was not allowed in
identifiers (as the first character) at that time. Now, identifiers
are allowed to start with an _. Hence '_foo is a perfectly valid
polymorphic type parameter!

> module M : SIG = 
>   struct
>     let l = ref [] 
>       
>     let f a = l:= a::!l
>   end
> 
> 
> Modules do not match:
>   sig val l : '_a list ref val f : '_a -> unit end
> is not included in
>   SIG
> Values do not match:
>   val l : '_a list ref
> is not included in
>   val l : 'a list ref
> 
> Note that the signature for list l IS '_a list ref. 

As mentioned above, no: it is 'a list ref. This explains the
typechecker message.

> I suppose this is due to the restriction on polymorphic references. 
> Is the OCaml restriction such that references may only be local to
> a single module? Is there a different restriction? 
> 
> 	Ohad.
> 
> ----------------------------------------------------------
> orodeh@cs.huji.ac.il
> www.cs.huji.ac.il/~orodeh

Anyway, your right: type variables ('_a types) should not escape the
scope of a module.

Merry Christmas,

Pierre Weis

INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2000-12-25 22:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-12-25  7:34 Ref polymorphism restriction Ohad Rodeh
2000-12-25 22:09 ` Pierre Weis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).