import Data.Int
class At c v i | c -> v, c -> i where
at :: c -> i -> v
instance At [a] a Int where
at l i = l !! i
{--
f = at [2 ^ i | i <- [0..]] 10
main = print f
--}
如果我在 ghci(带有 -fglasgow-exts 的 ghc 7.4.1)中加载它,我会收到这样的错误。
Prelude> :load Main.hs
[1 of 1] Compiling Main ( Main.hs, interpreted )
Main.hs:6:10:
Illegal instance declaration for `At [a] a Int'
(the Coverage Condition fails for one of the functional dependencies;
Use -XUndecidableInstances to permit this)
In the instance declaration for `At [a] a Int'
Failed, modules loaded: none.
我只是在学习函数依赖。