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たようci ~ Intc ~ [a]

于 2015-03-12T21:18:39.687 に答える