Skip to content

Instantly share code, notes, and snippets.

@Heimdell
Last active August 29, 2015 14:09
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 Heimdell/3f483c02226d95faf1ee to your computer and use it in GitHub Desktop.
Save Heimdell/3f483c02226d95faf1ee to your computer and use it in GitHub Desktop.
import Text.ParserCombinators.Parsec (Parser, parse, many, string)
import Control.Monad (msum, forM_)
program :: Parser ()
program = do
rbr <- opening
many program
string rbr
return ()
opening :: Parser String
opening = msum
[ string "(" >> return ")"
, string "[" >> return "]"
, string "{" >> return "}"
]
cases =
[ "((()()))"
, "([{}]{(){}})"
, "([{]}{(){}})"
]
main =
cases `forM_` \line ->
print (parse program "" line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment