caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Gurr, David (MED, self)" <David.Gurr@med.ge.com>
To: Caml Mailing List <caml-list@inria.fr>
Cc: "Gurr David (MED Self) (E-mail)" <David.Gurr@med.ge.com>
Subject: [Caml-list] a puzzling polymorphic variant type
Date: Wed, 30 Apr 2003 00:35:03 -0500	[thread overview]
Message-ID: <D4DBD8568F05D511A1C20002A55C008C11AC04FD@uswaumsx03medge.med.ge.com> (raw)

I had quick hack I wanted to try with XL's modular module system.  I
changed MiniML.ML.term to a polymorphic variant and thus changed the 
definitions of MiniML.MLScoping.scope_term : MiniML.ML.term ->
MiniML.ML.term
as follows:


    type 'term lst = [
      | `Nil
      | `Cons of 'term * 'term lst
      ]
    type 'term lambda = [
      | `Constant of int                        (* integer constants *)
      | `Longident of path                      (* id or mod.mod...id *)
      | `Function of Ident.t * 'term             (* fun id -> expr *)
      | `Apply of 'term * 'term                   (* expr(expr) *)
      | `Let of Ident.t * 'term * 'term           (* let id = expr in
expr *)
      ]
    type term = [
      | term lambda
      | term lst
      ]

    let rec scope_term_lst scope_term sc = function 
      | `Nil -> `Nil
      | `Cons(h,t) -> `Cons(scope_term sc h,scope_term_lst scope_term sc
t) 

    let rec scope_term_lambda scope_term sc = function
      | `Constant n -> `Constant n
      | `Longident path -> `Longident(Scope.value_path path sc)
      | `Function(id, body) ->
          `Function(id, scope_term (Scope.enter_value id sc) body)
      | `Apply(t1, t2) -> `Apply(scope_term sc t1, scope_term sc t2)
      | `Let(id, t1, t2) ->
          `Let(id, scope_term sc t1, scope_term (Scope.enter_value id
sc) t2)

     let rec scope_term sc  = function
       | #lambda as t -> scope_term_lambda scope_term sc t
       | #lst as t    -> scope_term_lst scope_term sc t

But I did not get the type I expected.  Instead I got:

val scope_term :
 Scope.t ->
 ([< `Apply of 'a * 'a
   | `Cons of 'a * 'a lst
   | `Constant of int
   | `Function of Ident.t * 'a
   | `Let of Ident.t * 'a * 'a
   | `Longident of path
   | `Nil] as 'a) ->
 ([> `Apply of 'b * 'b
   | `Cons of 'b * 'b    <<<<<<<<<<<<<<< what?
   | `Constant of int
   | `Function of Ident.t * 'b
   | `Let of Ident.t * 'b * 'b
   | `Longident of path
   | `Nil] as 'b)

But if I tried a slightly different definition:

     let rec scope_term sc  = function
       | #lambda as t -> scope_term_lambda scope_term sc t
       | `Nil -> `Nil
       | `Cons(h,t) -> `Cons(scope_term sc h,scope_term_lst scope_term
sc t)

Then I do get the type I expect:

val scope_term :
 Scope.t ->
 ([< `Apply of 'a * 'a
   | `Cons of 'a * ([< `Cons of 'a * 'b | `Nil] as 'b)
   | `Constant of int
   | `Function of Ident.t * 'a
   | `Let of Ident.t * 'a * 'a
   | `Longident of path
   | `Nil] as 'a) ->
 ([> `Apply of 'c * 'c
   | `Cons of 'c * ([> `Cons of 'c * 'd | `Nil] as 'd)
   | `Constant of int
   | `Function of Ident.t * 'c
   | `Let of Ident.t * 'c * 'c
   | `Longident of path
   | `Nil] as 'c) 

Does anyone have any ideas?

Thanks, 

-D

-------------------
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:[~2003-04-30  5:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-30  5:35 Gurr, David (MED, self) [this message]
2003-05-08  8:48 ` Jacques Garrigue

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=D4DBD8568F05D511A1C20002A55C008C11AC04FD@uswaumsx03medge.med.ge.com \
    --to=david.gurr@med.ge.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).