Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Ref polymorphism restriction
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Ohad Rodeh <orodeh@c...>
Subject: Ref polymorphism restriction
  The following program does not compile, with a 
rather strange error message. 

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

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

Modules do not match:
  sig val l : '_a list ref val f : '_a -> unit end
is not included in
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?