From: skaller <skaller@users.sourceforge.net>
To: brogoff <brogoff@speakeasy.net>
Cc: caml-list@yquem.inria.fr, nicolas.pouillard@gmail.com
Subject: Re: [Caml-list] Polymorphic recursion
Date: Wed, 04 Apr 2007 11:27:06 +1000 [thread overview]
Message-ID: <1175650026.24309.7.camel@rosella.wigram> (raw)
In-Reply-To: <Pine.LNX.4.58.0704031210470.11787@shell4.speakeasy.net>
On Tue, 2007-04-03 at 13:00 -0700, brogoff wrote:
> On Tue, 3 Apr 2007, Till Varoquaux wrote:
> > Therefor, if you wish to use polymorphic recursion (yep you can) you
> > might want to use something where you have to specify the type; this
> > includes records, objects and recursive modules. So this
> >
> > type 'a seq = Unit | Seq of ('a * ('a * 'a)seq)
> >
> > type szRec={f:'a.'a seq -> int};;
> >
> > let size=
> > let rec s =
> > {f=function
> > | Unit -> 0
> > | Seq(_, b) -> 1 + 2 * s.f b}
> > in
> > s.f
> >
> > might be what you where yearning for.
>
> What I'd be yearning for would be more like
>
> let rec size : 'a . 'a seq -> int =
> fun s ->
> match s with Unit -> 0 | Seq(_,b) -> 1 + 2 * (size b)
>
> rather than having to use recursive modules or higher rank polymorphism
> of record fields/polymorphic methods.
Why not:
let fun rec size : 'a . 'a seq -> int =
| Unit -> 0
| Seq(_,b) -> 1 + 2 * (size b)
with a nice camlp4 example for people by nicolas.pouillard@gmail.com ?
--
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net
next prev parent reply other threads:[~2007-04-04 1:27 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-03 16:59 Loup Vaillant
2007-04-03 17:20 ` [Caml-list] " Jeremy Yallop
2007-04-04 5:27 ` Alain Frisch
2007-04-04 12:54 ` Loup Vaillant
2007-04-03 17:35 ` Till Varoquaux
2007-04-03 20:00 ` brogoff
2007-04-04 1:27 ` skaller [this message]
2007-04-04 1:40 ` skaller
2007-04-04 13:49 ` Roland Zumkeller
2007-04-04 15:13 ` Alain Frisch
2007-04-04 15:20 ` Alain Frisch
2007-04-04 16:45 ` Roland Zumkeller
2007-04-04 19:58 ` Alain Frisch
2007-04-04 20:13 ` brogoff
2007-04-05 9:33 ` Roland Zumkeller
2007-04-05 9:54 ` Alain Frisch
2007-04-05 10:07 ` Daniel de Rauglaudre
2007-04-05 9:46 ` Francois Maurel
2007-04-04 15:50 ` Stefan Monnier
2007-04-04 23:36 ` [Caml-list] " Brian Hurt
2007-04-05 8:17 ` Loup Vaillant
-- strict thread matches above, loose matches on Subject: below --
2008-05-12 21:55 polymorphic recursion Jacques Le Normand
2008-05-12 22:16 ` [Caml-list] " Christophe TROESTLER
2003-08-24 18:01 [Caml-list] Polymorphic recursion Lukasz Stafiniak
2003-08-25 0:30 ` Jacques Garrigue
2003-08-25 0:43 ` 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=1175650026.24309.7.camel@rosella.wigram \
--to=skaller@users.sourceforge.net \
--cc=brogoff@speakeasy.net \
--cc=caml-list@yquem.inria.fr \
--cc=nicolas.pouillard@gmail.com \
/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