将三个连续的数字解析成一个字符串的惯用方法是什么?
以下方法可以工作,但不能扩展:
threeDigits :: Parser Int
threeDigits = do
d1 <- digit
d2 <- digit
d3 <- digit
return (digitToInt d1 * 100 + digitToInt d2 * 10 + digitToInt d3)更普遍的是,如何将此比例扩展到N个数字?
发布于 2017-12-16 15:39:20
使用count。
digits :: Int -> Parser Int
digits n = read <$> count n digithttps://stackoverflow.com/questions/47843604
复制相似问题