ReadP具有以下功能:
count :: Int -> ReadP a -> ReadP [a]
-- Usage:
count 3 $ satisfy (== 'c')我想知道是否有类似的函数可以在3到8次之间进行解析:
count_between 3 8 $ satisfy (== 'c')如果我必须创建我自己的,你会怎么做?
发布于 2017-06-28 05:15:21
count_between a b p = (++) <$> count a p <*> count_upto (b - a) p
count_upto 0 _ = pure []
count_upto b p = ((:) <$> p <*> count_upto (b-1) p) +++ pure []注意它与many的相似之处。munching的变体将使用<++而不是+++。
https://stackoverflow.com/questions/44789752
复制相似问题