Trying to start the applicative implementation of OptParser

This commit is contained in:
Zoe Roux
2021-03-10 21:19:50 +01:00
parent 95dfe58d05
commit 9b35ef6ccf
3 changed files with 19 additions and 11 deletions
+2 -2
View File
@@ -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 }
+8
View File
@@ -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
+9 -9
View File
@@ -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