
#8669: Closed TypeFamilies regression ------------------------------------------------+-------------------------- Reporter: merijn | Owner: Type: bug | Status: new Priority: high | Milestone: Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result at runtime | Unknown/Multiple Test Case: | Difficulty: Blocking: | Unknown | Blocked By: | Related Tickets: ------------------------------------------------+-------------------------- Comment (by simonpj): I know why this happens. If I add the kinds to the definition, I get this: {{{ type family Restrict k (a :: k) (as :: [k]) :: Constraint where Restrict Symbol (a::Symbol) (a ': as) = (a ~ "Oops! Tried to apply a restricted type!") Restrict k (x::k) (a ': as) = Restrict x as Restrict k (x::k) '[] = () }}} The first equation only applies to types of kind `Symbol` because the RHS has an equality that forces `a :: Symbol` since `"Oops" :: Symbol`. The constraint `(Restricted (a:*) [(),Int])` can't match the first equation (because the first equation matches only things of kind `Symbol`, so it correctly chooses the second. What to do? For your (2) how about this: {{{ class Error (s::Symbol) -- No instances }}} Now `Error :: Symbol -> Constraint`, as you wanted, and you can write {{{ type instance where Restrict a (a ': as) = Error "Oops! Tried to apply a restricted type!" Restrict x (a ': as) = Restrict x as Restrict x '[] = () }}} And away you go. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8669#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler