Reputation: 13
I was watching a video made by Richard Cook on SafariBookOnline. He builds a command line app with Haskell. In this video, he explains some basic concepts while writing a program to parse command lines arguments.
I am quite new to Haskell, and I can't figure out why this code does not work:
dataPathParser :: Parser FilePath
dataPathParser = strOption $
value defaultDataPath
<> long "data-path"
<> short 'p'
<> metavar "DATAPATH"
<> help ("path to data file (default " ++ defaultDataPath ++ ")")
This code does not work at well:
itemDescriptionValueParser :: Parser String
itemDescriptionValueParser =
strOption (long "desc" <> short 'd' <> metavar "DESCRIPTION" <> help "description")
And actually, everywhere I wrote "<>", I got an error where the compiler tells me that:
• Variable not in scope:
(<>) :: Mod f5 a5 -> Mod f4 a4 -> Mod ArgumentFields ItemIndex
• Perhaps you meant one of these:
‘<$>’ (imported from Options.Applicative),
‘<*>’ (imported from Options.Applicative),
‘<|>’ (imported from Options.Applicative)
The problem I got is most probably due to the difference of versions of GHC and Optparse-applicative. I use the latest ones. LTS Haskell 9.12: 0.13.2.0.
But since I am quite new, I can't figure out how to rewrite the code of Richard Cook.
I would appreciate any help.
Thanks in advance, Alex
Upvotes: 1
Views: 193
Reputation: 85837
A modifier can be created by composing the basic modifiers provided by here using the
Monoid
operationsmempty
andmappend
, or their aliasesidm
and<>
.
It looks like it doesn't export <>
, though, so you need to get it from Data.Monoid
:
import Data.Monoid
... or just:
import Data.Monoid ((<>))
Upvotes: 4