Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Peng Zang <peng.zang@gmail.com>
To: caml-list@yquem.inria.fr
Cc: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
Subject: Re: [Caml-list] typeclasses in OCaml
Date: Sat, 23 Aug 2008 08:50:22 -0400	[thread overview]
Message-ID: <200808230850.27191.peng.zang@gmail.com> (raw)
In-Reply-To: <20080823.115753.85827777.garrigue@math.nagoya-u.ac.jp>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Friday 22 August 2008 10:57:53 pm Jacques Garrigue wrote:
> There is no way to specify "a 'z version of 'self", and this is the
> reason you cannot do this in ocaml.
>
> Even if you don't require structural polymorphism for your object type
> (which you need here, since you want to write #mappable), there are
> other difficulties related to recursive types having to be regular.
>
> A classical workaround is to define map as a function using #fold and
> cons:
>
> let map cons f (o : 'a #foldable) =
>   o#fold (fun x o' -> cons (f x) o')
>
> Note that for this to work you need #fold to be the correct fold
> (i.e. fold_right)
>
> Hope this helps,
>
> Jacques Garrigue


Yes this has been very helpful.  It's good to know I'm not just missing 
something.  I will use your workaround instead.  It makes perfect sense.  
There is nothing inherently special about mappable.  It is just a container 
that we can access the elements of (that's #foldable) and that has a 
constructor.  Thanks,

Peng
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.7 (GNU/Linux)

iD8DBQFIsAeTfIRcEFL/JewRApXnAKDTDuq97Dfe7/WcIVtFLWfqUeb56QCeKcla
a61KJh5dWEnQmHwalusb0Mo=
=lP8V
-----END PGP SIGNATURE-----


      reply	other threads:[~2008-08-23 12:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-22 12:54 Peng Zang
2008-08-23  2:57 ` [Caml-list] " Jacques Garrigue
2008-08-23 12:50   ` Peng Zang [this message]

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=200808230850.27191.peng.zang@gmail.com \
    --to=peng.zang@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=garrigue@math.nagoya-u.ac.jp \
    /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