caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Damien <Damien.Pous@ens-lyon.fr>
To: skaller@users.sourceforge.net
Cc: caml users <caml-list@inria.fr>
Subject: Re: [Caml-list] polymorphic variant typing question
Date: Sat, 11 Sep 2004 11:21:15 +0200	[thread overview]
Message-ID: <20040911112115.11837e15@mostha> (raw)
In-Reply-To: <1094888964.27775.39.camel@pelican.wigram>

On 11 Sep 2004 17:49:25 +1000 skaller wrote:

> Consider this:
> [...]
> What this does is extend the regular expression
> type to allow a group combinator, but then reduce it
> by using left/right bracket codes. This typing
> compiles.
> 
> Question: how can I replace the last two lines of
> the match with something which just handles 'all the
> rest of the cases'?
>
> Do I have to factor the original regexp_t into invariant
> and variant parts??
I think yes...

I often use the following scheme :

<<
(* invariant type *)
type t  = [ `A | `B ]

(*** first level ***)
type 'x v1 = [ t | `C of 'x ]
type t1 = 'x v1 as 'x

(* open recursion with r *)
let r1 r = function
  | #t as x -> x
  | `C x -> `C (r x)

(* close the recursion for use at the first level *)
let rec f1: t1 -> t1 = fun x -> r1 f1 x



(*** second level ***)
type 'x v2 = [ 'x v1 | `D of 'x ]
type t2 = 'x v2 as 'x

(* open recursion (use the previous open recursion) *)
let r2 r = function
(*  | `C x -> `D (r x)   (* possible overriding of the `C case *) *)
  | #v1 as x1 -> r1 r x1
  | `D x -> `D (r x)

(* close the recursion at the second level *)
let rec f2: t2 -> t2 = fun x -> r2 f2 x



(* second to first level (similar to your groupify function) *)
let r21 r = function
  | #v1 as x1 -> r1 r x1 (* first level recursion *)
  | `D x -> `C (r x) (* convert GROUPS into brackets here... *)
let rec f21: t2 -> t1 = fun x -> r21 f21 x
>>

You may be interested by this paper from Jacques Garrigue :
<http://wwwfun.kurims.kyoto-u.ac.jp/~garrigue/papers/variant-reuse.pdf>

Hope this helps,
damien


-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


      reply	other threads:[~2004-09-11  9:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-11  7:49 skaller
2004-09-11  9:21 ` Damien [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=20040911112115.11837e15@mostha \
    --to=damien.pous@ens-lyon.fr \
    --cc=caml-list@inria.fr \
    --cc=skaller@users.sourceforge.net \
    /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).