
#10340: Type inference regression with Any -------------------------------------+------------------------------------- Reporter: akio | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 7.10.1 checker) | Keywords: Resolution: | Architecture: Operating System: Unknown/Multiple | Unknown/Multiple Type of failure: GHC rejects | Test Case: valid program | Blocking: Blocked By: | Differential Revisions: Related Tickets: | -------------------------------------+------------------------------------- Comment (by goldfire): I just took a look, and the problem here is fairly simple. I'm not sure what the right solution is, though. Here are the constraints that get to the solver: {{{ [W] $dMonadState_a1UB :: MonadState s_a1Uy[tau:1] m_a1Uz[tau:1] (CNonCanonical) [W] cobox_a1UD :: m_a1Uz[tau:1] ~ State Any (CNonCanonical) [W] cobox_a1UE :: s_a1Uy[tau:1] ~ Any (CNonCanonical) }}} In short order, we get a fuv for `Any` {{{ [W] cobox_a1UT :: Any ~ s_a1US[fuv:0] (CFunEqCan) }}} and a unification for `m_a1Uz`. {{{ setWantedTyBind m_a1Uz[tau:1] := State s_a1US[fuv:0] }}} The solver then attacks `cobox_a1UE`, which canonicalizes to {{{ [W] cobox_a1UW :: s_a1US[fuv:0] ~ s_a1Uy[tau:1] (CTyEqCan) }}} Because an fuv is on the left, no unification takes place. See `Note [Orient equalities with flatten-meta-vars on the left]` in !TcFlatten. When we then canonicalize the `MonadState` constraint, we get {{{ [W] $dMonadState_a1UB :: MonadState s_a1Uy[tau:1] (State s_a1US[fuv:0]) (CDictCan) }}} which can't get solved and is reported to the user. The "obvious" solution to me is to re-orient the `CTyEqCan` above (`cobox_a1UW`) so that unification gets the job done for us. But that `Note [Orient equalities with flatten-meta-vars on the left]` in !TcFlatten tells me not to. Another solution is to allow a Wanted to rewrite a Wanted here, but we've previously been convinced that this is a bad idea. Incidentally, I don't think this problem is at all restricted to `Any`. I haven't tested any other code, but I imagine this will bite whenever we want an instance with repeated pattern variables to match a type with irreducible type families. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10340#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler