main = putStrLn $ rle "wwwwaaadexxxxxx" split :: [Char] -> [[Char]] split str = reverse $ go [] (head str) str where go acc _ "" = acc go acc cur str = let newAcc = (takeWhile (==cur) str):acc newStr = dropWhile (==cur) str newCur = head newStr in go newAcc newCur newStr rle :: [Char] -> [Char] rle "" = "" rle x = foldl (\acc x -> acc ++ (head x:(show $ length x))) "" . split $ x