Omitting Constructor Parentheses

Skip to first unread message

Seyed H. HAERI (Hossein)

Apr 12, 2017, 7:31:27 PM4/12/17
to scala-user
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?


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 -

Naftoli Gugenheim

Apr 13, 2017, 12:03:55 AM4/13/17
to Seyed H. HAERI (Hossein), scala-user

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

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
For more options, visit
Reply all
Reply to author
0 new messages