小编Rue*_*ege的帖子

Haskell:使用foldr在函数中输入不匹配

我不明白为什么这些函数有错误:

countEqualPairs:: Eq a => [a] -> Int
countEqualPairs (s:ss) = foldr test s ss

test :: Eq a => a -> a -> Int
test s c = if (c == s) then 1 else 0
Run Code Online (Sandbox Code Playgroud)

错误信息:

Could not deduce (a ~ Int)
from the context (Eq a)
  bound by the type signature for
            countEqualPairs :: Eq a => [a] -> Int
  at Blatt06.hs:30:20-37
 `a' is a rigid type variable bound by
     the type signature for countEqualPairs :: Eq …
Run Code Online (Sandbox Code Playgroud)

haskell

-3
推荐指数
1
解决办法
93
查看次数

标签 统计

haskell ×1