caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Oddness with recursive polymorphic variants
@ 2006-05-04 15:54 Jeremy Yallop
  2006-05-04 17:10 ` [Caml-list] " Luc Maranget
  0 siblings, 1 reply; 8+ messages in thread
From: Jeremy Yallop @ 2006-05-04 15:54 UTC (permalink / raw)
  To: caml-list

I have two polymorphic variant types, as follows:

   type f = [`A | `B of f]
   type g = [f | `C]

Next, I have a function from f to g:

   let s1 : f -> g = function
     | `A -> `A
     | `B b -> b

Sadly, the compiler rejects this:

     Characters 57-58:
       | `B b -> b;;
                 ^
   This expression has type f but is here used with type g
   The first variant type does not allow tag(s) `C

The error message seems odd.  Why should it matter that g has more tags 
than f, since every value of f is a value of g (by definition)?

Indeed, minor variants of the function are accepted.  Both of the 
following are ok:

   let s2 : f -> g = function
     | `A -> `A
     | `B (#f as b) -> b

   let s3 : f -> g = function
     | `A -> `A
     | `B ((`A|`B _) as b) -> b

Am I missing something, or is this a bug?

Thanks,

Jeremy.


^ permalink raw reply	[flat|nested] 8+ messages in thread
* Oddness with recursive polymorphic variants
@ 2006-05-04 15:50 Jeremy Yallop
  0 siblings, 0 replies; 8+ messages in thread
From: Jeremy Yallop @ 2006-05-04 15:50 UTC (permalink / raw)
  To: caml-list

I have two polymorphic variant types, as follows:

   type f = [`A | `B of f]
   type g = [f | `C]

Next, I have a function from f to g:

   let s1 : f -> g = function
     | `A -> `A
     | `B b -> b

Sadly, the compiler rejects this:

     Characters 57-58:
       | `B b -> b;;
                 ^
   This expression has type f but is here used with type g
   The first variant type does not allow tag(s) `C

The error message seems odd.  Why should it matter that g has more tags 
than f, since every value of f is a value of g (by definition)?

Indeed, minor variants of the function are accepted.  Both of the 
following are ok:

   let s2 : f -> g = function
     | `A -> `A
     | `B (#f as b) -> b

   let s3 : f -> g = function
     | `A -> `A
     | `B ((`A|`B _) as b) -> b

Am I missing something, or is this a bug?

Thanks,

Jeremy.


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

end of thread, other threads:[~2006-05-05  6:43 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-05-04 15:54 Oddness with recursive polymorphic variants Jeremy Yallop
2006-05-04 17:10 ` [Caml-list] " Luc Maranget
2006-05-04 18:26   ` Michael Wohlwend
2006-05-04 18:33   ` brogoff
2006-05-04 18:58     ` Jeremy Yallop
2006-05-05  0:01       ` brogoff
2006-05-05  6:43         ` Luc Maranget
  -- strict thread matches above, loose matches on Subject: below --
2006-05-04 15:50 Jeremy Yallop

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).