
#9918: GHC chooses an instance between two overlapping, but cannot resolve a clause within the similar closed type family -------------------------------------+------------------------------------- Reporter: qnikst | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.3 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): Thanks for the examples in comment:7. The first example can show up the very problem I was looking for! Consider this alternate ending to the first example there (which also needs `ScopedTypeVariables`): {{{ type family Inf x where Inf () = S (Inf ()) -- pattern-match on () avoids an eager occurs- check test2 (_ :: x) = test (undefined :: Inf x) -- test2 :: x -> Int main = test2 () }}} This will, of course, evaluate to `2`. But it arguably shouldn't, because `main` boils down to a comparison between `S (S (Inf ()))` and `Inf ()`, which is impossible to determine. The extra constraint that appears in the second example (the one with closed type families) essentially says that the two type-level numbers have a well-defined relationship. When infinity is involved, they don't, giving more reliable behavior (in extreme, perverse circumstances, admittedly). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9918#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler