关于haskell:为什么这给了我“是一个严格的类型变量绑定”错误

Why is this giving me “is a rigid type variable bound by” error

1
2
3
4
5
6
7
heist :: (Num n) => [n] -> [n] -> n -> n
-- heist [] [] _ = 0
heist w v maxw = func w v i j where
    i = length w
    j = maxw  
func :: (Num n) => [n] -> [n] -> n -> n -> n
func _ _ 0 0 = 0

上面的代码给出了:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Heist.hs:15:27:
    Could not deduce (n ~ Int)
    from the context (Num n)
      bound by the type signature for
                 heist :: Num n => [n] -> [n] -> n -> n
      at Heist.hs:(15,1)-(17,16)
      `n' is a rigid type variable bound by
          the type signature for heist :: Num n => [n] -> [n] -> n -> n
          at Heist.hs:15:1
    In the third argument of `func', namely `i'
    In the expression: func w v i j
    In an equation for `heist':
        heist w v maxw
          = func w v i j
          where
              i = length w
              j = maxw

为什么会这样?

我正把我的头一寸一寸地绕在哈斯克尔式系统上。


length总是Int时返回延安。通过对ifunc到你说的那n应该Int,但heistn是通用的,hence型错误。 </P >


length时返回一Int;使用i = Data.List.genericLength wi = fromIntegral (length w)。。。。。。。 </P >