Haskell 对其结果被丢弃的解析器使用应用程序表示法

Haskell 对其结果被丢弃的解析器使用应用程序表示法,haskell,refactoring,parsec,applicative,Haskell,Refactoring,Parsec,Applicative,我有一个关于重构代码以使用Applicative接口的问题。假设我有一个使用一元接口的解析器,如下所示: filePath0 :: GenParser Char st Info filePath0 = do optional (string "./") r <- artist slash l <- album slash t <- track return $ Song r l t filePath :: GenParser Char st Inf

我有一个关于重构代码以使用
Applicative
接口的问题。假设我有一个使用一元接口的解析器,如下所示:

filePath0 :: GenParser Char st Info
filePath0 = do
  optional (string "./")
  r <- artist
  slash
  l <- album
  slash
  t <- track
  return $ Song r l t
filePath :: GenParser Char st Info
filePath = Song <$> artist <*> album <*> track
filePath0::GenParser Char st Info
filePath0=do
可选(字符串“/”)

你可以使用
*>
)::fa->fb->fb
(f b->f a
给予

filePath :: GenParser Char st Info
filePath = optional "./" *> Song <$> artist <*> slash *> album <*> slash *> track
filePath::GenParser Char st Info
filePath=可选“./”*>歌曲艺术家斜杠*>专辑斜杠*>曲目
您还可以使用
a->fb->fa
将“语义”保留在最左边。
filePath :: GenParser Char st Info
filePath = optional "./" *> Song <$> artist <*> slash *> album <*> slash *> track