Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: carette@mcmaster.ca
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Not a variant??
Date: Wed, 20 Aug 2008 12:21:02 +0900 (JST)	[thread overview]
Message-ID: <20080820.122102.241911903.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <48AB4F06.4070208@mcmaster.ca>

From: Jacques Carette <carette@mcmaster.ca>

> The function f1 below works fine -- so type d is seen to be a variant type.
> However, f2 does not compile because type c is *not* a variant type. 
> 
> However, if one looks at O'Caml's output for type c, it visually looks 
> like a variant, while that of d does not.  This is highly confusing.
> 
> This looks like a bug to me -- both c and d should be recognized as 
> variant types.
> 
> Jacques
> 
> type a = [`A ]
> type b = [`B ]
> type 'a c = 'a
>     constraint 'a = [< a | b]
>     ;;

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. This is clearly not the case for
c. The standard workaround is to write:

type c0 = [a | b]
type 'a c = 'a constraint 'a = [< c0]

Jacques Garrigue


  reply	other threads:[~2008-08-20  3:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-19 22:53 Jacques Carette
2008-08-20  3:21 ` Jacques Garrigue [this message]
2008-08-20 13:24   ` [Caml-list] " Jacques Carette
2008-08-21  5:10     ` Jacques Garrigue

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080820.122102.241911903.garrigue@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=carette@mcmaster.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox