Haskell Invalid Error Code?

Say I have the following (erroneous) code.

data A ab where APure :: (A ab) AApply :: A (A bc) c test :: (A ab) -> a -> b test (APure) a = a test AApply a = undefined 

GHC will then give me this error:

 Couldn't match type `b' with `A b1 b' `b' is a rigid type variable bound by the type signature for test :: A ab -> a -> b Inaccessible code in a pattern with constructor AApply :: forall c b. A (A bc) c, in an equation for `test' In the pattern: AApply In an equation for `test': test AApply a = undefined 

Is this error message incorrect? The error has nothing to do with AApply.

+6
source share
1 answer

Is this error message incorrect? The error has nothing to do with AApply .

Not really. This is probably an error due to which you get this error message, but not completely from the database.

Look at everything together, looking at the pieces.

 test (APure) a = a 

says we have a function

 test :: A ab -> r -> r 

Put it along with the signature

 test :: (A ab) -> a -> b 

and unify, ignoring the type error from the first equation, the type is refined to

 test :: A rr -> r -> r 

Then consider the equation

 test AApply a = undefined 

and see how this is unacceptable under the qualified type, since

 AApply :: A (A bc) c 

entail

 c ~ A bc 

if AApply were a valid first argument.

+4
source

All Articles