简体   繁体   English

错误:库optparse-applicative出现“变量不在范围内:(<>)”

[英]Error: “Variable not in scope: (<>)” with the library optparse-applicative

I was watching a video made by Richard Cook on SafariBookOnline. 我在SafariBookOnline上观看了Richard Cook制作的视频。 He builds a command line app with Haskell. 他与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: 我对Haskell还是很陌生,我无法弄清楚为什么这段代码不起作用:

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. 我遇到的问题很可能是由于GHC和Optparse-applicative版本的差异。 I use the latest ones. 我用最新的。 LTS Haskell 9.12: 0.13.2.0. 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. 但是由于我是新手,所以我不知道如何重写Richard Cook的代码。

I would appreciate any help. 我将不胜感激任何帮助。

Thanks in advance, Alex 预先感谢Alex

http://hackage.haskell.org/package/optparse-applicative-0.14.0.0/docs/Options-Applicative.html#t:Parser : 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 <> . 可以通过使用Monoid操作memptymappend或它们的别名idm<>组成此处提供的基本修饰符来创建修饰符。

It looks like it doesn't export <> , though, so you need to get it from Data.Monoid : 看起来它没有导出<> ,所以您需要从Data.Monoid获取它:

import Data.Monoid

... or just: ... 要不就:

import Data.Monoid ((<>))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM