caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Error: In the definition of t, type ('a, 'b) t should be ('b, 'a) t
@ 2010-01-06  6:39 Edgar Friendly
  2010-01-06  7:47 ` [Caml-list] " Jacques Garrigue
  0 siblings, 1 reply; 2+ messages in thread
From: Edgar Friendly @ 2010-01-06  6:39 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] Error: In the definition of t, type ('a, 'b) t should be ('b, 'a) t
  2010-01-06  6:39 Error: In the definition of t, type ('a, 'b) t should be ('b, 'a) t Edgar Friendly
@ 2010-01-06  7:47 ` Jacques Garrigue
  0 siblings, 0 replies; 2+ messages in thread
From: Jacques Garrigue @ 2010-01-06  7:47 UTC (permalink / raw)
  To: thelema314; +Cc: caml-list

From: Edgar Friendly <thelema314@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




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-01-06  7:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-06  6:39 Error: In the definition of t, type ('a, 'b) t should be ('b, 'a) t Edgar Friendly
2010-01-06  7:47 ` [Caml-list] " Jacques Garrigue

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).