- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Actors and typing
Tue, 2010-07-06, 18:32
Hi, I'm still new to both: Actors and Scala.
Is my understand correct that an Actor is kind of object I can throw a
message at which may or may not send back a reply?
Well that's fine. But why can't I restrict the type of messages which I
can throw at an actor or which an Actor will return?
Eg it would be no problem to define an Actor like this, would it?
class myActor extends Actor[ExpectedInput, OutputType] {
..
}
You can still use [Any,Any] if you want to allow everything, can't you?
Is there something I've missed?
eg when changing the return type from String to Either[Error, String] I
want my code to break at compile time.
Do other Actor implementations exist which provide this kind of static
checking?
Marc Weber
Tue, 2010-07-06, 19:17
#2
Re: Actors and typing
trait AbstractActor extends OutputChannel[Any] with CanReply[Any, Any]
... you might be able to back your own typed actors from OutputChannel / CanReply / InputChannel and such ... not sure how feasible this is, though ...
also there is in Actor
def !: Future[A]
so you can create a helper method using the resulting future's inputChannel (which is typed) to create like a typed !? method....
best, -sciss-
Am 06.07.2010 um 18:32 schrieb Marc Weber:
> Hi, I'm still new to both: Actors and Scala.
>
> Is my understand correct that an Actor is kind of object I can throw a
> message at which may or may not send back a reply?
>
> Well that's fine. But why can't I restrict the type of messages which I
> can throw at an actor or which an Actor will return?
>
> Eg it would be no problem to define an Actor like this, would it?
>
> class myActor extends Actor[ExpectedInput, OutputType] {
> ..
> }
>
> You can still use [Any,Any] if you want to allow everything, can't you?
>
> Is there something I've missed?
>
> eg when changing the return type from String to Either[Error, String] I
> want my code to break at compile time.
>
> Do other Actor implementations exist which provide this kind of static
> checking?
>
> Marc Weber
Tue, 2010-07-06, 22:17
#3
Re: Actors and typing
Hi Marc,
On 07/06/2010 07:32 PM, Marc Weber wrote:
> Is my understand correct that an Actor is kind of object I can throw a
> message at which may or may not send back a reply?
>
> Well that's fine. But why can't I restrict the type of messages which I
> can throw at an actor or which an Actor will return?
The following thread discusses this:
http://article.gmane.org/gmane.comp.lang.scala/12988
The bottom line is that both the dynamically-scoped `self` as well as
`receiveWithin`/`reactWithin` cause problems with typed actors.
However, note that the `Reactor` trait (new in Scala 2.8) is
parameterized in the type of messages is accepts. Consequently,
`Reactor` neither supports `self` nor `reactWithin`.
> Do other Actor implementations exist which provide this kind of static
> checking?
You may be interested in a blog post by Josh Suereth that explains how
to use channels and partial functions to build input- and output-typed
instances of `scala.actors.Actor`:
http://suereth.blogspot.com/2010/02/actor-styles-oo-functional-or-blende...
However, in this case the behavior of an actor is defined by a partial
function that should not use `self` or `receiveWithin`.
Cheers,
Philipp
On Tue, Jul 6, 2010 at 10:32 AM, Marc Weber <marco-oweber@gmx.de> wrote:
Lift has Actors that can be typed for message receipts.
Stambecco (built on Lift Actors) supports typed messages and typed messages with typed responses.
--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Blog: http://goodstuff.im
Surf the harmonics