diff --git a/GetOpt/Options.hs b/GetOpt/Options.hs index c4241a1..767aa8e 100644 --- a/GetOpt/Options.hs +++ b/GetOpt/Options.hs @@ -1,7 +1,7 @@ module GetOpt.Options where -import GetOpt.Data(Option(..), OptionParser) -import GetOpt.Parsers +import GetOpt.Data( Option(..), OptionParser ) +import GetOpt.Parsers ( Parser(..) ) meta :: String -> Mod a meta v = Mod $ \x -> x { metavar = v } diff --git a/GetOpt/Parsers.hs b/GetOpt/Parsers.hs index d49d0da..3fd78e4 100644 --- a/GetOpt/Parsers.hs +++ b/GetOpt/Parsers.hs @@ -12,3 +12,11 @@ instance Functor Parser where fmap f (DefParser a) = DefParser $ f a fmap f (OptParser opt next) = OptParser (fmap (f .) opt) next +instance Applicative Parser where + -- pure a -> f a + pure a = DefParser a + + -- (<*>) f (a -> b) -> f a -> f b + (<*>) (DefParser f) p = fmap f p + -- (<*>) (OptParser (Option (a -> b -> c)) Parser (a -> b)) -> Parser a -> Parser c + (<*>) (OptParser f next) p = OptParser () next \ No newline at end of file diff --git a/Main.hs b/Main.hs index 590177e..e765b02 100644 --- a/Main.hs +++ b/Main.hs @@ -17,19 +17,19 @@ getParser = Configuration <> meta "RULE" <> help "The rulset used." ) - -- <*> option ( - -- long "start" - -- <> short 's' - -- <> meta "START" - -- <> help "At witch line should we start" - -- <> value 0 - -- ) + <*> option auto ( + long "start" + <> short 's' + <> meta "START" + <> help "At witch line should we start" + <> value 0 + ) data Configuration = Configuration { - rule :: Int - -- start :: Int, + rule :: Int, + start :: Int -- lines :: Maybe Int, -- window :: Int, -- move :: Int