From: Alex Baretta <alex@barettadeit.com>
To: Olivier Andrieu <andrieu@ijm.jussieu.fr>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] generic functions
Date: Mon, 10 Jan 2005 13:16:32 +0100 [thread overview]
Message-ID: <41E27220.7040009@barettadeit.com> (raw)
In-Reply-To: <20050110.114716.71093554.andrieu@ijm.jussieu.fr>
Olivier Andrieu wrote:
> Alex Baretta [Mon, 10 Jan 2005]:
> > type poly_int = [ `Int of int ]
> > type poly_float = [ `Float of float ]
> >
> > let foo_int foo = function
> > | `Int x -> `Int(x * x)
> > | other -> foo other
> >
> > let foo_float foo = function
> > | `Float x -> `Float(x *. x)
> > | other -> foo other
> >
> > let rec foo x = match x with
> > | #poly_int -> foo_int foo x
> > | #poly_float -> foo_float foo x
>
> Hum, I would have written this in that way :
> ,----
> | let foo_int (`Int x) = `Int (x * x)
> | let foo_float (`Float x) = `Float (x *. x)
> |
> | let foo = function
> | | #poly_int as x -> foo_int x
> | | #poly_float as x -> foo_float x
> `----
>
> What's the use for the `other -> foo other' clauses ?
In my previous post I mentioned *extensible functions*. The first
parameter of single instances of the polymorphic foo (i.e. foo_int and
foo_float) allow the generalization of each of these to arbitrarily
complex polymorphic type schema. We have exactly 7888 lines of code
which contain such late-bound-recursive functions à la foo_int.
Obviously it takes a relatively complex example to show why
late-bound-recursion is essential to the implementation of a fairly
extensional polymorphism with Ocaml's polymorphic variants.
Alex
--
*********************************************************************
http://www.barettadeit.com/
Baretta DE&IT
A division of Baretta SRL
tel. +39 02 370 111 55
fax. +39 02 370 111 54
Our technology:
The Application System/Xcaml (AS/Xcaml)
<http://www.asxcaml.org/>
The FreerP Project
<http://www.freerp.org/>
next prev parent reply other threads:[~2005-01-10 12:16 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-01-09 13:19 wiedergaenger
2005-01-09 14:56 ` [Caml-list] " Richard Jones
2005-01-09 15:48 ` Brian Hurt
2005-01-09 17:17 ` David McClain
2005-01-09 18:09 ` brogoff
2005-01-09 18:45 ` padiolea
2005-01-10 0:23 ` skaller
2005-01-11 12:14 ` Daniel Yokomizo
2005-01-10 9:55 ` [Caml-list] " Alex Baretta
2005-01-10 10:47 ` Olivier Andrieu
2005-01-10 12:16 ` Alex Baretta [this message]
2005-01-12 23:49 ` Aleksey Nogin
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=41E27220.7040009@barettadeit.com \
--to=alex@barettadeit.com \
--cc=andrieu@ijm.jussieu.fr \
--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