[Caml-list] Error: In the definition of t, type ('a, 'b) t should be ('b, 'a) t

2010-01-05 Thread Edgar Friendly

This error message was new to me, and I wondered what's going on and why:

# type ('a, 'b) t = [ `A | `T of ('b, 'a) t ];;
Error: In the definition of t, type ('a, 'b) t should be ('b, 'a) t

I can get unhelpful suggestions through foolishness with three type 
parameters:
# type ('a, 'b, 'c) t = [ `A | `T of ('a, 'c, 'b) t | `V of ('b, 'c, 'a) 
t];;

Error: In the definition of t, type ('a, 'b, 'c) t should be ('c, 'a, 'b) t
# type ('c, 'a, 'b) t = [ `A | `T of ('a, 'c, 'b) t | `V of ('b, 'c, 'a) 
t];;

Error: In the definition of t, type ('a, 'b, 'c) t should be ('b, 'c, 'a) t

Any explanation of what's going on?

Thanks,
E

___
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


Re: [Caml-list] Error: In the definition of t, type ('a, 'b) t should be ('b, 'a) t

2010-01-05 Thread Jacques Garrigue
From: Edgar Friendly thelema...@gmail.com
 This error message was new to me, and I wondered what's going on and
 why:
 
 # type ('a, 'b) t = [ `A | `T of ('b, 'a) t ];;
 Error: In the definition of t, type ('a, 'b) t should be ('b, 'a) t

Structural recursive types (objects and polymorphic variants) must be
regular. I.e., type abbreviations must always have the same
parameters.
The error message is a bit confusing, due to the way type variables
are printed  (original names are not kept), but it says that type
parameters got exchanged.

If you really want to define this type, you have to unroll it by hand:

type ('a, 'b) t = [ `A of 'a | `T of [ `A of 'b | `T of ('a,'b) t]];;

(I added an argument to `A to make the parameters meaningful.)

Jacques Garrigue



___
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