小编Phi*_*lip的帖子

错误 - 无法推断实例

我是Haskell的初学者.我有这个功能

test f xs 
  | length xs == 0  = []
  | f (head xs)     = head xs : test f (tail xs)
  | otherwise       = test f (tail xs)
Run Code Online (Sandbox Code Playgroud)

此函数应该从列表xs的每个元素中创建一个列表,该列表与f值匹配,但它会返回错误:

test 1 [1,2]
ERROR - Cannot infer instance
*** Instance   : Num (a -> Bool)
*** Expression : test 1 [1,2]
Run Code Online (Sandbox Code Playgroud)

这部分:

| f (head xs)
Run Code Online (Sandbox Code Playgroud)

应该是Bool但是呢?它是否作为过滤器工作?如何使此功能起作用?提前致谢.

haskell types type-inference instance

1
推荐指数
1
解决办法
757
查看次数

标签 统计

haskell ×1

instance ×1

type-inference ×1

types ×1