From: skaller <skaller@users.sourceforge.net>
To: Andrej.Bauer@andrej.com
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] map and fold
Date: Sun, 24 Dec 2006 14:42:14 +1100 [thread overview]
Message-ID: <1166931734.25424.41.camel@rosella.wigram> (raw)
In-Reply-To: <458DC1BC.5090802@fmf.uni-lj.si>
On Sun, 2006-12-24 at 00:54 +0100, Andrej Bauer wrote:
> skaller wrote:
> Furthermore if t is inductively defined, we can express map in terms of
> fold. Examples:
>
> 1) Lists:
>
> type 'a list = Nil | Cons of 'a * 'a list
>
> let map f = fold Nil (fun u _ x -> Cons (f u, x))
>
> 2) Trees:
>
> type 'a tree = Empty | Node of 'a * 'a tree * 'a tree
>
> let map f = fold Empty (fun u _ _ x y -> Node (f u, x, y))
However in Ocaml at least you cannot actually write a single
definition for map in terms of a single fold -- you have to
write out fold for each data type, and worse, even given that
you still need to write out map for each data type too,
following an idiomatic pattern.
How could Ocaml be extended to get rid of this unsafe
verbosity?
Even if the resulting generic operators weren't first class,
it would still be useful to define 'map' once and be done
with it.
--
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net
next prev parent reply other threads:[~2006-12-24 3:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-12-22 11:18 skaller
2006-12-22 12:12 ` [Caml-list] " Florian Hars
2006-12-23 23:54 ` Andrej Bauer
2006-12-24 3:26 ` skaller
2006-12-24 3:42 ` skaller [this message]
2006-12-24 11:00 ` Tom
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=1166931734.25424.41.camel@rosella.wigram \
--to=skaller@users.sourceforge.net \
--cc=Andrej.Bauer@andrej.com \
--cc=caml-list@yquem.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