0
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.

我只是在学习函数依赖。

4

1 回答 1

0

正如 dave4420 在评论中所写:“i -> c位说知道我告诉你是什么c,但是你说如果i ~ Int那么c ~ [a]对于任何 a”。

于 2015-03-12T21:18:39.687 回答