[GHC] #9838: PatternSynonyms and ConstraintKinds should not be required at the use site.

#9838: PatternSynonyms and ConstraintKinds should not be required at the use site. -------------------------------------+------------------------------------- Reporter: ekmett | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.3 Keywords: | Operating System: Architecture: Unknown/Multiple | Unknown/Multiple Difficulty: Unknown | Type of failure: Blocked By: | None/Unknown Related Tickets: | Test Case: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Currently both PatternSynonyms and ConstraintKinds have to be enabled at the usage site, not just at the construction site. This pretty much ensures that they'll never be used to 'clean up' or virtualize an existing API, because switching to pattern synonyms for constructors or switching a 'class alias' to a type synonym immediately break all users. For instance right now, as a user I universally write {{{ class (Foo a, Bar a) => Baz a instance (Foo a, Bar a) => Baz a }}} rather than {{{ type Baz a = (Foo a, Bar a) }}} because the former gives a better user experience and I can pay all the extensions needed for it at the definition site, rather than have all my users pay them at the use site. I'd like to propose that the language extensions for these two cases, `PatternSynonyms` and `ConstraintKinds` only be required at the definition site, rather than at the use site. The former is definitely needed at the definition site because of the new syntax, but unless you explicitly re-export a pattern, no syntax changes at the usage site. This would also be more consistent with existing policies for other extensions: We don't require users to turn on FunctionalDependencies to get the benefit of functional dependencies, or to turn on MultiParamTypeClasses to use an MPTC, merely to define them. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9838 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9838: PatternSynonyms and ConstraintKinds should not be required at the use site. -------------------------------------+------------------------------------- Reporter: ekmett | Owner: Type: feature | Status: new request | Milestone: Priority: normal | Version: 7.8.3 Component: Compiler | Keywords: Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: | Related Tickets: None/Unknown | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by simonpj): * cc: cactus, goldfire (added) Comment: I agree 100%. Requiring a language extension flag at the definition but not the use is definitely GHC's standard policy. (Eg overlapping instances.) I understand about pattern synonyms. Gergo, could you look at this? I don't understand about constraint kinds. Can you give a concrete example? Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9838#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9838: PatternSynonyms and ConstraintKinds should not be required at the use site. -------------------------------------+------------------------------------- Reporter: ekmett | Owner: Type: feature | Status: new request | Milestone: Priority: normal | Version: 7.8.3 Component: Compiler | Keywords: Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: | Related Tickets: None/Unknown | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by hvr): Btw, here's a related [https://groups.google.com/forum/#!msg/haskell-core- libraries/q9H-QlL_gnE/WUSqogVY89QJ CLC posting of mine] showing a concrete use-case for pattern-synonyms which is hindered by requiring `-XPatternSynonyms` at the usage-site... -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9838#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9838: PatternSynonyms and ConstraintKinds should not be required at the use site. -------------------------------------+------------------------------------- Reporter: ekmett | Owner: Type: feature | Status: new request | Milestone: Priority: normal | Version: 7.8.3 Component: Compiler | Keywords: Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: | Related Tickets: None/Unknown | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by ekmett): Re: `ConstraintKinds` You can construct a fairly simple example where someone wants to have something that they can put in a context that, say, offered both `Applicative m` and `Monad m` as a stopgap for the AMP. {{{ class (Applicative m, Monad m) => ApplicativeMonad m instance (Applicative m, Monad m) => ApplicativeMonad m }}} as opposed to {{{ type ApplicativeMonad m = (Applicative m, Monad m) }}} Similar hack-arounds are common among folks who see `Semigroup` as a superclass of `Monoid`, but who have to workaround the lack of a superclass relationship. These sorts of synonyms are actually quite common, I think I first used it back around 2006 when I first found haskell: e.g. TXOr in http://hackage.haskell.org/package/type-int-0.5.0.2/docs/src/Data-Type- Boolean.html#TXOr is an instance of this pattern, but it was a well known pattern long before the time I started using it. The former requires "scarier" extensions than the latter for the person constructing it, but the latter requires an extension to be turned on by the user, hoisting the library designer upon the horns of a dilemma, do they take the burden upon themselves and use "the old way" of thinking about these things or do they make every user turn on `ConstraintKinds`? Mind you it still isn't a clean decision even with this change, because the former still works better in some scenarios, e.g. you can pass the class/instance version of `ApplicativeMonad` as an argument that expects something of kind `(* -> *) -> Constraint`, but the type synonym version cannot be partially applied, but these are the kinds of thoughts users of `ConstraintKinds` wind up thinking. Almost all of my current real world examples of this are now entangled with this secondary concern: e.g. https://github.com/ekmett/hask/blob/master/src/Hask/Category.hs#L93 gets partially applied in https://github.com/ekmett/hask/blob/master/src/Hask/Category.hs#L283 https://github.com/ekmett/hask/blob/master/src/Hask/Category/Polynomial.hs#L... gets partially applied in https://github.com/ekmett/hask/blob/master/src/Hask/Category/Polynomial.hs#L... etc. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9838#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9838: PatternSynonyms and ConstraintKinds should not be required at the use site. -------------------------------------+------------------------------------- Reporter: ekmett | Owner: Type: feature | Status: new request | Milestone: Priority: normal | Version: 7.8.3 Component: Compiler | Keywords: Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: | Related Tickets: None/Unknown | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by goldfire): Here's a test case for the !ConstraintKinds problem: {{{ {-# LANGUAGE ConstraintKinds #-} module A where type EqShow a = (Eq a, Show a) }}} {{{ module B where import A foo :: EqShow a => a -> String foo x = show x ++ show (x == x) }}} Compiling yields {{{ B.hs:5:8: Illegal tuple constraint: EqShow a (Use ConstraintKinds to permit this) In the type signature for ‘foo’: foo :: EqShow a => a -> String }}} I'd love to see this fix get in for 7.10, but I won't have a chance to work on this before the (new) freeze date on Friday. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9838#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9838: PatternSynonyms and ConstraintKinds should not be required at the use site. -------------------------------------+------------------------------------- Reporter: ekmett | Owner: Type: feature | Status: new request | Milestone: Priority: normal | Version: 7.8.3 Component: Compiler | Keywords: Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: | Related Tickets: None/Unknown | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by carter): What modules would need be touched to get that in for 7.10? (if its not too deep a dive, i can try to make time tomorrow?) Theres some refinements Ed still wants me to do on the prefetch work, but I think he and i would both agree that getting this into 7.10 has greater impact -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9838#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9838: PatternSynonyms and ConstraintKinds should not be required at the use site.
-------------------------------------+-------------------------------------
Reporter: ekmett | Owner:
Type: feature | Status: new
request | Milestone:
Priority: normal | Version: 7.8.3
Component: Compiler | Keywords:
Resolution: | Architecture: Unknown/Multiple
Operating System: | Difficulty: Unknown
Unknown/Multiple | Blocked By:
Type of failure: | Related Tickets:
None/Unknown |
Test Case: |
Blocking: |
Differential Revisions: |
-------------------------------------+-------------------------------------
Comment (by Dr. ERDI Gergo

#9838: PatternSynonyms and ConstraintKinds should not be required at the use site. -------------------------------------+------------------------------------- Reporter: ekmett | Owner: Type: feature | Status: new request | Milestone: Priority: normal | Version: 7.8.3 Component: Compiler | Keywords: Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: | Related Tickets: None/Unknown | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by cactus): I've removed the need for turning on `PatternSynonyms` just to use pattern synonyms. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9838#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9838: PatternSynonyms and ConstraintKinds should not be required at the use site. -------------------------------------+------------------------------------- Reporter: ekmett | Owner: Type: feature | Status: new request | Milestone: Priority: normal | Version: 7.8.3 Component: Compiler | Keywords: Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: | Related Tickets: None/Unknown | Test Case: | patsyn/should_compile/ImpExp_Imp, | polykinds/T9838 | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by simonpj): * testcase: => patsyn/should_compile/ImpExp_Imp, polykinds/T9838 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9838#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9838: PatternSynonyms and ConstraintKinds should not be required at the use site.
-------------------------------------+-------------------------------------
Reporter: ekmett | Owner:
Type: feature | Status: new
request | Milestone:
Priority: normal | Version: 7.8.3
Component: Compiler | Keywords:
Resolution: | Architecture: Unknown/Multiple
Operating System: | Difficulty: Unknown
Unknown/Multiple | Blocked By:
Type of failure: | Related Tickets:
None/Unknown |
Test Case: |
patsyn/should_compile/ImpExp_Imp, |
polykinds/T9838 |
Blocking: |
Differential Revisions: |
-------------------------------------+-------------------------------------
Comment (by Simon Peyton Jones

#9838: PatternSynonyms and ConstraintKinds should not be required at the use site. -------------------------------------+------------------------------------- Reporter: ekmett | Owner: Type: feature | Status: closed request | Milestone: Priority: normal | Version: 7.8.3 Component: Compiler | Keywords: Resolution: fixed | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: | Related Tickets: None/Unknown | Test Case: | patsyn/should_compile/ImpExp_Imp, | polykinds/T9838 | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by simonpj): * status: new => closed * resolution: => fixed Comment: Good. Done. Tests added. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9838#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC