Re: [scala-user] Case class lose tupled method after redefining the companion object

941 views
Skip to first unread message

√iktor Ҡlang

unread,
Jun 3, 2012, 10:44:56 AM6/3/12
to Carlos Encarnacion, scala...@googlegroups.com


On Sat, Jun 2, 2012 at 1:36 AM, Carlos Encarnacion <encarnaci...@gmail.com> wrote:
Hi,

case class A(v: String)
object A {
  A.tupled // compile error
}

What am I missing here?

 A description of what you're trying to achieve?


--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: @viktorklang

Jason Zaugg

unread,
Jun 3, 2012, 11:11:54 AM6/3/12
to Carlos Encarnacion, scala...@googlegroups.com
On Sat, Jun 2, 2012 at 1:36 AM, Carlos Encarnacion
<encarnaci...@gmail.com> wrote:
> Hi,
>
> case class A(v: String)
> object A {
>   A.tupled // compile error
> }
>
> What am I missing here?

https://issues.scala-lang.org/browse/SI-3664

-jason

Stefan Zeiger

unread,
Jun 3, 2012, 5:11:07 PM6/3/12
to scala...@googlegroups.com
On 2012-06-02 1:36, Carlos Encarnacion wrote:
>
> What am I missing here?

https://issues.scala-lang.org/browse/SI-4808


Jefferson Andrade

unread,
Jun 4, 2012, 10:25:18 AM6/4/12
to Carlos Encarnacion, scala...@googlegroups.com
I believe that once you explicitly define the companion object you no longer have the implicit one.

Jeff.


On Mon, Jun 4, 2012 at 10:38 AM, Carlos Encarnacion <encarnaci...@gmail.com> wrote:
The implicit defined companion object of a case class have a method called tupled. I just want to use it, after explicit defining the companion object.


On Friday, June 1, 2012 7:36:56 PM UTC-4, Carlos Encarnacion wrote:
Hi,

case class A(v: String)
object A {
  A.tupled // compile error
}

What am I missing here?



--
"You question the worthiness of my Code? I should kill you where you stand!"

Carlos Encarnacion

unread,
Jun 4, 2012, 11:25:11 AM6/4/12
to scala...@googlegroups.com, Carlos Encarnacion
If that is true, it's quite unfortunate. Is there any workaround?

Andreas Flierl

unread,
Jun 4, 2012, 11:45:18 AM6/4/12
to scala...@googlegroups.com
Hi,

the following works:

case class Foo(a: Int, b: String)
object Foo extends((Int, String) => Foo) {
Foo.tupled
}

Carlos Encarnacion <encarnaci...@gmail.com> wrote:
> If that is true, it's quite unfortunate. Is there any workaround?
(...)
> On Friday, June 1, 2012 7:36:56 PM UTC-4, Carlos Encarnacion wrote:
> Hi,
>
> case class A(v: String)
> object A {
> A.tupled // compile error
> }
>
> What am I missing here?

Aside from the already-mentioned fact that custom companion objects of
case classes aren't functions by default, the "tupled" method is only
available on functions of arity 2 and higher. Your case class only has
one parameter. Therefore, its auto-generated companion would not have
the "tupled" method either.

Kind regards
Andreas

Knut Arne Vedaa

unread,
Jun 4, 2012, 5:24:50 PM6/4/12
to scala...@googlegroups.com
On 04.06.2012 17:25, Carlos Encarnacion wrote:
> If that is true, it'squite unfortunate. Is there any workaround?
>
> On Monday, June 4, 2012 10:25:18 AM UTC-4, Jefferson Andrade wrote:
>
> I believe that once you explicitly define the companion object you
> no longer have the implicit one.

Not true at all:

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

case class Foo(a: Int)
object Foo { def apply(s: String) = s }

// Exiting paste mode, now interpreting.

defined class Foo
defined module Foo

scala> Foo(3)
res3: Foo = Foo(3)

scala> Foo("hello")
res4: String = hello


Knut Arne Vedaa

John Ky

unread,
Mar 4, 2014, 2:49:36 AM3/4/14
to scala...@googlegroups.com
Hi Scala Users,

I just wanted to mention that I bumped into this behaviour and found it very surprising.

Is that really how Scala us supposed to behave?

Cheers,

-John


On Saturday, 2 June 2012 09:36:56 UTC+10, Carlos Encarnacion wrote:
Hi,

case class A(v: String)
object A {
  A.tupled // compile error
}

What am I missing here?


  Sydney, Australia

        

Som Snytt

unread,
Mar 4, 2014, 3:21:48 AM3/4/14
to John Ky, scala-user
What you don't hear is people complaining that scalac messed with their type hierarchy.

Also, there is controversy about whether collections should be functions, because as implicit vals they also convert things.

Do people exploit this?

scala> :pa

// Entering paste mode (ctrl-D to finish)

case class A(i: Int)
implicit object A extends (Int => A)


// Exiting paste mode, now interpreting.

defined class A
defined object A

scala> def f(a: A) = a.i * 2
f: (a: A)Int

scala> f(3)
res2: Int = 6


I love the Klassik Klangism at the start of the thread:


> What am I missing here?
> A description of what you're trying to achieve?

I also love the follow-ups that reply with not one issue number but two.  Maybe one is canonical.



--
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/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages