Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Obj.magic, Obj.t etc.
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Florian Douetteau <Florian.Douetteau@e...>
Subject: Re: [Caml-list] Obj.magic, Obj.t etc.

>
> As an interesting aside, I've discovered recently that even Obj.repr
> is dangerous:
>
> # Obj.repr;;
> - : 'a -> Obj.t = <fun>
> # let arr = Array.create 1 (Obj.repr 1.0);;
> val arr : Obj.t array = [|<abstr>|]
> # arr.(0) <- Obj.repr 1;;
> Segmentation fault
>
> >From a subtyping point of view, this basically means that there cannot
> be any "top" element in the ocaml type system.

To be fully accurate, it only means that the current implementation of the
code generator would
not support it directly.
If subtyping was to be supported, an unboxed float array would be created
iff
its the compile-time type "float array" (it would be created boxed if typed
"Top array")  .

I don't know if the current runtime implementation makes other assumptions
of the same kind about the lack of subtyping;
for instance, the gc could avoid marking the content of an array starting
with an unboxed integer ? Same thing about list cells.

--
Florian

-------------------
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