1 Apr 2004 06:00
Re: examples of heterogenous collections (containers ?)
<briand <at> aracnet.com>
2004-04-01 04:00:07 GMT
2004-04-01 04:00:07 GMT
>>>>> "skaller" == skaller <skaller <at> users.sourceforge.net> writes: skaller> You are thinking about this problem *backwards*! :) Well that's why it's giving me so much trouble.(Continue reading)skaller> The cast will always work if the object has a method named skaller> 'f' which when invoked with no arguments returns unit. skaller> Obviously, because Ocaml is wonderful, your cast will fail skaller> on objects without a suitable 'f' method. I LIKE IT. No inheritance required. Objects which have the same method with the same signature work "automagically". skaller> The solution is to use a factory function in a single skaller> module, and return an abstraction of the class type you skaller> wish to deal with. I'm not sure I followed that, can you expand ? For future readers of the list here and appropriate example. It turns out I was silly and never even bothered to look in the _manual_ of all places. I looked everywhere else. This is covered in the section called "Using Coercions", go figure. Anyway, enough blather, here's the example : class elt = object method f x = 2 * x end
skaller> The cast will always work if the object has a method named
skaller> 'f' which when invoked with no arguments returns unit.
skaller> Obviously, because Ocaml is wonderful, your cast will fail
skaller> on objects without a suitable 'f' method.
I LIKE IT. No inheritance required. Objects which have the same
method with the same signature work "automagically".
skaller> The solution is to use a factory function in a single
skaller> module, and return an abstraction of the class type you
skaller> wish to deal with.
I'm not sure I followed that, can you expand ?
For future readers of the list here and appropriate example. It turns
out I was silly and never even bothered to look in the _manual_ of all
places. I looked everywhere else. This is covered in the section
called "Using Coercions", go figure.
Anyway, enough blather, here's the example :
class elt = object
method f x = 2 * x
end
RSS Feed