caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Damien Guichard" <alphablock@orange.fr>
To: "Stéphane Gimenez" <stephane.gimenez@pps.jussieu.fr>
Cc: "The Caml Mailing List" <caml-list@inria.fr>
Subject: Re: [Caml-list] type generalization of recursive calls
Date: Wed, 17 Feb 2010 19:13:22 +0100	[thread overview]
Message-ID: <555701182057358141@orange.fr> (raw)

I have to apologize because your definition is actually correct.
Sorry i have read it too fast and didn't see map burried in type casting.

It seems to me your are doing structural recursion on some binary tree structure.
Presumably to fast-merge binary heaps or something like that.
pa_polyrec is probably a must have for such things.

- damien



Le 17/02/2010 à 17:34:24, "Stéphane Gimenez" <stephane.gimenez@pps.jussieu.fr>
à écrit :
>
>Hi,
>
>I just realized that ocaml generalizes the type of a recursively
>defined function *only* for calls which are outside it's own
>definition. Recursive calls cannot use a generalized type.
>
>In fact, I'm tring to work with such a data type:
>
>type 'a t =
>  | E
>  | D of 'a t * 'a t
>  | O of 'a
>  | I of 'a t t
>
>And, I'm forced to use some dark magic to define simple operations on
>it:
>
>let rec map (f : 'a -> 'b) : 'a t -> 'b t =
>  begin function
>  | E -> E
>  | D (t1, t2) -> D (map f t1, map f t2)
>  | O a -> O (f a)
>  | I tt ->
>      I ((Obj.magic map : ('a t -> 'b t) -> 'a t t -> 'b t t) (map f) tt)
>  end
>
>Questions:
>  - Is it theoreticaly safe to generalize recursive calls ?
>  - Is there a syntactical trick to use generalized recursive calls ?
>  - Could such a generalization be added to the type checker ?
>      - Performance issues ?
>      - More obfusctated type checking errors ?
>
>In a related disscution I found, one asked about generalization
>between mutualy recursive definitions (same problem). No answers, but
>maybe I just lack pointers.
>
>Cheers,
>Stéphane
>
>_______________________________________________
>Caml-list mailing list. Subscription management:
>http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
>Archives: http://caml.inria.fr
>Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>Bug reports: http://caml.inria.fr/bin/caml-bugs
>


--
Mail created using EssentialPIM Free - www.essentialpim.com




             reply	other threads:[~2010-02-17 18:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-17 18:13 Damien Guichard [this message]
  -- strict thread matches above, loose matches on Subject: below --
2010-02-17 17:59 Damien Guichard
2010-02-17 16:34 Stéphane Gimenez
2010-02-17 19:41 ` [Caml-list] " Boris Yakobowski
2010-02-17 20:25   ` Dario Teixeira
2010-02-17 20:33     ` Boris Yakobowski

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=555701182057358141@orange.fr \
    --to=alphablock@orange.fr \
    --cc=caml-list@inria.fr \
    --cc=stephane.gimenez@pps.jussieu.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).