相关疑难解决方法(0)

Haskell映射函数中约束错误中的非类型变量参数

我正在编写一个函数mapper2,它将函数应用于两个列表:

mapper2 :: (a-> b -> c) -> [a] -> [b] -> [c]
mapper2 f (x:xs) (y:ys) = (f x y) : (mapper2 f xs ys)
mapper2 _ _ _ = []
Run Code Online (Sandbox Code Playgroud)

我能够编译该函数但在应用它时会出错:

*Main> mapper2 (\x -> x*2) [2,4] [4,6] 

<interactive>:4:1: error:
    • Non type-variable argument in the constraint: Num (b -> c)
      (Use FlexibleContexts to permit this)
    • When checking the inferred type
        it :: forall b c. (Num (b -> c), Num b) => [c]
Run Code Online (Sandbox Code Playgroud)

有人可以向我解释如何解决这个问题以及错误意味着什么?

haskell

7
推荐指数
2
解决办法
1万
查看次数

标签 统计

haskell ×1