Version française
Home     About     Download     Resources     Contact us    
Browse thread
mutable and polymorphism
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Radu Grigore <radugrigore@g...>
Subject: mutable and polymorphism
Compile the following three files one-by-one.
  (*a.ml*) let _ = ref () in let f = fun _ -> () in f 1; f 'a'
  (*b.ml*) let f = let _ = () in fun _ -> () in f 1; f 'a'
  (*c.ml*) let f = let _ = ref () in fun _ -> () in f 1; f 'a'
The files a.ml and b.ml compile; the file c.ml fails with
  Error: This expression has type char
    but an expression was expected of type int
Could someone explain why having a mutable field ("contents" in this
case) restricts the polymorphism of f?

PS: A few hours ago I tried to post from Google Groups, but the
message didn't seem to go thru. Apologies if this is a duplicate