Version française
Home     About     Download     Resources     Contact us    
Browse thread
Error: In the definition of t, type ('a, 'b) t should be ('b, 'a) t
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Garrigue <garrigue@m...>
Subject: Re: [Caml-list] Error: In the definition of t, type ('a, 'b) t should be ('b, 'a) t
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