caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Dario Teixeira <darioteixeira@yahoo.com>
To: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
Cc: "caml-list@inria.fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] GADTs and parsers
Date: Mon, 16 Jul 2012 08:12:45 -0700 (PDT)	[thread overview]
Message-ID: <1342451565.67265.YahooMailNeo@web111507.mail.gq1.yahoo.com> (raw)
In-Reply-To: <068D1036-F986-4349-9EEA-B4D7453D5180@math.nagoya-u.ac.jp>

Hi,

> Here is a more complete version of his code.

> I also changed a bit your types, because there is another problem
> using polymorphic variants with GADTs: when you get a GADT
> equation involving a refinable polymorphic variant, you are going
> to get get a local private type. If your type is unbounded, you
> cannot even use subtyping on it. Also [< `Nonlink] has exactly
> the same elements as [ `Nonlink], so it is better to use the latter.
> 
>    Jacques
> 
> type inkind = [ `Link | `Nonlink ]
> 
> type _ inline_t =
>     | Text: string -> [< inkind > `Nonlink ] inline_t
>     | Bold: 'a inline_t list -> 'a inline_t
>     | Link: string -> [< inkind > `Link ] inline_t
>     | Mref: string * [ `Nonlink ] inline_t list -> [< inkind > `Link ] 
> inline_t

Thanks for the input!  You are right, it is easy to forget that a declaration
such as [> `Nonlink ] is way more open than intended, particularly in this
case where only `Nonlink and `Link are in play.

Anyway, this sort of "closed variant", though mentioned in the language reference,
is a subtlety of polymorphic variants which is not mentioned in section 4.2 (tutorial)
of the manual.  I know the manual is not intended as a full-blown tutorial on the
language, but I reckon it could benefit from mentioning this aspect...

Best regards,
Dario Teixeira

      parent reply	other threads:[~2012-07-16 15:12 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-15 16:54 Dario Teixeira
2012-07-15 17:43 ` Gabriel Scherer
2012-07-15 18:58   ` Dario Teixeira
2012-07-15 20:37     ` Gabriel Scherer
2012-07-15 19:55 ` Leo P White
2012-07-16 14:45   ` Dario Teixeira
2012-07-15 22:41 ` Jacques Garrigue
2012-07-16  8:50   ` Leo P White
2012-07-16 10:06     ` Leo P White
2012-07-16 15:12   ` Dario Teixeira [this message]

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=1342451565.67265.YahooMailNeo@web111507.mail.gq1.yahoo.com \
    --to=darioteixeira@yahoo.com \
    --cc=caml-list@inria.fr \
    --cc=garrigue@math.nagoya-u.ac.jp \
    /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;
as well as URLs for NNTP newsgroup(s).