"Extends case class" in dotty?

261 views
Skip to first unread message

Francois

unread,
Jul 11, 2016, 10:51:05 AM7/11/16
to dotty-i...@googlegroups.com
I learned (in
https://github.com/lampepfl/dotty/pull/1261#issuecomment-221736473) that
dotty will/is still support(ing) the possibility to extends case class.

I already asked on twitter, and the sole reason that came to not have
already removed that support in 2.x was for source compatibility,
because such source level compatibility would need a major bump on Scala
version.

Having that possibility forbid the possibility to even have a discussion
about marking case class final (and so save a lot of boilerplate in user
code).

So, two questions :

1/ Will Dotty support case class inheritance ?

2/ If so, why ?


Thanks !

--
Francois ARMAND - @fanf42
http://rudder-project.org
http://www.normation.com

martin odersky

unread,
Jul 11, 2016, 12:07:41 PM7/11/16
to Francois, dotty-i...@googlegroups.com
There are lots of instances in `dotc` itself where case classes are inherited. It's really very handy for 
things like hash-consing, or fine-grained case distinctions. So this will certainly not go away. 

Alleviating the syntactic burden of expressing ADTs: Yes, we are considering this. Nothing definite published yet, though.

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



--

Martin Odersky
EPFL and Lightbend

Naftoli Gugenheim

unread,
Jul 11, 2016, 12:13:24 PM7/11/16
to Francois, dotty-i...@googlegroups.com


On Mon, Jul 11, 2016, 10:51 AM Francois <fan...@gmail.com> wrote:
I learned (in
https://github.com/lampepfl/dotty/pull/1261#issuecomment-221736473) that
dotty will/is still support(ing) the possibility to extends case class.

I already asked on twitter, and the sole reason that came to not have
already removed that support in 2.x was for source compatibility,
because such source level compatibility would need a major bump on Scala
version.

Having that possibility forbid the possibility to even have a discussion
about marking case class final (and so save a lot of boilerplate in user
code).

So, two questions :

1/ Will Dotty support case class inheritance ?

2/ If so, why ?

Why not?




Thanks !

--
Francois ARMAND - @fanf42
http://rudder-project.org
http://www.normation.com

Serge

unread,
Jul 11, 2016, 7:10:32 PM7/11/16
to dotty-i...@googlegroups.com
Just a couple of thoughts about the possible syntax for ADTs.

trait Animal

object Animal {
final case class _ extends Animal {
Cat
Dog
Bird
}
}

trait Color(val code: String)

object Color {
trait SomeTrait

final case class _ extends Color {
Red <- ("#ff0000") //constructor parameters
Green <- ("#00ff00")
Blue <- ("#0000ff")

Black <- ("#000000") with SomeTrait {
def someFn: Int = ???
}
}
}

Francois

unread,
Jul 12, 2016, 4:43:20 AM7/12/16
to dotty-i...@googlegroups.com


Thanks for the answer !

And I'm thrilled by the idea of having burden-free ADT definition - because you're right, from my user point of view, I will almost never (directly) use case classes/objects if I were given a short way to define closed ADT.

Now, I'm really eager to be able to know more about what you are thinking about.

Thanks !
Reply all
Reply to author
Forward
0 new messages