Account Options

  1. Sign in
Google Groups Home
« Groups Home
Message from discussion ANN: pa_polyrec: syntax for polymorphic recursion
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Jeremy Yallop  
View profile  
 More options Sep 28 2009, 4:56 pm
Newsgroups: fa.caml
From: Jeremy Yallop <yal...@gmail.com>
Date: Mon, 28 Sep 2009 20:56:39 UTC
Local: Mon, Sep 28 2009 4:56 pm
Subject: [Caml-list] ANN: pa_polyrec: syntax for polymorphic recursion
I'm pleased to announce the initial release of pa_polyrec, a syntax extension
for polymorphic recursion in OCaml.

    https://forge.ocamlcore.org/projects/pa-polyrec/

There are several methods for encoding polymorphic-recursive functions in OCaml;
this extension allows them to be written directly, using a natural syntax.  For
example, given the following type of perfectly-balanced trees we might wish to
write a function for summing the leaves.

   type 'a perfect = Zero of 'a | Succ of ('a * 'a) perfect

In standard OCaml such a function can be written as follows:

   let sump f =
     (object (o)
         method sump : 'a. ('a -> int) -> 'a perfect -> int =
           fun f -> function
            | Zero x -> f x
            | Succ x -> o#sump (fun (a, b) -> f a + f b) x
      end)#sump f

   let sum_perfect = sump id

Using pa_polyrec one can write the function in the following less obfuscated style:

   let rec sump : 'a. ('a -> int) -> 'a perfect -> int =
     fun f -> function
      | Zero x -> f x
      | Succ x -> sump (fun (a, b) -> f a + f b) x

   let sum_perfect = sump id

Note that the type variable 'a in the type of the function is quantified: this
is what differentiates polymorphic-recursive functions from standard OCaml
recursive function definitions.

More complex usage is supported, including mutual recursion.  A number of
examples are included in the distribution, including several modules from Chris
Okasaki's thesis "Purely Functional Data Structures" and code from Richard Bird
and Ross Paterson's paper "de Bruijn notation as a nested datatype".

_______________________________________________
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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.