[GHC] #10097: GHC 7.11 errors on dictionary casting tricks

#10097: GHC 7.11 errors on dictionary casting tricks -------------------------------------+------------------------------------- Reporter: heisenbug | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.11 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Blocked By: Test Case: | Related Tickets: Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- I am not saying this is a bug, it just seems to mess with techniques that assume white-box knowledge of GHC's dictionary-passing internals. So, I have this function (in the `gdiff` fork I am fooling around with): {{{ iFeelDirty :: (forall ts . List f ts => f t ts -> Con f t) -> (forall ts . IsList f ts -> f t ts -> Con f t) iFeelDirty = unsafeCoerce }}} It compiles perfectly before 7.11, but now I get: {{{ src/Data/Generic/Diff/Effectful.hs:139:14: No instance for (List f ts3) The type variable `ts3' is ambiguous Relevant bindings include iFeelDirty :: (forall ts. List f ts => f t ts -> Con f t) -> forall ts. IsList f ts -> f t ts -> Con f t (bound at src/Data/Generic/Diff/Effectful.hs:139:1) In the expression: unsafeCoerce In an equation for `iFeelDirty': iFeelDirty = unsafeCoerce }}} For reference, this is the file I am looking at: https://github.com/ggreif/gdiff/blob/97b13e2dca0c35c2c53d5430f6f0700dc89938e... Looks like the old trick (also used by ekmett's `reflection` lib?) fails to deliver. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10097 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10097: GHC 7.11 errors on dictionary casting tricks -------------------------------------+------------------------------------- Reporter: heisenbug | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.11 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by goldfire): I don't like that there's been a typechecker regression here, but this doesn't seem like an outright bug to me. The one bit I'm quite unsure of is the eta-contraction... and my reasoning-about-higher-rank-eta- contracted-functions neuron seems to be enjoying the snow day here. So I'll eta-expand: {{{ iFeelDirty x = unsafeCoerce x }}} Now, I can see why your error appears. When you say `x`, GHC will try to instantiate the implicit parameters of `x`, namely `ts` and `List f ts`. But, GHC has no guidance as to what these should be, because it can't glean anything useful from `unsafeCoerce`. Some more type annotations might be helpful, as might be newtype wrappers to accurately control what you're `unsafeCoerce`ing. So, I have two conclusions: * I'm happy enough with an error in the eta-expanded version, but I agree that the eta-contracted one should probably work. * I don't think this bug shows up a problem with the dirty dictionary- casting trick. That should still be valid. It's just a typechecker behavior change, which (I believe) could be overcome with more types. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10097#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10097: GHC 7.11 errors on dictionary casting tricks -------------------------------------+------------------------------------- Reporter: heisenbug | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.11 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by simonpj): A recent (somewhat obscure) change is that GHC actually does eta-expansion to make higher-rank types match up. That is often useful (i.e. makes more programs typecheck). And really it is confusing if eta-expansion can make a difference to type checking. So I'm disinclined to "fix" this. Or at least I'd require more motivation! Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10097#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC