[GHC] #10978: Anonymous type instances

#10978: Anonymous type instances -------------------------------------+------------------------------------- Reporter: | Owner: benjamin.hodgson | Type: feature | Status: new request | Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 (Type checker) | Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- I find that commonly I write a `type family` (because it doesn't ''need'' to be a `data family`, and `type` families are more flexible), but I find myself writing `data` types for some of the instances anyway. Presently you're forced to use type synonyms for all the instances of a `type family`, even if you don't intend to refer to the type by any name other than that of the type family. I find this tiresome: {{{#!hs type family F a type instance F Char = Int newtype FBool = FBool Int type instance F Bool = FBool data FInt = A | B | ... type instance F Int = FInt }}} '''I want to write `data instance`s and `newtype instance`s for `type` families'''. These proposed constructs would introduce a new type without a name of its own (the only way to refer to it would be through the `type family`), just like the current design of `data` families. The above code would be roughly equivalent to: {{{#!hs type family F a type instance F Char = Int -- already legal newtype instance F Bool = FBool Int data instance F Int = A | B | ... }}} I call this idea ''anonymous type instances'' but I'm open to suggestions for a snappier name. Going the other way (writing a `type instance` for a `data family`) would remain illegal under this proposal. {{{#!hs data family G a type instance G Char = Int -- still illegal }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10978 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10978: Anonymous type instances -------------------------------------+------------------------------------- Reporter: benjamin.hodgson | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 7.8.3 checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by benjamin.hodgson): * version: 7.10.2 => 7.8.3 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10978#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10978: Anonymous type instances -------------------------------------+------------------------------------- Reporter: benjamin.hodgson | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 7.8.3 checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by goldfire): I don't see any structural problems with this proposal, but I think it doesn't pay its way. It would be yet another wrinkle to already-quite- complex type family story. And, I think more problematically, this approach would prohibit you to write class instances for these new datatypes. Because type families are not injective and generative, you cannot specify a type family in a class instance head. But with these "anonymous type instances", there would be no other way to name the datatype, so you've effectively made datatypes for which no instances can exist. (Except maybe by `deriving`. But you'd even be prohibited from standalone-deriving.) So I'm skeptical, even though I do think the underlying idea is sound. If you really want this, find a loud chorus of people who think likewise. :) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10978#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10978: Anonymous type instances -------------------------------------+------------------------------------- Reporter: benjamin.hodgson | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 7.8.3 checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by nomeata):
Because type families are not injective and generative, you cannot specify a type family in a class instance head.
Would it be possible to allow type families in instance heads if they reduce to something that is allowed, akin to `TypeSynonymInstances`? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10978#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10978: Anonymous type instances -------------------------------------+------------------------------------- Reporter: benjamin.hodgson | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 7.8.3 checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by goldfire): Replying to [comment:3 nomeata]:
Because type families are not injective and generative, you cannot specify a type family in a class instance head.
Would it be possible to allow type families in instance heads if they reduce to something that is allowed, akin to `TypeSynonymInstances`?
This has been suggested before but was discarded as a bad idea. There's some useful conversation on the ticket... but I can't find the ticket! Short story: this would be akin to allowing term-level function definitions like `foo (not True) = 5`. If we reduce `not True`, we'll get `False`, and this definition is perfectly sound. But it's terrible, nonetheless. If you could find the ticket, I'd be grateful. But I really did try. :( -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10978#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC