【发布时间】:2018-03-26 12:25:45
【问题描述】:
我是Haskell 的新手,我进入了下面的代码,但并不真正理解它的作用。
我知道toDigits 函数被声明为采用Integer 并返回Integers 的数组。如果参数n 等于或小于0,我们返回一个空数组,否则......?这就是奥秘!
toDigits :: Integer -> [Integer]
toDigits n
| n < 1 = []
| otherwise = reverse $ split [] n
where split _ 0 = []
split acc m = lastDigit m : split acc (dropLastDigit m)
你能解释一下吗?
【问题讨论】:
-
accumulator 参数从未在该实现中使用。它可能应该被省略。
-
lastDigit和dropLastDigit是做什么的?
标签: haskell split functional-programming reverse