[GHC] #8026: DatatypeContexts should be fixed, not deprecated

#8026: DatatypeContexts should be fixed, not deprecated -----------------------------+---------------------------------------------- Reporter: gidyn | Owner: Type: feature request | Status: new Priority: normal | Component: Compiler Version: 7.6.3 | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: None/Unknown | Blockedby: Blocking: | Related: -----------------------------+---------------------------------------------- To borrow an example from the [http://hackage.haskell.org/trac/haskell- prime/wiki/NoDatatypeContexts prime wiki page], the following code fails to compile: {{{ data Eq a => Foo a = Foo a isEq :: Foo a -> Foo a -> Bool isEq (Foo x) (Foo y) = x == y }}} We have to tell the compiler that {{{Eq a => Foo a}}} in {{{isEq}}}, even though this is part of the data type's definition. Furthermore, {{{ getVal :: Foo a -> a getVal (Foo x) = x }}} will also fail because of the missing constraint, even though it isn't used in the function's definition. Rather than just deprecating the {{{DatatypeContexts}}} extension, it should be "fixed" to remember the context wherever the data type is used. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/8026 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8026: DatatypeContexts should be fixed, not deprecated -------------------------------+-------------------------------------------- Reporter: gidyn | Owner: Type: feature request | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: wontfix | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: None/Unknown | Difficulty: Unknown Testcase: | Blockedby: Blocking: | Related: -------------------------------+-------------------------------------------- Changes (by simonpj): * status: new => closed * difficulty: => Unknown * resolution: => wontfix Comment: We already have a notation for the "fixed" version: {{{ data Foo a where Foo :: Eq a => a -> Foo a }}} Moreover, this is arguably the "right" notation because you can vary the context per-constructor: {{{ data Bar a where Bar1 :: Eq a => a -> Bar a Bar2 :: (Ix a, Show a) => a -> a -> Bar a }}} You may want to make suggesitons to the Haskell Prime group, but I'm disinclined to add yet new behaviour to GHC when an existing solution does the job. Simon -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/8026#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8026: DatatypeContexts should be fixed, not deprecated -------------------------------+-------------------------------------------- Reporter: gidyn | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: None/Unknown | Difficulty: Unknown Testcase: | Blockedby: Blocking: | Related: -------------------------------+-------------------------------------------- Changes (by gidyn): * status: closed => new * resolution: wontfix => Comment: This only works when pattern matching on the constructor, and GADTs are no different to classical data types for this. Functions which uses a {{{Foo}}} without pattern matching will require a redundant type context in either case. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/8026#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8026: DatatypeContexts should be fixed, not deprecated -------------------------------+-------------------------------------------- Reporter: gidyn | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: None/Unknown | Difficulty: Unknown Testcase: | Blockedby: Blocking: | Related: -------------------------------+-------------------------------------------- Comment(by gidyn): This might be a better example: {{{ data Eq a => Pair a = Pair {x::a, y::a} equal :: Pair a -> Bool equal pair = (x pair) == (y pair) }}} Is there any way you can avoid a redundant {{{Eq a =>}}} in the definition of {{{equal}}}, without adding a redundant pattern match? -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/8026#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8026: DatatypeContexts should be fixed, not deprecated -------------------------------+-------------------------------------------- Reporter: gidyn | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: None/Unknown | Difficulty: Unknown Testcase: | Blockedby: Blocking: | Related: -------------------------------+-------------------------------------------- Changes (by gidyn): * cc: gideon@… (added) -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/8026#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8026: DatatypeContexts should be fixed, not deprecated -------------------------------+-------------------------------------------- Reporter: gidyn | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: None/Unknown | Difficulty: Unknown Testcase: | Blockedby: Blocking: | Related: -------------------------------+-------------------------------------------- Comment(by gidyn): Replying to [comment:1 simonpj]:
You may want to make suggesitons to the Haskell Prime group
Haskell Prime expect extensions to be implemented in a compiler first, so that would have to come if/after it's been implemented here. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/8026#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8026: DatatypeContexts should be fixed, not deprecated -------------------------------+-------------------------------------------- Reporter: gidyn | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: None/Unknown | Difficulty: Unknown Testcase: | Blockedby: Blocking: | Related: -------------------------------+-------------------------------------------- Comment(by isaacdupree): In your example, do any of these three expressions typecheck? (note: functions are not in Eq) {{{ Pair id id undefined :: Pair (()->()) equal undefined }}} -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/8026#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8026: DatatypeContexts should be fixed, not deprecated -------------------------------+-------------------------------------------- Reporter: gidyn | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: None/Unknown | Difficulty: Unknown Testcase: | Blockedby: Blocking: | Related: -------------------------------+-------------------------------------------- Comment(by monoidal): @gidyn: What would the type of `x` be in your example? You probably want `x` to ''introduce'' the validity of constraint `Eq a`. So the type would be somewhat dual to `Eq a => Pair a -> a`: using it would prove the constraint `Eq a`, rather than requiring evidence for the constraint. Something like `Pair a -> (Eq a; a)`. It seems to me this change would complicate the type system a lot, while the benefits are rather doubtful. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/8026#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8026: DatatypeContexts should be fixed, not deprecated -------------------------------+-------------------------------------------- Reporter: gidyn | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: None/Unknown | Difficulty: Unknown Testcase: | Blockedby: Blocking: | Related: -------------------------------+-------------------------------------------- Comment(by gidyn): Replying to [comment:7 monoidal]: The generated getter should have type {{{x :: Eq a => Foo a => a}}} - nothing complicated about it, unless I missed your point. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/8026#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8026: DatatypeContexts should be fixed, not deprecated -------------------------------+-------------------------------------------- Reporter: gidyn | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: None/Unknown | Difficulty: Unknown Testcase: | Blockedby: Blocking: | Related: -------------------------------+-------------------------------------------- Comment(by monoidal): @gidyn: You probably meant `x :: Eq a => Pair a -> a`. Consider isaacdupree's `equal (undefined :: Pair (() -> ()))`. Surely this should be legal: `undefined` inhabits every type. Yet attempting to evaluate it leads to using `==` from `Eq (() -> ())` which does not exist. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/8026#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC