我尝试在类型实例的where-body中使用type变量.但是GHC不对类型实例中的函数使用类型变量.
我尝试实现类型类Bits的[a].
instance forall a. Bits a => Bits [a] where
xor = zipWith xor
rotateL list dis = keeped .|. overlap
where
overlap = tail moved ++ [head moved]
(keeped, moved) = unzip $ map (\n -> let rot = rotate n dis in (rot.&.mask, rot.&.filter)) list
mask = (complement 0) `shiftL` dis -- this line
filter = complement mask
Run Code Online (Sandbox Code Playgroud)
GHC说:
Could not deduce (Num a) arising from the literal ‘0’
Run Code Online (Sandbox Code Playgroud)
预期:
这0应该是类型 …