Browse thread
Re[2]: [Caml-list] obj.magic for polymorphic record fields
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Jacques Le Normand <rathereasy@g...> |
| Subject: | Re: [Caml-list] obj.magic for polymorphic record fields |
right, the use case is totally wrong
I'm automatically generating code from type declarations using camlp4 and it
would break down in presence of polymorphic record fields.
Here's the fix I chose (Thanks to Mr. Pouillard):
module type MagicSignature =
sig
val x : 'a
end
and I would replace every occurence of
{bar = x}
with
let module X : MagicSignature = (struct let y = x end) in {bar = X.y}
-Jacques L.
On Mon, Dec 21, 2009 at 9:00 AM, Boris Yakobowski <boris@yakobowski.org>wrote:
> On Mon, Dec 21, 2009 at 2:44 PM, Goswin von Brederlow <goswin-v-b@web.de>
> wrote:
> >> However it issues a warning so i acknowledge it's less elegant.
> >
> > Which I don't quite understand.
>
> The warning is based on the results of the type inference algorithm.
> You're not supposed to find values of type 'a. 'a "in the wild", yet
> (Obj.magic a) has this type. Thus the Ocaml compiler deduces that
> you're doing something wrong: your function never returns, it does not
> use its arguments, etc. Here, using Obj.magic breaks the crystal ball
> of the compiler, and the warning is incorrect.
>
> There is an easy way to silence the warning though:
>
> let baz = {bar = fun x -> (Obj.magic a : _ -> _) x}
>
> (but not let baz = {bar = fun x -> (Obj.magic a : 'a -> 'a) x} for
> ugly reasons...)
>
> You are however quite correct. Using Obj.magic in this particular case
> seems quite wrong.
>
> --
> Boris
>
> _______________________________________________
> 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
>