Re: [Caml-list] obj.magic for polymorphic record fields

2009-12-24 Thread Goswin von Brederlow
Boris Yakobowski writes: > On Tue, Dec 22, 2009 at 2:35 PM, Goswin von Brederlow > wrote: >> But the type inference should deduce that in >> >> (Obj.magic fn) x >> >> the 'a is actually 'b -> 'c as I am applying an argument to it. > > Sure, and it does. But it remains that the principal type of

Re: [Caml-list] obj.magic for polymorphic record fields

2009-12-22 Thread Boris Yakobowski
On Tue, Dec 22, 2009 at 2:35 PM, Goswin von Brederlow wrote: > But the type inference should deduce that in > > (Obj.magic fn) x > > the 'a is actually 'b -> 'c as I am applying an argument to it. Sure, and it does. But it remains that the principal type of (Obj.magic fn) is 'a, without any other

Re: [Caml-list] obj.magic for polymorphic record fields

2009-12-22 Thread Goswin von Brederlow
Boris Yakobowski writes: > On Mon, Dec 21, 2009 at 2:44 PM, Goswin von Brederlow > 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 f

Re: [Caml-list] obj.magic for polymorphic record fields

2009-12-21 Thread Jacques Le Normand
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 eve

Re: [Caml-list] obj.magic for polymorphic record fields

2009-12-21 Thread Boris Yakobowski
On Mon, Dec 21, 2009 at 2:44 PM, Goswin von Brederlow 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",

Re: [Caml-list] obj.magic for polymorphic record fields

2009-12-21 Thread Goswin von Brederlow
"Damien Guichard" writes: >> I once faced this situation and the solution is to use modules. > That is one good practical solution. > > The simpler solution that immediatly came to my mind is eta-expansion. > > type foo = {bar : 'a. 'a -> 'a} > let a : int -> int = fun x -> x > let baz = {b

Re[2]: [Caml-list] obj.magic for polymorphic record fields

2009-12-20 Thread Damien Guichard
> I once faced this situation and the solution is to use modules. That is one good practical solution. The simpler solution that immediatly came to my mind is eta-expansion. type foo = {bar : 'a. 'a -> 'a} let a : int -> int = fun x -> x let baz = {bar = fun x -> (Obj.magic a) x} However i

Re: [Caml-list] obj.magic for polymorphic record fields

2009-12-20 Thread Nicolas Pouillard
Excerpts from Jacques Le Normand's message of Sun Dec 20 18:44:57 +0100 2009: > Dear ocaml-list, > the following code does not type check: > > type foo = {bar : 'a. 'a -> 'a} > let a : int -> int = fun x -> x > let baz = {bar = Obj.magic a} > > with the error > > Error: This field value has type

[Caml-list] obj.magic for polymorphic record fields

2009-12-20 Thread Jacques Le Normand
Dear ocaml-list, the following code does not type check: type foo = {bar : 'a. 'a -> 'a} let a : int -> int = fun x -> x let baz = {bar = Obj.magic a} with the error Error: This field value has type 'a -> 'a which is less general than 'b. 'b -> 'b my question is: how could I use obj.m