Skip to content

Bad location for violation of functional dependency

The code below produces an error message which gives no
clue
that the actual source of the error is on the line
marked L3
(pointing instead to L1 and L2):

  .../BadWarningLoc.hs:1:0:
    Couldn't match `S Z' against `Z'
      Expected type: S Z
      Inferred type: Z
    When using functional dependencies to combine
      MinMax a Z Z a,
	arising from the instance declaration at
.../BadWarningLoc.hs:10:0
      MinMax (S Z) Z _c d,
	arising from use of `t' at .../BadWarningLoc.hs:21:8-10

With the type signature, marked L4, uncommented the error
message does indeed point to the culprit, L3.

(With L3 commented-out, the code compiles.)

	thanks,
	mike

{-# OPTIONS_GHC -fglasgow-exts
-fallow-undecidable-instances #-}
data Z		= Z
data S a	= S a

n0	= Z
n1	= S n0

class MinMax a b c d | a b -> c d, a c d -> b, b c d -> a
instance MinMax Z Z Z Z				
instance MinMax a Z Z a	 -- L1: wrongly flagged as
error src.
instance MinMax Z b Z b				
instance MinMax a b c d => MinMax (S a) (S b) (S c) (S d)

class Extend a b  where extend :: a -> b ->  b
instance Extend Z b where  Z `extend` b = b
instance MinMax a b _c b  => Extend a b where _a
`extend` b = b

t	:: MinMax a b _c d => a -> b -> d
t _ _	= (undefined :: d)

t1 = n1 `t` n0	    -- L2
t2 = n1 `extend` n0 -- L3: uncommenting just this line
produces
		    --	   an error message pointing at L1 and L2
		    --	   with no mention of the real culprit, L3.
--t1	:: S Z	    -- L4: uncommenting this and L3 produces an
		    --	error message rightly pointing at L2 and L3.
Trac metadata
Trac field Value
Version 6.4
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution ResolvedFixed
Component Compiler (Type checker)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information