fork download
  1. import Data.Char
  2. import Data.List.Split
  3. import Data.Maybe
  4. import Text.Read
  5.  
  6.  
  7. sep :: String -> [String]
  8. sep s = concat $ map sepBr (splitOn " " s) where
  9. sepBr :: String -> [String]
  10. sepBr "" = []
  11. sepBr " " = []
  12. sepBr word
  13. | a `elem` brackets = [[a]] ++ sepBr bc
  14. | c `elem` brackets = sepBr ab ++ [[c]]
  15. | otherwise = ([a : bc])
  16. where a = if word == [] then [] else head word
  17. b = if word == [] then [] else init $ tail word
  18. c = if word == [] then [] else last word
  19. ab = [a] ++ b
  20. bc = b ++ [c]
  21. brackets = ['(', ')']
  22.  
  23. main :: IO()
  24. main = do
  25. putStrLn $ show $ sep "(+ 12 (* 3 4 (+ 1 2 3) 5) 1)"
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.hs:2:8:
    Could not find module `Data.List.Split'
    Use -v to see a list of the files searched for.
stdout
Standard output is empty