Quantcast

Omitting Constructor Parentheses

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Omitting Constructor Parentheses

Seyed H. HAERI (Hossein)
Dear all,

I have a class

case class Left(val e: Expr = Num(1)) extends Command

which I'd like to use like

val v = Left

in which I'd be omitting the constructor's parentheses -- just like those of any other purely functional method. I get the following error under Scala 2.11.8, however:

type mismatch; found : m1.syntax.Left.type required: m2.syntax.Command

Why is that?

TIA,
--Hossein
 
--------------------------------------------------------------------------------------------------------------

Seyed H. HAERI (Hossein), Dr.

Post-Doctoral Research Fellow
Department of Computing Science and Engineering
Catholic University of Louvain
Louvain-la-Neuve, Belgium

ACCU - Professionalism in programming - http://www.accu.org/
--------------------------------------------------------------------------------------------------------------

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Omitting Constructor Parentheses

Naftoli Gugenheim

Because it's the name of the companion object that's generated with the case class. In fact the syntax with parentheses only works by desugaring to a call to the companion's apply method


On Wed, Apr 12, 2017, 7:31 PM Seyed H. HAERI (Hossein) <[hidden email]> wrote:
Dear all,

I have a class

case class Left(val e: Expr = Num(1)) extends Command

which I'd like to use like

val v = Left

in which I'd be omitting the constructor's parentheses -- just like those of any other purely functional method. I get the following error under Scala 2.11.8, however:

type mismatch; found : m1.syntax.Left.type required: m2.syntax.Command

Why is that?

TIA,
--Hossein
 
--------------------------------------------------------------------------------------------------------------

Seyed H. HAERI (Hossein), Dr.

Post-Doctoral Research Fellow
Department of Computing Science and Engineering
Catholic University of Louvain
Louvain-la-Neuve, Belgium

ACCU - Professionalism in programming - http://www.accu.org/
--------------------------------------------------------------------------------------------------------------

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Loading...