【发布时间】:2015-01-12 04:14:01
【问题描述】:
为什么单次使用这种类型可以编译,但是放入列表却失败了?
ft1 :: (Foldable t, Num a) => t a -> a
ft1 = (F.foldl (+) 0)
fTest :: [(Foldable t, Num a) => t a -> a ]
fTest = [ F.foldl (+) 0 ]
后者给出错误:
folding.hs:80:10:
Illegal polymorphic or qualified type:
(Foldable t, Num a) => t a -> a
Perhaps you intended to use ImpredicativeTypes
In the type signature for `fTest':
fTest :: [(Foldable t, Num a) => t a -> a]
同样,尝试命名它失败(不同):
type Ftst t a = (Foldable t, Num a) => t a -> a
folding.hs:80:1:
Illegal polymorphic or qualified type:
(Foldable t, Num a) => t a -> a
Perhaps you intended to use RankNTypes or Rank2Types
In the type declaration for `Ftst'
【问题讨论】:
-
猜测:也许你的意思是
fTest :: (Foldable t, Num a) => [t a -> a]? -
谢谢;我以为我已经尝试过了,但它确实有效。然而仍然尝试使用类型别名(如上面的 Ftst)命名相同的类型失败(有或没有列表符号) - 为什么?
标签: haskell