Skip to content

Instantly share code, notes, and snippets.

@nanki
Created January 8, 2012 07:35
Show Gist options
  • Save nanki/1577600 to your computer and use it in GitHub Desktop.
Save nanki/1577600 to your computer and use it in GitHub Desktop.
Parsec golf.
import qualified Text.Parsec as P
import Control.Applicative
import Control.Monad (msum)
main = do
P.parseTest primitive0 "short"
P.parseTest primitive1 "byte"
P.parseTest primitive2 "char"
primitive0 = do
P.try (P.string "short")
<|> P.try (P.string "byte")
<|> P.try (P.string "char")
<|> P.try (P.string "long")
<|> P.try (P.string "int")
keywords = ["short", "byte", "char", "long", "int"]
primitive1 = do
(foldl1 (<|>) $ map (P.try . P.string) keywords)
primitive2 = do
msum $ map (P.try . P.string) keywords
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment