Skip to content

Instantly share code, notes, and snippets.

@comfly
Created June 8, 2016 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save comfly/70ed32850162b31b468eafce79eb7d77 to your computer and use it in GitHub Desktop.
Save comfly/70ed32850162b31b468eafce79eb7d77 to your computer and use it in GitHub Desktop.
Run length encoding
module Main where
import Data.Foldable
rle = (concatMap (\(sym, num) -> sym:show num)) . foldr' collect []
where collect s [] = [(s, 1)]
collect s all@((sym, num):others)
| sym == s = (sym, num + 1):others
| otherwise = (s, 1):all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment