From: Martin Jambon <martin_jambon@emailuser.net>
To: Jon Harrop <jdh30@cam.ac.uk>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Functors
Date: Sun, 2 May 2004 18:24:15 +0800 (HKT) [thread overview]
Message-ID: <Pine.LNX.4.44.0405021727120.1794-100000@localhost> (raw)
In-Reply-To: <200405021012.28011.jdh30@cam.ac.uk>
On Sun, 2 May 2004, Jon Harrop wrote:
> Could Set (and others) be implemented polymorphically by using a comparison
> function passed as an argument?
>
> If so, what would be the implications of this approach? I think: you couldn't
> use the type checker to enforce consistent comparison functions between two
> different sets which were, say, being merged. I think you can enforce this
> using the functor approach provided the Sets came from the same functor
> "instantiation".
With my words: I understand functors as a way to parametrize a type with a
value.
They allow you to detect inconsistencies at compile time (e.g. 2 sets
parametrized with different "compare" functions).
Without functors, as far as I know, you can only test inconsistencies at
run time (e.g. by putting all the parameters in a record an check physical
equality of the records).
> Functors appear to be somewhat similar to templates in C++. Does the functor
> approach produce more efficient code as it is partially specialised over the
> comparison function?
Unfortunately no.
Julien Signoles wrote a defunctorizer (works from the source code of the
functor):
http://www.lri.fr/~signoles/ocamldefun/manual.html
Maybe some user manual should tell us more about when to use functors
rather than just how to use them.
Martin
-------------------
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
next prev parent reply other threads:[~2004-05-02 10:24 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-05-02 9:12 Jon Harrop
2004-05-02 10:24 ` Martin Jambon [this message]
2004-05-02 13:34 ` Jon Harrop
2004-05-02 14:12 ` skaller
2004-05-02 16:49 ` Jon Harrop
2004-05-03 0:20 ` skaller
2004-05-03 14:43 ` Jacques Carette
2004-05-03 16:09 ` Alain.Frisch
2004-05-03 18:53 ` Jacques Carette
2004-05-03 19:17 ` [Caml-list] Mathematica Jon Harrop
2004-05-03 22:51 ` [Caml-list] Functors Alain.Frisch
2004-05-03 16:02 ` Julien Signoles
2004-05-03 18:41 ` Jon Harrop
2004-05-04 7:25 ` Jean-Christophe Filliatre
2004-05-05 8:15 ` Julien Signoles
2004-05-05 20:41 ` brogoff
2004-05-06 11:16 ` Jon Harrop
2004-05-06 20:23 ` Alain.Frisch
2004-05-06 18:26 ` Olivier Grisel
2004-05-06 12:26 ` Julien Signoles
2004-05-06 16:35 ` brogoff
2004-05-02 17:18 ` David Brown
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=Pine.LNX.4.44.0405021727120.1794-100000@localhost \
--to=martin_jambon@emailuser.net \
--cc=caml-list@inria.fr \
--cc=jdh30@cam.ac.uk \
/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