caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Dario Teixeira <darioteixeira@yahoo.com>
To: "caml-list@inria.fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] GADTs and parsers
Date: Mon, 16 Jul 2012 07:45:29 -0700 (PDT)	[thread overview]
Message-ID: <1342449929.34621.YahooMailNeo@web111508.mail.gq1.yahoo.com> (raw)
In-Reply-To: <Prayer.1.3.5.1207152055260.20778@hermes-2.csi.cam.ac.uk>

Hi,

> What about something like (not really tested):

> 
> type _ guard_t =    | Nonlinked: [> `Nonlink ] guard_t
>    | Either: [> `Nonlink | `Link ] guard_t
> 
> let inlineseq_from_astseq seq =
> let rec process : type a. a guard_t -> ast_t -> a inline_t =  fun guard 
> ast ->   match (guard, ast) with
>   | (Nonlinked, Ast_Text txt)   -> Text txt
>   | (Either, Ast_Text txt)      -> Text txt
>   | (x, Ast_Bold xs)            -> Bold (List.map (process x) xs)
>   | (Either, Ast_Link lnk)      -> Link lnk
>   | (Either, Ast_Mref (lnk, xs))         -> Mref (lnk, List.map (process 
> Nonlinked) xs)   | _   -> assert false
> in List.map (process Either) seq

I see what you mean -- using an auxiliary GADT basically.
Nice technique to keep in mind -- thanks!

Cheers,
Dario

  reply	other threads:[~2012-07-16 14:45 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 [this message]
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

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=1342449929.34621.YahooMailNeo@web111508.mail.gq1.yahoo.com \
    --to=darioteixeira@yahoo.com \
    --cc=caml-list@inria.fr \
    /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).