This site is updated infrequently. For up-to-date information, please visit the new OCaml website at ocaml.org.

Not a variant??
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
 Date: 2008-08-21 (07:50) From: Jacques Garrigue Subject: Re: [Caml-list] Not a variant??
```From: Jacques Carette <carette@mcmaster.ca>
> Jacques Garrigue wrote:
> > The message is maybe not clear enough: for pattern-matching and
> > inheritance, you need an "exact" variant type, i.e. a type whose lower
> > and upper bounds are identical.
> Indeed - I would suggest that the error include some clearer diagnostics
> that indicate how the variant is 'inexact'.
>
> > The standard workaround is to write:
> >
> > type c0 = [a | b]
> > type 'a c = 'a constraint 'a = [< c0]
> >
> This got me further, thanks.  But not far enough...
> Here is a simple example of the problems I am now running into:
>
> type 'a a = [`A of 'a ]
> type 'a b = [`B of 'a ]
> type    d = [`D ]
> type ('a,'b) e = ['b a | 'a b | d]
>
> type ('a,'b) c = ('a,'b) e
>     constraint 'a = [< 'b a ]
>     constraint 'b = [< 'a b ]
>
> type 'd cc = 'd
>     constraint 'd = [< ('a,'b) c]
>
> let is_cc = function
>     | #cc -> true
>     | _   -> false
> ;;
>
> (* complains that cc is not a variant type when trying to define is_cc *)

Sure, you must use #c as pattern, not #cc.
Or are you thinking of another problem?

Jacques Garrigue

```