411 REFERENCE · Wikibooks
99 Elm Problems/Problem 10/Solutions
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
Solution 1: Recursive version
runLengthEncode list =
case list of
[] -> []
[ x ] -> [ (x, 1) ]
x :: xs ->
case runLengthEncode xs of
[] -> []
(x', n) :: xs' ->
if x == x' then
(x, n + 1) :: xs'
else
( x, 1 ) :: (x', n) :: xs'