The Artima Developer Community
Sponsored Link

Programming in Scala Forum
error: illegal inheritance from sealed class List

1 reply on 1 page. Most recent reply: Apr 19, 2017 4:24 PM by John Lee

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
    Next Topic
Flat View: This topic has 1 reply on 1 page
John Lee

Posts: 2
Nickname: greentea
Registered: Apr, 2017

error: illegal inheritance from sealed class List Posted: Apr 19, 2017 12:11 PM
Reply to this message Reply
Advertisement
I am trying out the examples in the book from Section 22.1 and am getting this error

error: illegal inheritance from sealed class List

These classes don't compile so I'm confused as to why they're included as examples? Am I missing something here?

case object Nil extends List[Nothing] {
override def isEmpty = true
def head: Nothing =
throw new NoSuchElementException("head of empty list")
def tail: List[Nothing] =
throw new NoSuchElementException("tail of empty list")
}

final case class ::[T](hd: T, tl: List[T]) extends List[T] {
def head = hd
def tail = tl
override def isEmpty: Boolean = false
}


John Lee

Posts: 2
Nickname: greentea
Registered: Apr, 2017

Re: error: illegal inheritance from sealed class List Posted: Apr 19, 2017 4:24 PM
Reply to this message Reply
Never mind. I see now they are defining their own List class as

abstract class List[+T] {
def isEmpty: Boolean
def head: T
def tail: List[T]
}

Flat View: This topic has 1 reply on 1 page
    Next Topic Topic: Doubt in Scala Program


Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2017 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us