caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques GARRIGUE <garrigue@kurims.kyoto-u.ac.jp>
To: skaller@users.sourceforge.net
Cc: jon@jdh30.plus.com, caml-list@inria.fr
Subject: Re: [Caml-list] C++ STL and template features compared with OCaml parametric polymorphism and OO features
Date: Mon, 27 Sep 2004 18:40:51 +0900 (JST)	[thread overview]
Message-ID: <20040927.184051.125125212.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <1096260483.28613.426.camel@pelican.wigram>

From: skaller <skaller@users.sourceforge.net>
> On Mon, 2004-09-27 at 11:59, Jon Harrop wrote:
> 
> >  In practice, I'm all for 
> > aggressive factoring but I can't see what we're factoring here...
> 
> Sure you can. Consider:
> 
> type 'a F = A | B of 'a | C of 'a * 'a * int 
> 
> Can you write a map function for this? Of course you
> can! What about:
> 
> type 'a F = A of int | C of 'a * int | X of 'a F * 'a
> 
> Yes, of course you can!
> 
> Its obvious how to do it! 
> 
> There *exists* a universal algorithm in your head
> for writing map functions. But this pattern cannot
> be encoded in Ocaml as an HOF:
> 
> map: 'a 'F -> ('a -> 'b) -> 'b 'F
> 
> You can do this provided you have only types built
> from variants, tuples, and recursion (no function types).
> 
> In fact you could probably write this function
> in camlp4 from the definition of each type
> for which you need a map. 

Not exactly: what you demonstrated here is that you can automatically
build a map function for any type definition with one (or more) type
parameter. And the solution is more or less unique because you
required this map to be polymorphic in the parameter.

I often need to define map for types with no parameters. In that case
the problems is more complex, because there are many possible
definitions for map. You need to understand the semantics of the data
structure to choose.

And most types with parameters have small definitions, so defining map
by hand is not that bad...
(Yes, I know that there is a nice programming pattern involving big
types with parameters, but you cannot do this with normal sum types :-)

Jacques Garrigue

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  reply	other threads:[~2004-09-27  9:41 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-25 21:12 Vasili Galchin
2004-09-25 21:38 ` Nicolas Cannasse
2004-09-25 22:15   ` Vasili Galchin
2004-09-25 22:52     ` Vasili Galchin
2004-09-26  1:34       ` Jon Harrop
2004-09-26  5:31         ` Radu Grigore
2004-09-26  9:47           ` sejourne_kevin
2004-09-26 13:05           ` Jon Harrop
2004-09-26 14:36             ` skaller
2004-09-26 15:08               ` sejourne_kevin
2004-09-26 15:27                 ` skaller
2004-09-26 18:51               ` Jon Harrop
2004-09-26 20:14                 ` Radu Grigore
2004-09-27  1:59                   ` Jon Harrop
2004-09-27  4:48                     ` skaller
2004-09-27  9:40                       ` Jacques GARRIGUE [this message]
2004-09-27 10:50                     ` Radu Grigore
2004-09-27 12:14                       ` skaller
2004-09-27 13:11                       ` Jon Harrop
2004-09-27 13:31                         ` Radu Grigore
2004-09-27 16:54                           ` Jon Harrop
2004-09-29 18:59                             ` Radu Grigore
2004-09-27 13:32                         ` Radu Grigore
2004-09-27 14:04                         ` Brian Hurt
2004-09-27 14:58                           ` skaller
2004-09-27 15:30                             ` Brian Hurt
2004-09-27 16:38                               ` skaller
2004-09-27 17:01                                 ` Brian Hurt
2004-09-28  1:21                                   ` skaller
2004-09-27 16:41                           ` brogoff
2004-09-28  0:26                             ` skaller
2004-09-29 15:32                         ` Florian Hars
2004-09-29 16:49                           ` [Caml-list] Factoring HOFs [was Re: C++ STL...] Jon Harrop
2004-09-30  9:19                             ` Radu Grigore
2004-09-30 10:13                             ` Keith Wansbrough
2004-09-30 10:31                               ` Keith Wansbrough
2004-09-30 13:21                               ` skaller
2004-09-30 23:17                               ` [Caml-list] Factoring HOFs Jacques Garrigue
2004-10-01  8:46                                 ` Keith Wansbrough
2004-10-01 17:35                                 ` brogoff
2004-09-26 20:43                 ` [Caml-list] C++ STL and template features compared with OCaml parametric polymorphism and OO features skaller
2004-09-26 14:19           ` skaller

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=20040927.184051.125125212.garrigue@kurims.kyoto-u.ac.jp \
    --to=garrigue@kurims.kyoto-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=jon@jdh30.plus.com \
    --cc=skaller@users.sourceforge.net \
    /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).