Created
April 27, 2015 16:12
-
-
Save nulldatamap/9465192c6a57023d0aa5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- 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