## #11408 closed bug (fixed)

# Delicate solve order

Reported by: | simonpj | Owned by: | |
---|---|---|---|

Priority: | normal | Milestone: | 8.0.1 |

Component: | Compiler | Version: | 7.10.3 |

Keywords: | Cc: | dimitris, goldfire | |

Operating System: | Unknown/Multiple | Architecture: | Unknown/Multiple |

Type of failure: | None/Unknown | Test Case: | indexed-types/should_compile/T11408 |

Blocked By: | Blocking: | ||

Related Tickets: | Differential Rev(s): | ||

Wiki Page: |

### Description (last modified by )

Should we successfully infer a type for `f`

:

f x = [h x, [x]]

assuming `h :: forall b. F b -> b`

?

Assuming `(x::alpha)`

and we instantiate `h`

at `beta`

, we get the constraints

(1) beta ~ [alpha] from the list [h x, [x]] (2) alpha ~ F beta from the call of h

Now if we happen to unify the constraint (1) first, `beta := [alpha`

], then we successfully infer

f :: forall a. (a ~ F [a]) => a -> [[a]]

But if we unify the constraint (2) first, `alpha := F beta`

, we get

f :: forall b. (b ~ [F b]) => F b -> [[F b]]

which looks ambiguous. It isn't ambiguous, in fact, but the solver has to work hard to prove it. It actually succeeds here, but in the more complicated example in `indexed-types/should_compile/IndTypesPerfMerge`

, it didn't. There the function `merge`

has (a slightly more complicated form of) this delicately-balanced situation.

But see `Note [Orientation of equalities with fmvs]`

in `TcFlatten`

for why we don't defer solving (2).

### Change History (5)

### comment:1 Changed 4 years ago by

### comment:2 Changed 4 years ago by

Description: | modified (diff) |
---|---|

Resolution: | → fixed |

Status: | new → closed |

Test Case: | → indexed-types/should_compile/T11408 |

### comment:3 Changed 4 years ago by

Status: | closed → merge |
---|

### comment:4 Changed 4 years ago by

Status: | merge → closed |
---|

This was merged to `ghc-8.0`

as 9f466c8841c7ddda84951c9e3470540d25d0bfdb.

### comment:5 Changed 4 years ago by

Milestone: | → 8.0.1 |
---|

**Note:**See TracTickets for help on using tickets.

In 9308c736/ghc: