Omitting Constructor Parentheses

31 views
Skip to first unread message

Seyed H. HAERI (Hossein)

unread,
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?

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/
--------------------------------------------------------------------------------------------------------------

Naftoli Gugenheim

unread,
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 scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages