Background: At work we have a big C++ project. I just added a new object, and now $boss asked me to add the send/receive interface. These two methods allow an object to be serialized to and from a stream. Essentially it means
// superclass methods for core types sendInt(int_member); sendString(string_member); // all object members need to also inherit Serializable obj->send(socket); and receiveInt(int_member); receiveString(string_member); obj = new Object(); obj->receive(socket); etc for each member, in the right order with the right type. This is a dump example since we just do .perl, but let's say pretend for a moment that we don't. Perl 6 has some advantages over C++ that make this trivial (or so I hope): * a meta model (iterate attributes, know their type, etc) * roles (no need to inherit Serializable, this is a bit cleaner) * attitude (this is up for discussion ;-) I'd like to be able to declare my serializable role as a univeral role. This basicaally means: role Serializable { method send ( Stream $fh ) { # iterate all attrs my Serializable $attr = $?SELF.meta.get_attr; ... } method receive ( Stream $fh ) { # iterate all attrs ... } } # core types Num does Serializable { method send ( Stream $fh ) { $fh.print( "$?SELF" ); } } and then to never say that any class does it. Instead, i'd like to have a duck typing like approach: my Serializable $x = Monkey.new(); # or my $x = Monkey.new but Serializable; # and then $x.send( $socket ); # no ambiguity And then I'd like to have these features: * Have type inferrencing type check the send and receive methods * have it automatically infer that all the attrs of Monkey are also Serializable, due to the fact that send iterates them and declares that * get nice errors that tell me that Moneky can't be Serializable because the member $stream deep inside an object within Monkey (for example, if Anus has Stream ;-) is not Serializable, nor can the Serializable role be automatically applied to it because it has opaque internals. This probably makes more sense for other interfaces. This also reminds me a bit of attribute grammars - i'd like to be able to automatically derive node roles inside AGs by just specifying a generic universal behavior, and behavior for the leaves. Err, comments please =) -- () Yuval Kogman <[EMAIL PROTECTED]> 0xEBD27418 perl hacker & /\ kung foo master: MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM: neeyah!
pgpj8V2131aFs.pgp
Description: PGP signature