tail is a list operation that returns every element after the first. For a nonempty list val mylist = Cons(x, xs), tail returns xs without changing mylist. Because the list is immutable, the result can reuse the existing structure rather than copy it. section 3.3
Removing the first element
Given Cons(1, Cons(2, Nil)), tail returns Cons(2, Nil). Applying tail to Nil fails; the exercise permits using sys.error("message") for that case. The operation takes constant time because it returns the stored tail directly. section 3.3 section 3.1
Implement tail against the custom list definition:
- Handle Cons by returning its tail field. section 3.3
- Handle Nil by raising an error rather than returning a list. section 3.3
- Use the defined List and Nil types, not Scala’s built-in versions. section 3.3
Use the data-sharing figure to see how tail preserves the original list while returning a reference to its remaining structure. section 3.3


