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 Tuesday 03 March 2009 06:36:52 pm Jon Harrop wrote: > On Tuesday 03 March 2009 22:31:55 Yoann Padioleau wrote: > > Also, a maybe good thing with STL is that you can write a single 'find' > > or 'sort' function that will work for every kind of collections > > (list, arrays, map, hash, etc) by using the > > indirect iterator idiom, without the penalty of dynamic dispatch > > solutions. I am not sure OCaml can do that too. > > OCaml can do that too. Just wrap your code in a functor and parameterize it > over the module implementing the data structure (e.g. List or Array). > Modules and functors are second-class statically resolved constructs in > OCaml so there is no dynamic dispatch. As usual I want to point out the alternative: objects. Eg. you can write a function that takes any object with the "find" method and look for <whatever>. Objects in contrast to functors are dynamically dispatched so they are more flexible but just a little slower (method calls are cached). It also lets you make calls to find without being explict. Eg. instead of List.find or Array.find or Set.Make(String).find, you can just do #find. Peng -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.7 (GNU/Linux) iD8DBQFJrcfEfIRcEFL/JewRAsEzAKCfu/LbvuvPVDCCsOI8Kmi8cfHtTwCfZfEX ffjw1sTrYzJHbr0d8QQuaQw= =yXcr -----END PGP SIGNATURE-----