Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala Dotty Union Type DaysOfTheWeek Example

Tags:

scala

dotty

The official Scala Dotty team showed this example from (https://d-d.me/talks/scalaworld2015/#/12)

object DaysOfTheWeek {
  object Mon
  object Tue
  object Wed
  object Thu
  object Fri
  object Sat
  object Sun

  type Weekend = Sat.type | Sun.type
  type Workweek = Mon.type | Tue.type | Wed.type | Thu.type | Fri.type
  type All = Weekend | Workweek
}

If I use the latest Dotty nightly build, which as of this post is "0.1.1-20170322-5fd7a95-NIGHTLY", that example results in these errors:

Error:(13, 18) Singleton type DaysOfTheWeek.Sat.type is not allowed in a union type
Error:(13, 29) Singleton type DaysOfTheWeek.Sun.type is not allowed in a union type
Error:(14, 19) Singleton type DaysOfTheWeek.Mon.type is not allowed in a union type
Error:(14, 30) Singleton type DaysOfTheWeek.Tue.type is not allowed in a union type
Error:(14, 41) Singleton type DaysOfTheWeek.Wed.type is not allowed in a union type
Error:(14, 52) Singleton type DaysOfTheWeek.Thu.type is not allowed in a union type
Error:(14, 63) Singleton type DaysOfTheWeek.Fri.type is not allowed in a union type

Is there any way to get this official example working?

like image 929
clay Avatar asked Dec 10 '25 04:12

clay


1 Answers

This works now:

enum DaysOfTheWeek {
case Mon
case Tue
case Wed
case Thu
case Fri
case Sat
case Sun
  type Weekend = Sat.type | Sun.type
  type Workweek = Mon.type | Tue.type | Wed.type | Thu.type | Fri.type
  type All = Weekend | Workweek
}

Link to Scastie

like image 194
user Avatar answered Dec 13 '25 02:12

user



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!