本文介绍了这是Text.Parsec的惯用用法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Text.Parsec的使用有点生锈.如果我只想返回匹配的字符串,这是惯用的吗?

My use of Text.Parsec is a little rusty. If I just want to return the matched string is this idiomatic?

category :: Stream s m Char => ParsecT s u m [Char]                        
category = concat <$> (many1 $ (:) <$> char '/' <*> (many1 $ noneOf "/\n"))

我觉得可能已经存在liftM concat . many1(:) <$> p1 <*> p2的现有运算符,但我不确定.

I feel like there might be an existing operator for liftM concat . many1 or (:) <$> p1 <*> p2 that I'm ignoring, but I'm not sure.

推荐答案

我认为很好.明智的命名会使它更漂亮:

That's fine, I think. A little judicious naming would make it prettier:

category = concat <$> many1 segment
  where
    segment = (:) <$> char '/' <*> many1 (noneOf "/\n")

这篇关于这是Text.Parsec的惯用用法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 20:05