Haskell:列表理解:约束中的非类型变量参数:Num[t]

Haskell:列表理解:约束中的非类型变量参数:Num[t],haskell,Haskell,当我试图运行下面的函数时,我得到了一个错误 Prelude> let squareSum list = [result | (x, y, z) <- list, result <- x^2 + y^2 + z^2] <interactive>:4:5: Non type-variable argument in the constraint: Num [t] (Use FlexibleContexts to permit this) Wh

当我试图运行下面的函数时,我得到了一个错误

Prelude> let squareSum list = [result | (x, y, z) <- list, result <- x^2 + y^2 + z^2] 

<interactive>:4:5:
    Non type-variable argument in the constraint: Num [t]
    (Use FlexibleContexts to permit this)
    When checking that ‘squareSum’ has the inferred type
     squareSum :: forall t. Num [t] => [([t], [t], [t])] -> [t]
Prelude>let squareSum list=[result |(x,y,z)[t]

有人能给我解释一下,如何解决这个问题吗?这个错误到底是什么?

下面的片段解决了我的问题

Prelude> let processData fun list = [y | x <- list, let y = fun x]
Prelude> let sumSquare (x, y, z) = x^2 + y^2 + z^2
Prelude> 
Prelude> processData sumSquare [(1, 2, 3), (4, 5, 6)]
[14,77]
Prelude>let processData fun list=[y | x let sumSquare(x,y,z)=x^2+y^2+z^2
序曲>
前奏曲>过程数据sumSquare[(1,2,3)、(4,5,6)]
[14,77]
原始问题 您发布了:

Prelude> let squareSum list = [result | (x, y, z) <- list, result <- x^2 + y^2 + z^2]

<interactive>:3:5:
    Non type-variable argument in the constraint: Num [t]
    (Use FlexibleContexts to permit this)
    When checking that ‘squareSum’ has the inferred type
      squareSum :: forall t. Num [t] => [([t], [t], [t])] -> [t]

现在你说变量
list
包含元组(
(x,y,z)可能是因为你试图从一个和中提取
结果
——我想你想要
let squareSum list=[x^2+y^2+z^2 |(x,y,z)谢谢Carsten。我试过了,但仍然面临同样的问题。序曲>let squareSum list=[x^2+y^2+z^2 |(x,y,z)squareSum[1,2,3]:33:1:约束中的非类型变量参数:Num(t,t,t)(使用flexibleContext允许此操作)在检查“it”是否具有推断类型it::forall t.(Num t,Num(t,t,t))=>[(1,2,3),(4,5,6)]
使用
让平方和xs=sum[x^2|x
Prelude> let squareSum list = [ x^2 + y^2 + z^2 | (x, y, z) <- list]
Prelude> squareSum [1,2,3]

<interactive>:9:1:
    Non type-variable argument in the constraint: Num (t, t, t)
    (Use FlexibleContexts to permit this)
    When checking that ‘it’ has the inferred type
      it :: forall t. (Num t, Num (t, t, t)) => [t]
Prelude> :{
Prelude| let squareSum :: [(Int,Int,Int)] -> [Int]
Prelude|     squareSum list = [ x^2 + y^2 + z^2 | (x, y, z) <- list]
Prelude| :}
Prelude> squareSum [(1,2,3), (4,5,6)]
[14,77]