caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Michael Vanier <mvanier@cs.caltech.edu>
To: martin_jambon@emailuser.net
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] extensible records again
Date: Sun, 21 Mar 2004 01:22:17 -0800 (PST)	[thread overview]
Message-ID: <20040321092217.BBA0E9BBA2@orchestra.cs.caltech.edu> (raw)
In-Reply-To: <Pine.LNX.4.40.0403211617410.1400-100000@localhost> (message from Martin Jambon on Sun, 21 Mar 2004 16:53:38 +0800 (HKT))


Interesting.  I'll try it.  Thanks!

Mike

> Date: Sun, 21 Mar 2004 16:53:38 +0800 (HKT)
> From: Martin Jambon <martin_jambon@emailuser.net>
> Cc: caml-list@inria.fr
> 
> On Sat, 20 Mar 2004, Michael Vanier wrote:
> 
> > So I tried this.  Aside from the pain of having to change data to 'a data in
> > lots of places (which I can live with), I got bitten by the polymorphic
> > reference limitation.  Specifically, I have a mutable stack of data values
> > which became a mutable stack of 'a data values, but the function which
> > creates the mutable stack is of type '_a data, so it doesn't type check.  I
> > can't figure out any way around this.  Basically, my main data type _cannot_
> > be parameterized.
> 
> Keep your code polymorphic: create your stack in the same compilation
> unit as the full type instanciation.
> Then you have to pass your stack as a parameter
> to all functions that use it.
> 
> I guess this is more or less what you do:
> 
> (* a.ml *)
> let stack =
>   let st = Stack.create () in
>   Stack.push (`Int 1) st;
>   st
> (* compiler complains about '_ *)
> 
> 
> (* b.ml *)
> let some_function x =
>    match Stack.pop stack with
>        `Int i -> print_int i
>      | `Custom s -> print_string s
>      | _ -> ()
> 
> 
> Instead you should write:
> 
> (* a.ml *)
> let init_stack () =
>   let st = Stack.create () in
>   Stack.push (`Int 1) st;
>   st
> 
> 
> (* b.ml *)
> let some_function stack x =
>   match Stack.pop stack with
>       `Int i -> print_int i
>     | `Custom s -> print_string s
>     | _ -> print_float x
> 
> let _ =
>   let stack = A.init_stack () in
>   some_function stack 1.2
> 
> 
> I hope it answers your question...
> 
> Martin
> 
> 

-------------------
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:[~2004-03-21  9:22 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-21  6:21 Michael Vanier
2004-03-21  8:08 ` Oleg Trott
2004-03-21  8:40   ` Michael Vanier
2004-03-21 16:10     ` Oleg Trott
2004-03-21 17:06       ` skaller
2004-03-21 17:36         ` Oleg Trott
2004-03-22  3:19           ` skaller
2004-03-22  7:49           ` Ville-Pertti Keinonen
2004-03-22  9:32             ` Oleg Trott
2004-03-22 10:25               ` Ville-Pertti Keinonen
2004-03-21 22:35         ` Michael Vanier
2004-03-22  3:39           ` skaller
2004-03-21 22:34       ` Michael Vanier
2004-03-22  3:31         ` skaller
2004-03-22  5:54           ` Michael Vanier
2004-03-23 19:14             ` skaller
2004-03-24  1:41               ` Jacques Garrigue
2004-03-24  8:44                 ` Julien Signoles
2004-03-24 10:04                   ` Jacques Garrigue
2004-03-21  8:53 ` Martin Jambon
2004-03-21  9:22   ` Michael Vanier [this message]
2004-03-21 17:00 ` skaller
2004-03-22  8:13 ` Achim Blumensath
2004-03-23  2:14   ` Michael Vanier
2004-03-23  7:25     ` Achim Blumensath
2004-03-31 10:05 ` Marcin 'Qrczak' Kowalczyk

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=20040321092217.BBA0E9BBA2@orchestra.cs.caltech.edu \
    --to=mvanier@cs.caltech.edu \
    --cc=caml-list@inria.fr \
    --cc=martin_jambon@emailuser.net \
    /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).