English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Question about float refs.
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2010-08-19 (13:14)
From: Lukasz Stafiniak <lukstafi@g...>
Subject: Re: [Caml-list] Question about float refs.
On Thu, Aug 19, 2010 at 1:52 PM, Ethan Burns <burns.ethan@gmail.com> wrote:
> Hello,
> I noticed a strange behavior when using references to floating point
> values.  My suspicion, initially, was that the references would not be
> boxed because they are the same as a record with a single mutable
> field that is of type float.  It seems that OCaml still boxes float
> refs.

Note that refs are just a standard polymorphic type defined in Pervasives:

  type 'a ref = {
    mutable contents : 'a ;

Being polymorphic, the "float ref" are not unboxed: imagine what would
happen when you passed them to a function

foo : 'a ref -> 'a list = fun x -> [ !x ]

or similar (with a negative occurrence of polymorphic ref).