Skip to content

Instantly share code, notes, and snippets.

@nulldatamap
Created April 27, 2015 16:12
Show Gist options
  • Select an option

  • Save nulldatamap/9465192c6a57023d0aa5 to your computer and use it in GitHub Desktop.

Select an option

Save nulldatamap/9465192c6a57023d0aa5 to your computer and use it in GitHub Desktop.
-- Naïve indenter
space = repeat ' '
_indent :: Int -> [Int] -> [Char] -> [Char]
_indent _ _ [] = ""
_indent w k@(t:_) (',':s) = '\n' : take t space ++ ',' : _indent (t+1) k s
_indent w k (c:s) = c : _indent (w+1) (f c) s
where
f v
| c == '{' || c == '[' = (w:k)
| c == '}' || c == ']' = drop 1 k
| otherwise = k
indent :: String -> String
indent = _indent 0 []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment