[GHC] #8828: allow fully applied type families in instance heads

#8828: allow fully applied type families in instance heads ------------------------------------+------------------------------------- Reporter: aavogt | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.2 Keywords: | Operating System: Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: None/Unknown Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | ------------------------------------+------------------------------------- Hi, it would be nice if the following example were acceptable: {{{ {-# LANGUAGE FlexibleInstances, TypeFamilies, TypeSynonymInstances #-} data X a = X a type family TX a type instance TX a = X a instance Show (TX Int) }}} But ghc complains that it cannot substitute the instance of TX: {{{ ts.hs:6:10: Illegal type synonym family application in instance: TX Int In the instance declaration for ‛Show (TX Int)’ }}} A more practical (but not self-contained) example involving extensible records looks http://lpaste.net/100436 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8828 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8828: allow fully applied type families in instance heads -------------------------------------+------------------------------------ Reporter: aavogt | Owner: goldfire Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by simonpj): * owner: => goldfire Comment: Seems very reasonable. The rule would be this: you normalise the instance type, and check that there are no remaining type family calls. After all, with `-XFlexibleInstances` you can use type synonyms in instance heads, and this is just an extension of the same idea. c.f. http://www.haskell.org/ghc/docs/latest/html/users_guide/type-class- extensions.html#flexible-instance-head Richard will work on this in due course. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8828#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8828: allow fully applied type families in instance heads -------------------------------------+------------------------------------ Reporter: aavogt | Owner: goldfire Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by goldfire): I've thought about this ticket some, and I think implementing this idea is a move in the wrong direction. Implementing this idea feels quite like allowing function applications in patterns. For example, how would we feel about this: {{{ foo :: Bool -> Int foo True = 1 foo (not True) = -1 }}} With some engineering, there is no reason that we couldn't accept a definition such as the one above. After all, `not True` is fully applied to constants and can be reduced to `False`. We can pretend that there is a TH-like stage restriction (somewhat like Simon's quite valid dependency concerns in comment:1) to prevent infinite regress. We can even check to make sure that the pattern match is complete. Yet, this definition smells like rotten eggs to me. Should it be different at the type level? I, personally, think not. What it seems we really want here are ''type pattern synonyms''. Pattern synonyms allow a richer syntax "on the left of an `=`", which is what we want here in types. It so happens that, currently, type patterns are syntactically just types that don't mention type families, but if we separate out a type pattern syntax from a type syntax (which I think is a good idea -- they are different!) then the idea of type families "on the left" becomes even more suspicious and type pattern synonyms make more sense. So, instead of implementing the idea proposed here, I would rather think about type pattern synonyms. How are these related to term pattern synonyms? How would we declare them? Can they be promoted to kinds? etc. What do others think here? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8828#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8828: allow fully applied type families in instance heads -------------------------------------+------------------------------------ Reporter: aavogt | Owner: goldfire Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by simonpj): I rather agree with Richard here. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8828#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8828: Type pattern synonyms -------------------------------------+------------------------------------- Reporter: aavogt | Owner: Type: feature | Status: new request | Milestone: ⊥ Priority: normal | Version: 7.6.2 Component: Compiler | Keywords: Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Project (more Unknown/Multiple | than a week) Type of failure: | Blocked By: None/Unknown | Related Tickets: Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by goldfire): * owner: goldfire => * difficulty: Unknown => Project (more than a week) * milestone: => ⊥ Comment: According to the discussion above, this is really a new feature that needs to be designed and implemented. I'm releasing ownership, though I can conceive of a future where I take this on again. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8828#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC