Alex k
Alex k

Reputation: 13

Error: "Variable not in scope: (<>)" with the library optparse-applicative

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

Answers (1)

melpomene
melpomene

Reputation: 85837

http://hackage.haskell.org/package/optparse-applicative-0.14.0.0/docs/Options-Applicative.html#t:Parser:

A modifier can be created by composing the basic modifiers provided by here using the Monoid operations mempty and mappend, or their aliases idm 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

Related Questions