Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* [Caml-list] OR-patterns with GADTs
@ 2014-11-21 18:39 Ashish Agarwal
  2014-11-21 21:04 ` Leo White
  0 siblings, 1 reply; 3+ messages in thread
From: Ashish Agarwal @ 2014-11-21 18:39 UTC (permalink / raw)
  To: Caml List

[-- Attachment #1: Type: text/plain, Size: 554 bytes --]

The following works fine:

type foo
type bar
type _ t =
| Foo : string -> foo t
| Bar : string -> bar t

let to_string : type a . a t -> string = function
  | Foo x -> x
  | Bar x -> x


However, if you try to avoid the redundant code of the two branches, you
get a compile error:

let to_string : type a . a t -> string = function
  | Foo x
  | Bar x -> x

Error: This pattern matches values of type foo t
       but a pattern was expected which matches values of type a t
       Type foo is not compatible with type a

Is there a real reason for this?

[-- Attachment #2: Type: text/html, Size: 915 bytes --]

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

end of thread, other threads:[~2014-11-22 12:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-21 18:39 [Caml-list] OR-patterns with GADTs Ashish Agarwal
2014-11-21 21:04 ` Leo White
2014-11-22 12:44   ` Ashish Agarwal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox