Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: [Caml-list] Type variables won't generalize
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Ryan Tarpine <rtarpine@h...>
Subject: Re: [Caml-list] Type variables won't generalize
>From: Charles Martin <joelisp@yahoo.com>
>To: "Ryan Tarpine" <rtarpine@hotmail.com>
>Subject: Re: [Caml-list] Type variables won't generalize
>Date: Wed, 03 Apr 2002 15:19:25 -0800
>
>
>I'm sure there's a real answer to your question, but in cases like you 
>describe, I always create the records and then assign back into them.  
>Thus:
>
>...
>
>Also, maybe you want to use mutable fields instead of ref?
>
>Charles
>

Using the ref was a silly mistake, yes; that's what I get from moving from a 
single ref to a tuple of refs to a record for storing data as my program 
grew in complexity  :)  But, I'm guessing you did not run the code you 
suggested.  Ocamlc chokes on it in the same manner as my original code.  
Here's exactly what I just tried:

type 'a my_object = {
  mutable partner : 'a my_object;
  mutable data : 'a
};;

let object1 = {
  partner = Obj.magic 0;
  data = `PNone
};;

let object2 = {
  partner = Obj.magic 0;
  data = `PNone
};;

Without even assigning back (it makes no difference whether I do or not), I 
get the same error:

File "foo.ml", line 6, characters 14-58:
The type of this expression, _[> `PNone] my_object,
contains type variables that cannot be generalized

The polymorphic variant is conflicting somehow, and I don't know enough 
about the type system to figure out how to fix it.  I would like to keep the 
variant because I don't know what types of data will be stored in that 
field, and I don't want to restrict it to a certain set.  I would like 
modules in the future to be able to store different types without having to 
recompile the whole program.

Ryan Tarpine, rtarpine@hotmail.com
"To err is human, to compute divine.  Trust your computer but not its 
programmer."
  - Morris Kingston

Ryan Tarpine, rtarpine@hotmail.com
"To err is human, to compute divine.  Trust your computer but not its 
programmer."
  - Morris Kingston

_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners