From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 05C11BC69 for ; Fri, 24 Aug 2007 07:03:00 +0200 (CEST) Received: from ipmail01.adl2.internode.on.net (ipmail01.adl2.internode.on.net [203.16.214.140]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l7O52vrl024492 for ; Fri, 24 Aug 2007 07:02:58 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAFYAzkY7pw2h/2dsb2JhbAAM X-IronPort-AV: E=Sophos;i="4.19,303,1183300200"; d="scan'208";a="178551601" Received: from ppp59-167-13-161.lns2.syd7.internode.on.net (HELO [192.168.1.201]) ([59.167.13.161]) by ipmail01.adl2.internode.on.net with ESMTP; 24 Aug 2007 14:32:04 +0930 Subject: pm variant type question From: skaller To: caml-list@inria.fr Content-Type: text/plain Date: Fri, 24 Aug 2007 15:01:44 +1000 Message-Id: <1187931704.7202.9.camel@rosella.wigram> Mime-Version: 1.0 X-Mailer: Evolution 2.10.1 Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 46CE6681.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; regexp:01 regexp:01 seq:01 failwith:01 lexer:01 seq:01 supertype:01 combinators:01 mli:01 val:01 lexer:01 sourceforge:01 typing:01 pairs:01 coercion:01 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 Felix, successor to C++: http://felix.sf.net