我是一个Haskell的入门者。在尝试完成hackerrank上的一些练习时,我遇到了一个错误,这让我想知道是否有“正确”的方法来解决它。
我尝试做的是这个:
import Data.Matrix
newtype Puzzle = Matrix Char
complete :: Puzzle -> Bool
complete p = '-' `elem` (toList p)
[... more functions on 'Matrix Char']
这给了我:
Couldn't match expected type ‘Matrix Char’
with actual type ‘Puzzle’
In the first argument of ‘toList’, namely ‘p’
In the second argument of ‘elem’, namely ‘(toList p)’
显而易见的解决方案当然是使用
Matrix Char
而不是Puzzle
。但我觉得这不是一个优雅的解决方案。更具体类型的抽象感觉是正确的方法...