嗨,这里是我的代码如下。Haskell:无法与Int类型[Int]匹配
data Treeof a = Node Int a [Treeof a] deriving (Eq,Show)
add_score :: Int -> Treeof a -> [[Int]]
add_score 0 (Node i a xs) = [[0]]
add_score n (Node i a xs) = [i]:[(map (add_score (n-1)) xs)]
我试图获取存储在树中每个节点的诠释,并将其存储在一个列表的列表,但得到如下所示的错误,我不能确定这是为什么。
Couldn't match type `[[Int]]' with `Int'
Expected type: Treeof a -> Int
Actual type: Treeof a -> [[Int]]
In the first argument of `map', namely `(add_score (n - 1))'
In the expression: (map (add_score (n - 1)) xs)
Failed, modules loaded: none.
编辑:更改[I]:[(地图(add_score第(n-1))XS)]至[I] :(图(add_score第(n-1))XS)
而得到一个类似的错误
Couldn't match type `[Int]' with `Int'
Expected type: Treeof a -> [Int]
Actual type: Treeof a -> [[Int]]
In the first argument of `map', namely `(add_score (n - 1))'
In the second argument of `(:)', namely
`(map (add_score (n - 1)) xs)
Failed, modules loaded: none.
你想在这里做什么 - 你不要添加任何东西! – Carsten
@Carsten我试图获取存储在树的节点中的Ints,并在初始节点之后为树的第一级的每个分支添加每个分数。 –
请粘贴代码片段而不是屏幕截图。 – amalloy