caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Till Varoquaux <till@pps.jussieu.fr>
To: David House <dmhouse@gmail.com>
Cc: Ethan Burns <burns.ethan@gmail.com>,
	caml-list@yquem.inria.fr, Wheeler Ruml <ruml@cs.unh.edu>
Subject: Re: [Caml-list] Question about float refs.
Date: Thu, 19 Aug 2010 09:49:32 -0400	[thread overview]
Message-ID: <AANLkTi=mdVXZZOXm+=cvy2Tpe5AQ_jt01WS_xQX3EwS=@mail.gmail.com> (raw)
In-Reply-To: <AANLkTinQRGWcGucXvc81WFKL-et=vX0gODod580o9kFm@mail.gmail.com>

What you want is the system to check at runtime whether it should box
the values or not. If you really care about this behaviour you can use
arrays instead of records:

type 'a ref = 'a array
let ref v = Array.create 1 v

let (!) v = v.(0)

let ( := ) v x = v.(0) <- x

I don't expect this to come without a runtime cost.
Till

On Thu, Aug 19, 2010 at 9:34 AM, David House <dmhouse@gmail.com> wrote:
> Note that you can directly observe boxedness using the Obj functions:
>
> # type t1 = { a : float; b : int };;
> type t1 = { a : float; b : int; }
> # type t2 = { c : float; d : float };;
> type t2 = { c : float; d : float; }
> # let x1 = { a = 1.; b = 2 };;
> val x1 : t1 = {a = 1.; b = 2}
> # let x2 = { c = 3.; d = 4. };;
> val x2 : t2 = {c = 3.; d = 4.}
> # Obj.tag (Obj.repr x1);;
> - : int = 0
> # Obj.tag (Obj.repr x2);;
> - : int = 254
>
> For the use case you describe, I believe your best bet is to define a
> float_ref type as you describe.
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>


  reply	other threads:[~2010-08-19 13:49 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-19 11:52 Ethan Burns
2010-08-19 13:14 ` [Caml-list] " Lukasz Stafiniak
2010-08-19 13:34 ` David House
2010-08-19 13:49   ` Till Varoquaux [this message]
2010-08-23 12:06 ` Christophe TROESTLER
2010-08-23 12:14   ` Ethan Burns
2010-08-23 12:42     ` Sylvain Le Gall
2010-08-23 13:00       ` [Caml-list] " Dmitry Bely
2010-08-31 19:41         ` Jon Harrop
2010-09-01  7:18           ` Dmitry Bely
2010-09-01  7:46             ` Christophe TROESTLER
2010-09-01  8:31             ` Fabrice Le Fessant
2010-09-01  9:54               ` Ethan Burns
2010-09-01 12:29                 ` Fabrice Le Fessant

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='AANLkTi=mdVXZZOXm+=cvy2Tpe5AQ_jt01WS_xQX3EwS=@mail.gmail.com' \
    --to=till@pps.jussieu.fr \
    --cc=burns.ethan@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=dmhouse@gmail.com \
    --cc=ruml@cs.unh.edu \
    /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).