我正在编写一个xml管道解析器,并且我更喜欢应用语法而不是一元语法。由于要结合许多论点,我有点迷失在应用程序中。我现在的问题有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发布于 2013-04-17 11:11:16
啊哈,推荐的Applicative style parser for constructor with two arguments链接让我找到了答案:使用(<$),不要使用(*>)。
parser = f <$ a1 <* a2 <* a3 <*> a4 <* a5 <*> a6 <* a7 <* a8https://stackoverflow.com/questions/16050719
复制相似问题