2017-06-27 1 views
3

READPがこの機能を持っていますReadPの "count 3"は3回出現を解析します。 3と8の間でどのように解析するのですか?

count :: Int -> ReadP a -> ReadP [a] 

-- Usage: 
count 3 $ satisfy (== 'c') 

3と8の発生の間に解析するために同様の機能がある場合、私は思ったんだけど:

count_between 3 8 $ satisfy (== 'c') 

私は自分自身を作成する必要がある場合、どのようにだろうそれを行う?

答えて

4
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に類似していることに注意してください。 munch+++の代わりに<++を使用します。