caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Jacques Le Normand" <rathereasy@gmail.com>
To: "caml-list caml-list" <caml-list@yquem.inria.fr>
Subject: polymorphic recursion clarification
Date: Mon, 12 May 2008 18:22:13 -0400	[thread overview]
Message-ID: <f74178430805121522t406439d4naa46f75b03a7652c@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1041 bytes --]

maybe I should state why I need polymorphic recursion
consider the function traverse which takes a function and an element of what
I want to traverse and returns a list of results.

let rec traverse f n=
  let ret = f n in
  let rest = match n#get_right_sibling_specific with
      None -> []
    | Some y -> traverse f y
  in
  let rest2 = match n#get_child_specific with
      None -> []
    | Some y -> traverse f y
  in
    match ret with
    None -> rest @ rest2
      | Some y -> y :: rest @ rest2


with type

val traverse :
  ((< get_child_specific : 'a option; get_right_sibling_specific : 'a
option;
      .. >
    as 'a) ->
   'b option) ->
  'a -> 'b list

the problem is that get_child_specific may not return an 'a option, but it
will always return a subtype of 'a option. is there any way to do this? ie,
give it a type

((< get_child_specific : #'a option; get_right_sibling_specific : #'a
option;
      .. >
    as 'a) ->
   'b option) ->
  'a -> 'b list

? (I believe this can be done with polymorphic recursion)
--Jacques

[-- Attachment #2: Type: text/html, Size: 1546 bytes --]

                 reply	other threads:[~2008-05-12 22:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=f74178430805121522t406439d4naa46f75b03a7652c@mail.gmail.com \
    --to=rathereasy@gmail.com \
    --cc=caml-list@yquem.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).