- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
please help: I think I knotted my brain into a loop!
Sat, 2012-02-18, 22:56
I should probably just go to sleep and dream it up, but this has got me puzzled: in an actor, I would like to have a “var” which holds an Option[Function1[_, _]] which is applied to each incoming message to obtain the function for the next message. While I can describe it easily in words, and also imagine how the code shall look like (autopilot = autopilot flatMap (_(msg))), I cannot figure out what the actual type should be to make this compile. Since the type system is Turing complete, there must be a way, but how do I create a recursive type?
Regards,
Roland
Regards,
Roland
Sat, 2012-02-18, 23:41
#2
Re: please help: I think I knotted my brain into a loop!
Am Samstag, 18. Februar 2012 23:19:52 UTC+1 schrieb √iktor Klang:
Ah, you mean I should not aim to make it a Function1. Yes, that would work, although it makes it more verbose for the client code (no nice function literal, instead an anonymous class with a single method).
On Sat, Feb 18, 2012 at 10:56 PM, rkuhn <google@rkuhn.info> wrote:I should probably just go to sleep and dream it up, but this has got me puzzled: in an actor, I would like to have a “var” which holds an Option[Function1[_, _]] which is applied to each incoming message to obtain the function for the next message. While I can describe it easily in words, and also imagine how the code shall look like (autopilot = autopilot flatMap (_(msg))), I cannot figure out what the actual type should be to make this compile. Since the type system is Turing complete, there must be a way, but how do I create a recursive type?
You can express it with a trait. I've tinkered with this in my pursuit to implement actors on top of Iteratees.
Regards,
Roland
On Sat, Feb 18, 2012 at 10:56 PM, rkuhn <google@rkuhn.info> wrote:
You can express it with a trait. I've tinkered with this in my pursuit to implement actors on top of Iteratees.
Cheers,√
--
Viktor Klang
Akka Tech LeadTypesafe - The software stack for applications that scale
Twitter: @viktorklang