Angenommen, ich habe den folgenden (fehlerhaften) Code.Haskell Inaccessible Code-Fehler?
data A a b where
APure :: (A a b)
AApply :: A (A b c) c
test :: (A a b) -> a -> b
test (APure) a = a
test AApply a = undefined
GHC wird mir dann diesen Fehler geben:
Couldn't match type `b' with `A b1 b'
`b' is a rigid type variable bound by
the type signature for test :: A a b -> a -> b
Inaccessible code in
a pattern with constructor
AApply :: forall c b. A (A b c) c,
in an equation for `test'
In the pattern: AApply
In an equation for `test': test AApply a = undefined
Ist das nicht diese Fehlermeldung völlig falsch? Der Fehler hat nichts mit AApply zu tun.
Wie soll 'AApply' den allgemeinen Typ' A a b' haben, wenn Sie es bereits als 'A (A b c) c' deklarieren? Es ist, als ob du 'concat 'definieren würdest: [a] -> [b]' wie 'concat' = concat': Wie wird Haskell 'a'" down "zu' [b] '? – leftaroundabout
Ja, es ist nicht intuitiv. Vielleicht solltest du [einen Fehler melden] (http://hackage.haskell.org/trac/ghc/newticket?type=bug). –
@leftaroundabout Ich verstehe nicht wirklich, was Sie meinen, aber dieser Fall ist absolut korrekt. Informieren Sie sich über PatternMatching mit GADTs. – nulvinge