« Return to Thread: [scala] Why are Scala's actors untyped?
Good question. I've often wondered the same thing.FWIW: Sometimes, I want strongly typed Actors. Sometimes I use Actors in the best Unityped way... much like the things I like about Ruby and Python and Smalltalk.
On 8/4/08, Ricky Clarkson <ricky.clarkson@...> wrote:Hi all,
I came across a use case for actors in my Java-only job, so I started thinking about how to go about implementing them for Java (or possibly using Scala's actors as a library, though $bang isn't a great method name). I learned enough of Erlang to be dangerous, then looked at Scala's implementation, to see how it would typically be implemented on the JVM. I was quite surprised to see that Scala's actors' messages are dispatched on through pattern matching - not the usual pattern matching that you can use to take a List, Option or Either to bits, but the kind equivalent to instanceof and casts from Javaland - i.e., BreaksWhenYouChangeStuff(tm).
So I had a quick go and had typed actors working well in Java in a couple of hours, enough to get my job done. Of course, programming for a Javaland project means that certain features seem too leftfield, e.g., using Either, tuples or Option, so in my own time I decided to port my typed actors to less than a screenful of Scala.
Then I had a look at Phillip Haller's tutorial on Scala Actors ( http://lamp.epfl.ch/~phaller/doc/ActorsTutorial.html ), and ported his PingPong example to my library. (Library sounds grandiose for less than a screenful of code, but nevermind). I link here to my version of that example - http://cime.net/~ricky/tmp/PingPong.scala . I tried to keep close to the original, but I found it hard to keep track of using Ping and Pong twice (as a class extending Actor and as a case object representing a message), so I renamed the case objects to PingMessage and PongMessage (and changed them to case classes).
But for the second example, I really have no idea why you would ever use actors to implement synchronous iteration over a tree, so I deleted my half-written port of that until I have fresher eyes. If anyone can explain why that example is useful, please do!
So far though, I'm really unsure why the original library is untyped - if it turns out when I do more interesting things with my version that typing is impossible or too awkward sometimes, it would make sense to route around it, but to have untyping as the default in Scala seems.. odd.
So, please enlighten me - why is it better to have untyped actors than typed actors? If you quote the test case above in your explanation, please don't count Either against it - that can easily be removed.
Here's my working version of the 'library' for typed actors - names copied from scala.actors, laughably small - http://cime.net/~ricky/tmp/Actor.scala . I'm not really sure right now whether Actor should have a result type too (it does in that version) or just a message type.
Cheers,
Ricky.
--
http://erikengbrecht.blogspot.com/
« Return to Thread: [scala] Why are Scala's actors untyped?
| Free embeddable forum powered by Nabble | Forum Help |