pHa has quit ["`halt`"]
fourslice has joined #ocaml
<fourslice> Is there a way to do class introspection to find out what class an object is at runtime?
<fourslice> (Short of making a big disjoint union, I mean)
pHa has joined #ocaml
<fourslice> pHa?
<graydon> afaik ocaml classes aren't given any implicit representation at runtime, beyond storage management and method dispatch.
<graydon> you can always construct an explicit representation, using tags or visitor methods or some such.
<graydon> I think you're basically in the same boat as C++-without-RTTI though.
<fourslice> Ok, thanks
<graydon> I may be wrong about it. I don't use the "objecty" parts of ocaml much
<fourslice> I'm writing a simple pong game to help me learn ocaml, so it's not really that big a thing
<fourslice> But I'm thinking about how it would effect larger games
<fourslice> Is it possible to define types in pieces?
<fourslice> I guess I should just try it
<graydon> in pieces?
<graydon> you can define types, subtypes, modules, functors, and classes. and perhaps some other things. what did you have in mind?
<fourslice> Can you "add on" to a type in after it's first mention in your code
<graydon> in some sense, using subtypes and subclasses, yes.
<fourslice> Hmmm... what exactly is a subtype?
<graydon> oh, sorry, I meant "variants" rather than "subtypes"
<graydon> see the section called "variants" on http://caml.inria.fr/ocaml/htmlman/manual006.html
<fourslice> Oh, yeah, that's what I mean, can you add more... I don't know the word... can you add more "types" to variants as you go?
<graydon> I think the term you want is "type constructors", and yes.
<fourslice> Hmm... where can I find info on that?
<graydon> though only add -- not remove. you can refine a variant type with more variants.
<graydon> did you see the page I pointed to? scroll down to the section on variants.
<fourslice> Yeah, I think that'd be a good way to do class introspection
<graydon> perhaps. you can also just use subclassing though.
<graydon> and visitor methods
<graydon> class introspection"
<fourslice> I don't know if subclassing will help too much, my problem is that when two things collide they are sent as superclasses so I need a way to figure out what hit what
<graydon> hm. I don't see why you need to break encapsulation for that.
<fourslice> Well, hitting different things has different effects, so depending on the thing hit, different stuff has to happen... what would you recommend?
<graydon> either virtualize the behavior (make it a member of the objects affected), or have the object return an object representing their preferred affect, or if you want to disambiguate from outside the objects you can visit them and have them call you back informing you of their type
<graydon> i.e. typical C++ solutions.
<fourslice> Hmm... but if I can add on to variants, I can typecase it and find out what it is in one fell swoop
<fourslice> i can just add on to some variant called "classtype" Foo of foo
<graydon> if you like. I don't see how adding on to them makes them any more useful than a normal sum type, though.
<fourslice> It doesn't, it just makes them easier to read
<fourslice> Since I can add on to it around where the class is
<graydon> I think you're thinking of different things, when you say "add on to it"
<graydon> you define a new type, when you refine a variant.
<graydon> a refined type, which the old one is a subset of, and can be used in place of.
<fourslice> What would be the problem with that?
<graydon> you can't say "type x += Some_New_Constructor"
<graydon> you have to say "type x = 'Some_new_constructor | y"
<graydon> so you're going to keep defining new types. up to you.
<graydon> anyway, I gotta go. wife wants me at home :)
<fourslice> Oh.... thanks for all your help!
<graydon> np. enjoy. look into the normal C++ disambiguation techniques.
graydon has left #ocaml []
fourslice has quit ["Client Exiting"]
pHa has quit [carter.openprojects.net irc.openprojects.net]
pHa has joined #ocaml
teek has joined #ocaml
teek has quit ["[x]chat"]
teek has joined #ocaml
smkl has joined #ocaml
teek has quit ["[x]chat"]
gene9 has joined #ocaml