caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Ryan Tarpine" <rtarpine@hotmail.com>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Type variables won't generalize
Date: Wed, 03 Apr 2002 20:37:02 -0500	[thread overview]
Message-ID: <F268yKFRJrzdDW6lCPx000080c8@hotmail.com> (raw)

>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


             reply	other threads:[~2002-04-04  1:37 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-04-04  1:37 Ryan Tarpine [this message]
2002-04-04  7:36 ` Francois Pottier
  -- strict thread matches above, loose matches on Subject: below --
2002-04-04 19:53 Ryan Tarpine
2002-04-04 12:19 Ryan Tarpine
2002-04-04 12:04 ` Remi VANICAT
2002-04-04 12:58 ` Jacques Garrigue
2002-04-03 22:21 Ryan Tarpine

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=F268yKFRJrzdDW6lCPx000080c8@hotmail.com \
    --to=rtarpine@hotmail.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).