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