我正在编写一个xml-conduit解析器,我更喜欢应用语法而不是monadic。尽管有很多论点可以组合,但是我在应用性方面有些迷失。我当前的问题有8个参数,我只想使用4和6来构造结果。

我可以使它起作用的唯一方法是:但是,应该有一些奇特的星星安排一个扁平的解决方案:

import Control.Applicative

a1 :: Applicative Text
a2 :: Applicative Text
a3 :: Applicative Text
a4 :: Applicative Text
a5 :: Applicative Text
a6 :: Applicative Text
a7 :: Applicative Text
a8 :: Applicative Text

data Data = Data Text Text
f :: Text -> Text -> Data

parser :: Applicative Data
parser = a1 *> a2 *> a3 *> (f <$> a4 <* a5 <*> a6) <* a7 <* a8

有没有办法用括号括起来的形式呢?
parser = f <$> a1 ?? a2 ?? a3 ?? a4 ?? a5 ?? a6 ?? a7 ?? a8

最佳答案

啊哈,建议的链接Applicative style parser for constructor with two arguments使我得到答案:使用(<$),不要使用(*>)

parser = f <$ a1 <* a2 <* a3 <*> a4 <* a5 <*> a6 <* a7 <* a8

关于haskell - 忽略Control.Applicative中的参数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16050719/

10-11 15:34