繁体   English   中英

Haskell错误:约束中的非类型变量参数:Num(a - > a - > a - > a)

[英]Haskell Error: Non type-variable argument in the constraint: Num (a -> a -> a -> a)

我是Haskell的新手,我正在尝试从我的书中运行以下示例代码:

整个档案:

-- my name

splitAt1   ::  [a] -> ([a], [a])
splitAt1 xs = (take 2 xs, drop 2 xs) 

我正在通过运行线路进行测试:

splitAt1 [1 2 3 4]

想法是输入数组在索引2处被拆分为两个数组。但是,我收到以下错误:

Non type-variable argument
  in the constraint: Num (a -> a -> a -> a)
(Use FlexibleContexts to permit this)
When checking that ‘it’ has the inferred type
  it :: forall a a1 a2 a3.
        (Num a1, Num a2, Num a3, Num (a1 -> a2 -> a3 -> a)) =>
        ([a], [a])

任何人都可以帮我解码错误信息,也许代码有什么问题?

功能很好,这是你的论点。

尝试splitAt1 [1,2,3,4]而不是splitAt1 [1 2 3 4] ,它应该工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM