Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: skaller <skaller@users.sourceforge.net>
To: caml-list@inria.fr
Subject: pm variant type question
Date: Fri, 24 Aug 2007 15:01:44 +1000	[thread overview]
Message-ID: <1187931704.7202.9.camel@rosella.wigram> (raw)

I'm having trouble typing this: we have:

type 'a regexp_t' =
  [
  | `REGEXP_seq of 'a regexp_t' * 'a regexp_t' (** concatenation *)
  | `REGEXP_alt of 'a regexp_t' * 'a regexp_t' (** alternation *)
  | `REGEXP_aster of 'a regexp_t'  (** Kleene closure *)
  | `REGEXP_string of string   (** concatenation of chars of string *)
  | `REGEXP_epsilon            (** epsilon: null string *)
  ]

type regexp_t = 'a regexp_t' as 'a
type 'c xreg_t = [
  'a regexp_t' | 
  `REGEXP_sentinel | 
  `REGEXP_code of 'c ] as 'a

let extend (r:regexp_t):'c xreg_t = (r:regexp_t :> 'c xreg_t)

let mklexer rs =
  match rs with
  | [] -> failwith "Empty Lexer list"
  | (hr,hc)::t ->
    let re = List.fold_left
      (fun acc (r,c) -> 
        `REGEXP_alt (acc, `REGEXP_seq (r, `REGEXP_code c)))
      (`REGEXP_seq (hr, `REGEXP_code hc)) t
    in process_regexp re


Basically, mklexer takes a list of regexp_t, but the supertype
formed by adding the sentinel and code combinators is used
internally.

The code above works, but I cannot seem to write an mli interface
for mklexer, which should be:

val 'c mklexer : (regexp_t * 'c) list -> 'c something

[Take a list of pairs, of regexp and some code, and generate
a lexer]

The coercion 'extend' above exhibits the desired widening ..
well I think it does, but it doesn't work even if I try

let mkelxer (rs: (regexp_t * 'c) list) : 'c something =
	let rs = map extend rs in ...


This is a very simple covariant extension .. why can't I get
it right? 

-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net


             reply	other threads:[~2007-08-24  5:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-24  5:01 skaller [this message]
2007-08-24 10:14 ` [Caml-list] " Jeremy Yallop
2007-08-24 10:23   ` skaller

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=1187931704.7202.9.camel@rosella.wigram \
    --to=skaller@users.sourceforge.net \
    --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