Brace expansion: Difference between revisions
Content added Content deleted
(Updated D entry) |
|||
Line 660:
[http://www.reddit.com/r/readablecode/comments/1w6exe/p6_crosswalk_braceexpansionparses/cf229at "Here is a direct translation to Haskell using parsec"] (of [http://rosettacode.org/mw/index.php?title=Brace_expansion&oldid=175567#Perl_6 an earlier version of the Perl 6 solution]):
<lang haskell>import Control.Applicative (liftA2, pure, (<$>), (<*>))
import Control.Monad (forever)
import Text.Parsec
Line 666:
parser :: Parsec String u [String]
parser = expand <$> many (try alts <|> try alt1 <|> escape <|> pure . pure <$> anyChar)
where
alt = expand <$> many (try alts <|> try alt1 <|> escape
expand =
p `sepBy2` sep = liftA2 (:) p (many1 (sep >> p))
main :: IO ()
|