Version franaise
Home About Download Resources Contact us
Browse thread
Safe Obj.magic container ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Tom_Primožič <tom.primozic@g...>
Subject: Re: [Caml-list] Safe Obj.magic container ?
The following are my experience and guesses, nothing
scientific/official/thoroughly tested:

> 1. can I assume that this is always going to work if u is 'a.'a   ?


Well, there is no type 'a.'a. You can have:
type u = { everything: 'a . 'a }
but this presupposes that values of type u are blocks (heap-allocated).
Therefore, if you cast a boolean (true) to type u, and then try to access
the everything field of the "new" value, you will get a segfault.

3. assuming the answer to 1. is No, is there a type u or a simple
> manipulation which should work for any type t ? Or perhaps just for
> polymorphic variants ?
>

type u = int
this will work for any type. You can even do pointer manipulation with it
(adding and subtracting even numbers of bytes).

Sorry everybody.

 - Tom