Browse thread
stl?
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Peng Zang <peng.zang@g...> |
| Subject: | Re: [Caml-list] stl? |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Wednesday 04 March 2009 01:11:18 am Brian Hurt wrote:
> This is another large factor. The three reasons functors aren't used very
> much are because:
> 1) They're a big, scary name,
> 2) They're slightly less efficient,
> 3) There are no good tutorials about how to use them, and
> 4) A fanatical devotion to the pope.
>
> I'll come in again...
Ha! =]
But I'll add one more reason. With functors you have extra overhead like
having to be explicit with what function you're using. In your example when
you want to use Newton's method you always must write "RatioNewton.newtons"
or "FloatNewtons.newtons". The alternative is to functorize the call site,
but (1) that has its own cost: lots of boilerplate functorizing code crowding
the real code and (2) you just defer the explicit naming cost as when that
function is called you'll still have to call either Float version or Ratio
version.
I think objects are much closer to type classes and a much nicer solution.
You can write:
class type ['a] num : object
method add : 'a -> 'a -> 'a
method mul : 'a -> 'a -> 'a
method sub : 'a -> 'a -> 'a
method div : 'a -> 'a -> 'a
method abs : 'a -> 'a -> 'a
end
let rec newtons : ('a #num as 'b) -> ('b -> 'b) -> ('b -> 'b) -> 'b -> 'b
= ...
Peng
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.7 (GNU/Linux)
iD8DBQFJro4RfIRcEFL/JewRAr0MAJ47aFyEvb4yzHOFVqVH/mS8w0TOfgCePNSE
HhVmyyi56RQ8y4gVpICcfXE=
=rz4T
-----END PGP SIGNATURE-----