99 Elm Problems/Problem 8/Solutions

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Solution 1: Recursive version

compress list =
  case list of
    [] -> []
    [ first ] -> [ first ]
    first :: next :: tail ->
      if first == next then
        compress (next :: tail)
      else
        first :: compress (next :: tail)