<urz>
where member_variable_hash is passed with new at object creation time
<urz>
but the type of member_variable_hash is parameterized on the class type so its problematic
<urz>
do i have to declare all member functions in one place?
<karryall>
do you really need the class type ?
<karryall>
because something like this should work:
<karryall>
class ['a] baz (i : 'a) = object (self) val v = i method get_v = v method add hash = Hashtbl.add hash v self end
<urz>
is it also impossible to up cast self?
<urz>
i tried to pass super to my hash, heh
mr_bungle has joined #ocaml
<urz>
i want the hash to be part of the object
<urz>
i mean
<urz>
i want the object to know the hash
<urz>
so the caller doesnt have to
<urz>
so i have to pass a pair around now? (hash, obj) ?
<urz>
this seems silly
<urz>
im getting disgusted
<urz>
hello
<urz>
i have a new unrelated question
<Banana>
yes ?
<urz>
Is it okay to modify the hashtable within an iteration of Hashtbl.iter ?
<urz>
i want to delete the item i just visited
<urz>
from the table
<Banana>
i think it's ok...
<urz>
do i have to make a list of items to delete first and iterate over that?
<Banana>
iter is guarantied to see exactly each element once.
<Banana>
so it should be fine.
<urz>
i have doubts
<urz>
what if i was adding elements?
<Banana>
?
<urz>
it'd repeat for ever
<urz>
maybe
<Banana>
how do you add elements while itering ?
<karryall>
urz: no I don't think that's a good idea
<Demitar>
urz, are you really sure you need to downcast your classes?
<Demitar>
s/classes/objects/
Anvil_Vapre has quit [Read error: 60 (Operation timed out)]
<urz>
nevermind, i've given up on that and worked around it
<urz>
i now want a template function like in c++, heh. It creates a new object but the class of the object is a parameter
<urz>
how do i do that?
<Demitar>
When would you use that exactly?
<urz>
well im using it as a macro basically
<urz>
is it not possible?
<karryall>
urz: probably not
<Demitar>
But won't the typing differences make it practically unuseful.
<urz>
oh
<urz>
unuseful how? it would have saved typing
<Demitar>
But where would it save you typing from doing new foo rather than new<foo>?
<Demitar>
(You can of course use any preprocessor you want to do macros.)
<urz>
well it did more than that
<urz>
thats just the problematic part i mentioned
<Demitar>
Add yourself to a hash for downcasting?
<urz>
let cmd =
<urz>
try Hashtbl.find hash msg
<urz>
with Not_found -> new <need class here> msg
<urz>
in
Anvil_Vapre has joined #ocaml
<karryall>
you don't need macros for that, new <a class> is valid functional value
<karryall>
let cmd obj_constructor = try Hashtbl.find hash msg with Not_found -> obj_constructor msg in ...
<Demitar>
Otherwise it couldn't be properly polymorphic anyway, or?
<urz>
and i have to do a (fun x -> new blah msg) when invoke the macro?
<urz>
er
<urz>
well i'd have to use fun ?
<Demitar>
urz, you can make a function for each class let blah_ctor = new blah
<karryall>
(new blah) should be enough
<urz>
oh
<Demitar>
karryall, ah, right. It's a function returning a class..
<urz>
nice, okay
<karryall>
yep
<Demitar>
urz, well in essence the difference would be (cmd<blah> msg) vs (cmd (new blah) msg)
lam has quit ["leaving"]
lam has joined #ocaml
<urz>
um
<urz>
does upcasting need to be explicit?
<Demitar>
Or? :)
<urz>
im getting an error message
<Demitar>
Yes.
* Demitar
personally prefers using modules rather than classes.
<urz>
heh, now i still have the problem that i need to pass a type in order to do the explicit upcast
<urz>
let cmd =
<urz>
try Hashtbl.find hash msg
<urz>
with Not_found -> new <need class here> msg
<urz>
in
<Demitar>
I think you're doing too much evil stuff. :)
<urz>
er
<urz>
thats the wrong paste
<urz>
sorry
<Demitar>
I get the suspicion you're using the wrong tool to archieve whatever you are aiming for.
<Demitar>
Why do you need classes?
<Demitar>
Anything a function with a closure won't handle?
<urz>
i wanted to use inheritence
<urz>
you'd never use classes for anything, am i right?
<urz>
this is the first time i've toyed with them in ocaml
<Demitar>
I would were it the right tool.
<Demitar>
Most of the time it's not though.
<Demitar>
My main reason to use classes would actually be syntactic sugar. :)
<Demitar>
obj#func rather than Module.func obj
<urz>
heh
<Demitar>
But in the end I think the latter has many advantages over using classes.
<urz>
okay
<urz>
well
<Demitar>
(Better type inference being a big one.)
<urz>
i didnt think i was doing something that would be hard to implement with classes
<urz>
i started with non classes and then decided to do the class way on a whim
<urz>
and it put me in ocaml hell
<urz>
might as well take the o off of ocaml, man
<urz>
heh
<Demitar>
Well the thing is that classes in ocaml are by structure and not by name, that's the thing you want to leverage rather than the hierarchy you want to leverage in the case of c++/java/...
<urz>
lets look at my object
<urz>
of the parent class
<karryall>
Demitar: heh, I did a syntax extension once that did this kind of syntactic sugar
<urz>
i have a list of callback functions each of type 'a -> unit
<urz>
i had a variable result that is of type 'a
<urz>
then i had a method get_watch_fors that would return a list of strings representing events that this object is interested in.
<urz>
that is actually fixed for each subclass
<urz>
then it had a method handle which handles one of those events manipulating is result variable and possibly invoking the method complete which calls all the callbacks in the list with the value of result
<Demitar>
Is it perhaps so that you actually want a set rather than a class hierarchy?
<urz>
yeah
<urz>
the heirarchy would be one level deep
<urz>
all from a single root
<Demitar>
That's very frequently the case. :)
<urz>
so lets Modulify this design
<urz>
heh
<urz>
i'll scrap the classes
<urz>
unless you think that ill advised?
<urz>
hm
<Demitar>
I'm no guru. I merely hack OCaml but it sounds like all you need is a list of tuples or a number of functions returning tuples or whatever.
<urz>
the 'a parameter would depend on the subclass by the way
<urz>
so i was actually having a bunch of roots
<urz>
but not because i wanted too really
<urz>
hmm
<urz>
module Handler =
<urz>
struct
<urz>
type t = {
<urz>
mutable callback_list : 'a list;
<urz>
}
<urz>
end
<urz>
i've not done parameterized modules
<karryall>
type 'a t = ...
<Demitar>
How are the different callbacks used since they have type 'a?
<urz>
well i said 'a but i should have said 'a -> unit
<Demitar>
Still, you can only have one of those in any one place.
<Demitar>
one type that is.
<urz>
well the entire module is going to use a single type for 'a
<Demitar>
Anyway, I'm off to eat lunch. Later.
kosmikus is now known as kosmikus|away
Iter has joined #ocaml
wolf|Zzz is now known as wolfman8k
buggs^z has joined #ocaml
buggs has quit [Read error: 110 (Connection timed out)]
cedricshock has joined #ocaml
buggs^z is now known as buggs
mr_bungle has quit [Remote closed the connection]
Iter has quit [calvino.freenode.net irc.freenode.net]
_shawn has quit [calvino.freenode.net irc.freenode.net]
Iter has joined #ocaml
_shawn has joined #ocaml
segphault has joined #ocaml
segphault has quit [Client Quit]
Lemmih has joined #ocaml
urz has quit ["[BX] For a good time, call 1-900-4BitchX"]
noss has joined #ocaml
Iter has quit [Read error: 110 (Connection timed out)]
Nutssh has joined #ocaml
Nutssh has left #ocaml []
maihem has joined #ocaml
Hipo has quit [Read error: 54 (Connection reset by peer)]
Hipo has joined #ocaml
bk_ has joined #ocaml
mattam_ has joined #ocaml
mattam has quit [Read error: 110 (Connection timed out)]
wolfman8k has quit [Read error: 60 (Operation timed out)]
wolfman8k has joined #ocaml
Hipo has quit [Connection timed out]
Hipo has joined #ocaml
Submarine has joined #ocaml
Anvil_Vapre has quit ["Leaving"]
maihem has quit ["Read error: 54 (Connection reset by chocolate)"]
mattam_ is now known as mattam
mrsolo_ has quit [Read error: 60 (Operation timed out)]
noss has quit ["Leaving"]
koa has joined #ocaml
wolfman8k has quit ["Leaving"]
blop_ronan has joined #ocaml
blop_ronan has quit ["L'enfer, c'est les autres."]
p0lartype has quit ["Client Exiting"]
CosmicRay has joined #ocaml
koa has left #ocaml []
truls has joined #ocaml
<truls>
hi folks
<Submarine>
hi
monotonom has joined #ocaml
_shawn has quit [calvino.freenode.net irc.freenode.net]
Smerdyakov has joined #ocaml
_shawn has joined #ocaml
Smerdyakov has quit ["eat"]
mrsolo_ has joined #ocaml
CosmicRay has quit ["Client exiting"]
monotonom has quit ["Don't talk to those who talk to themselves."]