debug icon indicating copy to clipboard operation
debug copied to clipboard

Ovelapping Show instances for monadic values

Open LukaHorvat opened this issue 8 years ago • 3 comments

Got another one for you.

Try this:

debug [d|
    f :: Int -> m Int
    f _ = undefined
    |]

You get an Overlapping instances for Show (m0 Int) error. This can be "fixed" by adding a instance {-# INCOHERENT #-} Show (m Int) somewhere because the arcane rules of instance selection pick this one.

I'm not really sure what you can really do about this.

LukaHorvat avatar Dec 19 '17 09:12 LukaHorvat

Thanks! I think the Show a instance I added is proving actively harmful - it works well in the same module, but is of no use in a different module, where it must live in the Debug library. Or I could inject a Show, but then you probably get other nasty problems.

Perhaps however _ => is enough to have GHC infer whatever Show instances it needs? Will try that tonight - Show (m Int) would be ideal.

ndmitchell avatar Dec 19 '17 13:12 ndmitchell

I went with _ => and it's vastly simpler - great news!

ndmitchell avatar Dec 25 '17 10:12 ndmitchell

I had to comment out the type2 example, so that still needs work.

ndmitchell avatar Dec 29 '17 00:12 ndmitchell