Immutable lists after building new ones

In Haskell, list values are immutable. The operator : builds a new list by placing one element in front of an existing list, tail returns a list without its first element, and ++ joins two lists into a new list. A program contains these three definitions:


haskell
xs = [4, 9, 2]
ys = 7 : xs
zs = tail ys ++ [5]


After all three definitions have been evaluated, xs contains elements and ys contains elements. The list zs contains elements. The sum of the elements of xs is , and the sum of the elements of zs is .

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Functional Languages and Programs Questions: