From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 4E9FCBC57 for ; Thu, 19 Aug 2010 15:49:34 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: As8BAGbTbEzRVdg0kGdsb2JhbACDGI93jUUIFQEBAQEJCQwHEQMfohqIXIJPhkKJAgEBAwWBHYMicwSJcYg+ X-IronPort-AV: E=Sophos;i="4.56,233,1280700000"; d="scan'208";a="67993822" Received: from mail-qw0-f52.google.com ([209.85.216.52]) by mail4-smtp-sop.national.inria.fr with ESMTP; 19 Aug 2010 15:49:33 +0200 Received: by qwj8 with SMTP id 8so1925224qwj.39 for ; Thu, 19 Aug 2010 06:49:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:sender:received :in-reply-to:references:date:x-google-sender-auth:message-id:subject :from:to:cc:content-type; bh=WWAo3xmrIeSGey3YBgH1PbKQPbA1dUF5dmgQUBi0THI=; b=UdCC3EOSKJb4fm5xGtl1EoD+PrVfP/3j1iUu1fYVuSxnTYrx5JAPFfMqAJrLO5qzhO kiLPX4Vo6fJ7xGn4IkS/egjF3bxf9dTm8vX3BA10hB8dxAljFc1YE8NE+Y9fvOMeXAKZ GlTmMOyeh09Dr1Q4kl7KzUeSo5+JiwIgRdBeA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; b=qGNH7rZhCk51KGKjs6Bw1qBm4/wOBdGd9EllZhbJRhiX4s71fbwmn6sAWk7jjT7jWl Hj18sTuAaizPHl1skU2XPRsVibvqLuyKZTOxVqk+r3aKnpDjlxt9gJX0QbpYPlufx403 aZ671xo8jCD1sqqxPGYXbqSXjaNt5ACH/dpNw= MIME-Version: 1.0 Received: by 10.224.61.12 with SMTP id r12mr1104422qah.101.1282225772604; Thu, 19 Aug 2010 06:49:32 -0700 (PDT) Sender: till.varoquaux@gmail.com Received: by 10.229.214.73 with HTTP; Thu, 19 Aug 2010 06:49:32 -0700 (PDT) In-Reply-To: References: Date: Thu, 19 Aug 2010 09:49:32 -0400 X-Google-Sender-Auth: GoT67O4z0E_CW7S_DVXy4K3hBM4 Message-ID: Subject: Re: [Caml-list] Question about float refs. From: Till Varoquaux To: David House Cc: Ethan Burns , caml-list@yquem.inria.fr, Wheeler Ruml Content-Type: text/plain; charset=UTF-8 X-Spam: no; 0.00; runtime:01 arrays:01 runtime:01 val:01 val:01 beginner's:01 ocaml:01 bug:01 beginners:01 wrote:01 pps:01 caml-list:01 caml-list:01 functions:01 jussieu:01 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 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 >