This page is no longer maintained — Please continue to the home page at www.scala-lang.org

please help: I think I knotted my brain into a loop!

2 replies
roland.kuhn
Joined: 2011-02-21,
User offline. Last seen 35 weeks 3 days ago.
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
Viktor Klang
Joined: 2008-12-17,
User offline. Last seen 1 year 27 weeks ago.
Re: please help: I think I knotted my brain into a loop!


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.
Cheers,√ 

Regards,

Roland



--
Viktor Klang

Akka Tech LeadTypesafe - The software stack for applications that scale

Twitter: @viktorklang
roland.kuhn
Joined: 2011-02-21,
User offline. Last seen 35 weeks 3 days ago.
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:


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.
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).

Regards,

Roland

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland