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

Why no call-by-name constructor parameter in case class allowed?

16 replies
DaveScala
Joined: 2011-03-18,
User offline. Last seen 1 year 21 weeks ago.

scala> case class Message(code: => Unit)
:1: error: `val' parameters may not be call-by-name
case class Message(code: => Unit)
^

scala> case class Message(code: () => Unit)
defined class Message

Why is it not allowed to have a call-by-name parameter in the
constructor of a case class?

DaveScala
Joined: 2011-03-18,
User offline. Last seen 1 year 21 weeks ago.
Re: Why no call-by-name constructor parameter in case class allo

In normal classes it is allowed:

scala> class Message2(code: => Unit)
defined class Message2

scala> class Message2(code: () => Unit)
defined class Message2

On 6 feb, 18:37, Dave wrote:
> scala> case class Message(code: => Unit)
> :1: error: `val' parameters may not be call-by-name
>        case class Message(code: => Unit)
>                                 ^
>
> scala> case class Message(code: () => Unit)
> defined class Message
>
> Why is it not allowed to have a call-by-name parameter in the
> constructor of  a case class?

Viktor Klang
Joined: 2008-12-17,
User offline. Last seen 1 year 27 weeks ago.
Re: Re: Why no call-by-name constructor parameter in case class
Apples to apples:
Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_24).Type in expressions to have them evaluated.Type :help for more information.
scala>  class Message2(code: => Unit)defined class Message2
scala>  class Message2(val code: => Unit)<console>:1: error: `val' parameters may not be call-by-name         class Message2(val code: => Unit)
On Mon, Feb 6, 2012 at 6:45 PM, Dave <dave [dot] mahabiersing [at] hotmail [dot] com> wrote:
In normal classes it is allowed:

scala> class Message2(code: => Unit)
defined class Message2

scala> class Message2(code: () => Unit)
defined class Message2


On 6 feb, 18:37, Dave <dave [dot] mahabiers [dot] [dot] [dot] [at] hotmail [dot] com> wrote:
> scala> case class Message(code: => Unit)
> <console>:1: error: `val' parameters may not be call-by-name
>        case class Message(code: => Unit)
>                                 ^
>
> scala> case class Message(code: () => Unit)
> defined class Message
>
> Why is it not allowed to have a call-by-name parameter in the
> constructor of  a case class?



--
Viktor Klang

Akka Tech LeadTypesafe - The software stack for applications that scale

Twitter: @viktorklang
DaveScala
Joined: 2011-03-18,
User offline. Last seen 1 year 21 weeks ago.
Re: Why no call-by-name constructor parameter in case class allo

Ha okay, but why is call-by-name not allowed for val?

On 6 feb, 18:49, √iktor Ҡlang wrote:
> Apples to apples:
>
> Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM,
> Java 1.6.0_24).
> Type in expressions to have them evaluated.
> Type :help for more information.
>
> scala>  class Message2(code: => Unit)
> defined class Message2
>
> scala>  class Message2(val code: => Unit)
> :1: error: `val' parameters may not be call-by-name
>         class Message2(val code: => Unit)
>
>
>
>
>
> On Mon, Feb 6, 2012 at 6:45 PM, Dave wrote:
> > In normal classes it is allowed:
>
> > scala> class Message2(code: => Unit)
> > defined class Message2
>
> > scala> class Message2(code: () => Unit)
> > defined class Message2
>
> > On 6 feb, 18:37, Dave wrote:
> > > scala> case class Message(code: => Unit)
> > > :1: error: `val' parameters may not be call-by-name
> > >        case class Message(code: => Unit)
> > >                                 ^
>
> > > scala> case class Message(code: () => Unit)
> > > defined class Message
>
> > > Why is it not allowed to have a call-by-name parameter in the
> > > constructor of  a case class?
>
> --
> Viktor Klang
>
> Akka Tech Lead
> Typesafe - The software stack for applications
> that scale
>
> Twitter: @viktorklang- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -

Viktor Klang
Joined: 2008-12-17,
User offline. Last seen 1 year 27 weeks ago.
Re: Re: Why no call-by-name constructor parameter in case class


On Mon, Feb 6, 2012 at 7:13 PM, Dave <dave [dot] mahabiersing [at] hotmail [dot] com> wrote:
Ha okay, but why is call-by-name not allowed for val?


What would it mean? 

On 6 feb, 18:49, √iktor Ҡlang <viktor [dot] kl [dot] [dot] [dot] [at] gmail [dot] com> wrote:
> Apples to apples:
>
> Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM,
> Java 1.6.0_24).
> Type in expressions to have them evaluated.
> Type :help for more information.
>
> scala>  class Message2(code: => Unit)
> defined class Message2
>
> scala>  class Message2(val code: => Unit)
> <console>:1: error: `val' parameters may not be call-by-name
>         class Message2(val code: => Unit)
>
>
>
>
>
> On Mon, Feb 6, 2012 at 6:45 PM, Dave <dave [dot] mahabiers [dot] [dot] [dot] [at] hotmail [dot] com> wrote:
> > In normal classes it is allowed:
>
> > scala> class Message2(code: => Unit)
> > defined class Message2
>
> > scala> class Message2(code: () => Unit)
> > defined class Message2
>
> > On 6 feb, 18:37, Dave <dave [dot] mahabiers [dot] [dot] [dot] [at] hotmail [dot] com> wrote:
> > > scala> case class Message(code: => Unit)
> > > <console>:1: error: `val' parameters may not be call-by-name
> > >        case class Message(code: => Unit)
> > >                                 ^
>
> > > scala> case class Message(code: () => Unit)
> > > defined class Message
>
> > > Why is it not allowed to have a call-by-name parameter in the
> > > constructor of  a case class?
>
> --
> Viktor Klang
>
> Akka Tech Lead
> Typesafe <http://www.typesafe.com/> - The software stack for applications
> that scale
>
> Twitter: @viktorklang- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -



--
Viktor Klang

Akka Tech LeadTypesafe - The software stack for applications that scale

Twitter: @viktorklang
DaveScala
Joined: 2011-03-18,
User offline. Last seen 1 year 21 weeks ago.
Re: Why no call-by-name constructor parameter in case class allo

It is actually only that I like to write
Message(println("hello"))
instead of
Message(() => println("hello"))

On 6 feb, 19:15, √iktor Ҡlang wrote:
> On Mon, Feb 6, 2012 at 7:13 PM, Dave wrote:
> > Ha okay, but why is call-by-name not allowed for val?
>
> What would it mean?
>
>
>
>
>
>
>
> > On 6 feb, 18:49, √iktor Ҡlang wrote:
> > > Apples to apples:
>
> > > Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM,
> > > Java 1.6.0_24).
> > > Type in expressions to have them evaluated.
> > > Type :help for more information.
>
> > > scala>  class Message2(code: => Unit)
> > > defined class Message2
>
> > > scala>  class Message2(val code: => Unit)
> > > :1: error: `val' parameters may not be call-by-name
> > >         class Message2(val code: => Unit)
>
> > > On Mon, Feb 6, 2012 at 6:45 PM, Dave
> > wrote:
> > > > In normal classes it is allowed:
>
> > > > scala> class Message2(code: => Unit)
> > > > defined class Message2
>
> > > > scala> class Message2(code: () => Unit)
> > > > defined class Message2
>
> > > > On 6 feb, 18:37, Dave wrote:
> > > > > scala> case class Message(code: => Unit)
> > > > > :1: error: `val' parameters may not be call-by-name
> > > > >        case class Message(code: => Unit)
> > > > >                                 ^
>
> > > > > scala> case class Message(code: () => Unit)
> > > > > defined class Message
>
> > > > > Why is it not allowed to have a call-by-name parameter in the
> > > > > constructor of  a case class?
>
> > > --
> > > Viktor Klang
>
> > > Akka Tech Lead
> > > Typesafe - The software stack for
> > applications
> > > that scale
>
> > > Twitter: @viktorklang- Tekst uit oorspronkelijk bericht niet weergeven -
>
> > > - Tekst uit oorspronkelijk bericht weergeven -
>
> --
> Viktor Klang
>
> Akka Tech Lead
> Typesafe - The software stack for applications
> that scale
>
> Twitter: @viktorklang- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -

d_m
Joined: 2010-11-11,
User offline. Last seen 35 weeks 2 days ago.
Re: Re: Why no call-by-name constructor parameter in case class

On Mon, Feb 06, 2012 at 10:13:32AM -0800, Dave wrote:
> Ha okay, but why is call-by-name not allowed for val?

Here's an interpreter session that shows the two possible options. The
Eager class seems pointless to me, and the Lazy class might be want you
want but is obviously not compatible with case classes (which use val
and not lazy val).

Welcome to Scala version 2.9.0.1 (Java HotSpot(TM) 64-Bit Server VM,
Java 1.6.0_26).
Type in expressions to have them evaluated.
Type :help for more information.

scala> def get9 = { println("nine"); 9 }
get9: Int

scala> class Eager(x: => Int) { val y = x }
defined class Eager

scala> class Lazy(x: => Int) { lazy val y = x }
defined class Lazy

scala> val e = new Eager(get9)
nine
e: Eager = Eager@58a40787

scala> e.y
res0: Int = 9

scala> val l = new Lazy(get9)
l: Lazy = Lazy@4dbed348

scala> l.y
nine
res1: Int = 9

Viktor Klang
Joined: 2008-12-17,
User offline. Last seen 1 year 27 weeks ago.
Re: Re: Why no call-by-name constructor parameter in case class


On Mon, Feb 6, 2012 at 7:29 PM, Dave <dave [dot] mahabiersing [at] hotmail [dot] com> wrote:
It is actually only that I  like to write
Message(println("hello"))
instead of
Message(() => println("hello"))

Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_24).Type in expressions to have them evaluated. Type :help for more information.
scala> :paste// Entering paste mode (ctrl-D to finish)
object Message { def apply(f: => Unit) = new Message(() => f) } class Message(val f: () => Unit)
// Exiting paste mode, now interpreting.
defined module Messagedefined class Message
scala> Message(println("pigdog")) res0: Message = Message@f0de2bd
scala> res0.fres1: () => Unit = <function0> 




On 6 feb, 19:15, √iktor Ҡlang <viktor [dot] kl [dot] [dot] [dot] [at] gmail [dot] com> wrote:
> On Mon, Feb 6, 2012 at 7:13 PM, Dave <dave [dot] mahabiers [dot] [dot] [dot] [at] hotmail [dot] com> wrote:
> > Ha okay, but why is call-by-name not allowed for val?
>
> What would it mean?
>
>
>
>
>
>
>
> > On 6 feb, 18:49, √iktor Ҡlang <viktor [dot] kl [dot] [dot] [dot] [at] gmail [dot] com> wrote:
> > > Apples to apples:
>
> > > Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM,
> > > Java 1.6.0_24).
> > > Type in expressions to have them evaluated.
> > > Type :help for more information.
>
> > > scala>  class Message2(code: => Unit)
> > > defined class Message2
>
> > > scala>  class Message2(val code: => Unit)
> > > <console>:1: error: `val' parameters may not be call-by-name
> > >         class Message2(val code: => Unit)
>
> > > On Mon, Feb 6, 2012 at 6:45 PM, Dave <dave [dot] mahabiers [dot] [dot] [dot] [at] hotmail [dot] com>
> > wrote:
> > > > In normal classes it is allowed:
>
> > > > scala> class Message2(code: => Unit)
> > > > defined class Message2
>
> > > > scala> class Message2(code: () => Unit)
> > > > defined class Message2
>
> > > > On 6 feb, 18:37, Dave <dave [dot] mahabiers [dot] [dot] [dot] [at] hotmail [dot] com> wrote:
> > > > > scala> case class Message(code: => Unit)
> > > > > <console>:1: error: `val' parameters may not be call-by-name
> > > > >        case class Message(code: => Unit)
> > > > >                                 ^
>
> > > > > scala> case class Message(code: () => Unit)
> > > > > defined class Message
>
> > > > > Why is it not allowed to have a call-by-name parameter in the
> > > > > constructor of  a case class?
>
> > > --
> > > Viktor Klang
>
> > > Akka Tech Lead
> > > Typesafe <http://www.typesafe.com/> - The software stack for
> > applications
> > > that scale
>
> > > Twitter: @viktorklang- Tekst uit oorspronkelijk bericht niet weergeven -
>
> > > - Tekst uit oorspronkelijk bericht weergeven -
>
> --
> Viktor Klang
>
> Akka Tech Lead
> Typesafe <http://www.typesafe.com/> - The software stack for applications
> that scale
>
> Twitter: @viktorklang- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -



--
Viktor Klang

Akka Tech LeadTypesafe - The software stack for applications that scale

Twitter: @viktorklang
Derek Williams 3
Joined: 2011-08-12,
User offline. Last seen 42 years 45 weeks ago.
Re: Re: Why no call-by-name constructor parameter in case class

A third option could be accessing it with a def, so it is evaluated each time it is accessed.

On Feb 6, 2012 11:24 AM, "Erik Osheim" <erik [at] plastic-idolatry [dot] com> wrote:
On Mon, Feb 06, 2012 at 10:13:32AM -0800, Dave wrote:
> Ha okay, but why is call-by-name not allowed for val?

Here's an interpreter session that shows the two possible options. The
Eager class seems pointless to me, and the Lazy class might be want you
want but is obviously not compatible with case classes (which use val
and not lazy val).


Welcome to Scala version 2.9.0.1 (Java HotSpot(TM) 64-Bit Server VM,
Java 1.6.0_26).
Type in expressions to have them evaluated.
Type :help for more information.

scala> def get9 = { println("nine"); 9 }
get9: Int

scala> class Eager(x: => Int) { val y = x }
defined class Eager

scala> class Lazy(x: => Int) { lazy val y = x }
defined class Lazy

scala> val e = new Eager(get9)
nine
e: Eager = Eager@58a40787

scala> e.y
res0: Int = 9

scala> val l = new Lazy(get9)
l: Lazy = Lazy@4dbed348

scala> l.y
nine
res1: Int = 9
DaveScala
Joined: 2011-03-18,
User offline. Last seen 1 year 21 weeks ago.
Re: Why no call-by-name constructor parameter in case class allo

Thanks all

Only Message is a case class which makes it problematic:

scala> :paste
// Entering paste mode (ctrl-D to finish)

case object Message { def apply(code: => Unit) = new Message(() =>
code) }
case class Message(code: () => Unit)

// Exiting paste mode, now interpreting.

:9: error: double definition:
method apply:(code: () => Unit)Message and
method apply:(code: => Unit)Message at line 8
have same type after erasure: (code: Function0)Message
case class Message(code: () => Unit)
^

Stefan Zeiger
Joined: 2008-12-21,
User offline. Last seen 27 weeks 3 days ago.
Re: Re: Why no call-by-name constructor parameter in case class

On 2012-02-06 19:13, Dave wrote:
> Ha okay, but why is call-by-name not allowed for val?

A val with call-by-name is a def. Since Scala does not guarantee
immutability, evaluating an expression multiple times may lead to
different values, which is not acceptable for stable identifiers like
vals. The closest you can get is a "lazy val". You cannot use that in a
case class constructor but I can't think of a good reason why it's
disallowed (other than that it wouldn't be very useful -- all of the
interesting case class features would need to force evaluation).

-sz

Naftoli Gugenheim
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Why no call-by-name constructor parameter in case class allowed?
Why does Message have to be a case class?

On Monday, February 6, 2012, Dave wrote:
Thanks all

Only Message is a case class which makes it problematic:

scala> :paste
// Entering paste mode (ctrl-D to finish)

case object Message { def apply(code: => Unit) = new Message(() =>
code) }
case class Message(code: () => Unit)

// Exiting paste mode, now interpreting.

<console>:9: error: double definition:
method apply:(code: () => Unit)Message and
method apply:(code: => Unit)Message at line 8
have same type after erasure: (code: Function0)Message
      case class Message(code: () => Unit)
                 ^
DaveScala
Joined: 2011-03-18,
User offline. Last seen 1 year 21 weeks ago.
Re: Why no call-by-name constructor parameter in case class allo

Because it is sent and received by actors so for the pattern matching
in the receive mailbox.

On 9 feb, 03:52, Naftoli Gugenheim wrote:
> Why does Message have to be a case class?
>
>
>
> On Monday, February 6, 2012, Dave wrote:
> > Thanks all
>
> > Only Message is a case class which makes it problematic:
>
> > scala> :paste
> > // Entering paste mode (ctrl-D to finish)
>
> > case object Message { def apply(code: => Unit) = new Message(() =>
> > code) }
> > case class Message(code: () => Unit)
>
> > // Exiting paste mode, now interpreting.
>
> > :9: error: double definition:
> > method apply:(code: () => Unit)Message and
> > method apply:(code: => Unit)Message at line 8
> > have same type after erasure: (code: Function0)Message
> >       case class Message(code: () => Unit)
> >                  ^- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -

Joshua.Suereth
Joined: 2008-09-02,
User offline. Last seen 32 weeks 5 days ago.
Re: Re: Why no call-by-name constructor parameter in case class

Be careful sending closures between jvms.   You may have to make a whole lot of your classes serializable and maintain friendly serialization over time.

On Feb 9, 2012 7:36 AM, "Dave" <dave [dot] mahabiersing [at] hotmail [dot] com> wrote:
Because it is sent and received by actors so for the pattern matching
in the receive mailbox.

On 9 feb, 03:52, Naftoli Gugenheim <naftoli [dot] [dot] [dot] [at] gmail [dot] com> wrote:
> Why does Message have to be a case class?
>
>
>
> On Monday, February 6, 2012, Dave wrote:
> > Thanks all
>
> > Only Message is a case class which makes it problematic:
>
> > scala> :paste
> > // Entering paste mode (ctrl-D to finish)
>
> > case object Message { def apply(code: => Unit) = new Message(() =>
> > code) }
> > case class Message(code: () => Unit)
>
> > // Exiting paste mode, now interpreting.
>
> > <console>:9: error: double definition:
> > method apply:(code: () => Unit)Message and
> > method apply:(code: => Unit)Message at line 8
> > have same type after erasure: (code: Function0)Message
> >       case class Message(code: () => Unit)
> >                  ^- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -
Naftoli Gugenheim
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Re: Re: Why no call-by-name constructor parameter in case class
So you have to expand on Victor's code a drop:
object Message { def apply(f: => Unit) = new Message(() => f) def unapply(m: Message): Option[()=>Unit] = Some(m.f) // IIRC, or something similar }class Message(val f: () => Unit)

On Thu, Feb 9, 2012 at 7:36 AM, Dave <dave [dot] mahabiersing [at] hotmail [dot] com> wrote:
Because it is sent and received by actors so for the pattern matching
in the receive mailbox.

On 9 feb, 03:52, Naftoli Gugenheim <naftoli [dot] [dot] [dot] [at] gmail [dot] com> wrote:
> Why does Message have to be a case class?
>
>
>
> On Monday, February 6, 2012, Dave wrote:
> > Thanks all
>
> > Only Message is a case class which makes it problematic:
>
> > scala> :paste
> > // Entering paste mode (ctrl-D to finish)
>
> > case object Message { def apply(code: => Unit) = new Message(() =>
> > code) }
> > case class Message(code: () => Unit)
>
> > // Exiting paste mode, now interpreting.
>
> > <console>:9: error: double definition:
> > method apply:(code: () => Unit)Message and
> > method apply:(code: => Unit)Message at line 8
> > have same type after erasure: (code: Function0)Message
> >       case class Message(code: () => Unit)
> >                  ^- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -

DaveScala
Joined: 2011-03-18,
User offline. Last seen 1 year 21 weeks ago.
Re: Why no call-by-name constructor parameter in case class allo

And the Serialize interface and overriding 'equals' (the extras that
the case keyword adds to a normal class and makes pattern matching
work)? Is 'equals' simply the result of: that.f == this.f

Aren't they necessary?

On 13 feb, 02:52, Naftoli Gugenheim wrote:
> So you have to expand on Victor's code a drop:
>
> object Message {
>  def apply(f: => Unit) = new Message(() => f)
>  *def unapply(m: Message): Option[()=>Unit] = Some(m.f) // IIRC, or
> something similar*}
>
> class Message(val f: () => Unit)
>
>
>
> On Thu, Feb 9, 2012 at 7:36 AM, Dave wrote:
> > Because it is sent and received by actors so for the pattern matching
> > in the receive mailbox.
>
> > On 9 feb, 03:52, Naftoli Gugenheim wrote:
> > > Why does Message have to be a case class?
>
> > > On Monday, February 6, 2012, Dave wrote:
> > > > Thanks all
>
> > > > Only Message is a case class which makes it problematic:
>
> > > > scala> :paste
> > > > // Entering paste mode (ctrl-D to finish)
>
> > > > case object Message { def apply(code: => Unit) = new Message(() =>
> > > > code) }
> > > > case class Message(code: () => Unit)
>
> > > > // Exiting paste mode, now interpreting.
>
> > > > :9: error: double definition:
> > > > method apply:(code: () => Unit)Message and
> > > > method apply:(code: => Unit)Message at line 8
> > > > have same type after erasure: (code: Function0)Message
> > > >       case class Message(code: () => Unit)
> > > >                  ^- Tekst uit oorspronkelijk bericht niet weergeven -
>
> > > - Tekst uit oorspronkelijk bericht weergeven -- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -

Naftoli Gugenheim
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Why no call-by-name constructor parameter in case class allowed?
I hope you're not pattern matching to compare it to another function -- that won't work. Function equality boils down to eq, testing if they are the same actual instance. You just need an extractor, which binds the function to a local identifier.
// thiscase Message(f) => println(f) // is syntactic sugar for approximatelycase m if Message.unapply(m).isDefined => println(Message.unapply(m).get)// which boils down tocase m: Message => println(m.f)
So you don't need equality for that.
As for serialization I can't comment but I guess you could specify it yourself using the annotation or trait (or interface). But as was pointed out, it's not trivial, if it's even possible, to serialize a function. For example:
object C {  var x = 2  val f: Int => Boolean = _ + x > 10}
class D {  val c = C  val f = c.f}
val m = Message(() => println((new D).f(7))C.x = 4
How do you serialize that?

On Monday, February 13, 2012, Dave wrote:
And the Serialize interface and overriding 'equals' (the extras that
the case keyword adds to a normal class and makes pattern matching
work)? Is 'equals' simply the result of: that.f == this.f

Aren't they necessary?

On 13 feb, 02:52, Naftoli Gugenheim <naftoli [dot] [dot] [dot] [at] gmail [dot] com> wrote:
> So you have to expand on Victor's code a drop:
>
> object Message {
>  def apply(f: => Unit) = new Message(() => f)
>  *def unapply(m: Message): Option[()=>Unit] = Some(m.f) // IIRC, or
> something similar*}
>
> class Message(val f: () => Unit)
>
>
>
> On Thu, Feb 9, 2012 at 7:36 AM, Dave <dave [dot] mahabiers [dot] [dot] [dot] [at] hotmail [dot] com> wrote:
> > Because it is sent and received by actors so for the pattern matching
> > in the receive mailbox.
>
> > On 9 feb, 03:52, Naftoli Gugenheim <naftoli [dot] [dot] [dot] [at] gmail [dot] com> wrote:
> > > Why does Message have to be a case class?
>
> > > On Monday, February 6, 2012, Dave wrote:
> > > > Thanks all
>
> > > > Only Message is a case class which makes it problematic:
>
> > > > scala> :paste
> > > > // Entering paste mode (ctrl-D to finish)
>
> > > > case object Message { def apply(code: => Unit) = new Message(() =>
> > > > code) }
> > > > case class Message(code: () => Unit)
>
> > > > // Exiting paste mode, now interpreting.
>
> > > > <console>:9: error: double definition:
> > > > method apply:(code: () => Unit)Message and
> > > > method apply:(code: => Unit)Message at line 8
> > > > have same type after erasure: (code: Function0)Message
> > > >       case class Message(code: () => Unit)
> > > >                  ^- Tekst uit oorspronkelijk bericht niet weergeven -
>
> > > - Tekst uit oorspronkelijk bericht weergeven -- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -

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