[GHC] #13773: Types are not normalized in instance declarations

#13773: Types are not normalized in instance declarations -------------------------------------+------------------------------------- Reporter: augustss | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 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: -------------------------------------+------------------------------------- Consider the example below. It does not compile, but replacing 5*2 by 10 makes it compile. This is quite annoying since it forces me to do the normalization that the computer is really much better at doing. {{{#!hs module NatInstance where import GHC.TypeLits type N = 5 * 2 data D (n :: Nat) = D instance Show (D N) where show _ = "" }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13773 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13773: Types are not normalized in instance declarations -------------------------------------+------------------------------------- Reporter: augustss | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 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): How would you feel about {{{#!hs f :: Int -> Bool f (5*2) = True f _ = False }}} GHC rejects this. Should it? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13773#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13773: Types are not normalized in instance declarations -------------------------------------+------------------------------------- Reporter: augustss | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 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 augustss): No, I don't think GHC should accept (5*2) in a function definition. But I think it should accept my instance declaration. Here are two reasons: * GHC already does some normalization of types in instance declarations as it allows me to use type synonyms. * In the case of function definitions there is a workaround (guards), but there is no such workaround for instances. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13773#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13773: Types are not normalized in instance declarations -------------------------------------+------------------------------------- Reporter: augustss | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 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 ezyang): Related: #13262 which I think is asking for the same thing, but in a different context (it showed up in Backpack.) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13773#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13773: Types are not normalized in instance declarations -------------------------------------+------------------------------------- Reporter: augustss | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 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): Care to write a [https://github.com/ghc-proposals/ghc-proposals ghc- proposal]? I don't much like this new idea, and comment:10:ticket:13262 suggests that Simon PJ doesn't either, but perhaps others do. I think the best way to find out is to make a proposal. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13773#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13773: Types are not normalized in instance declarations -------------------------------------+------------------------------------- Reporter: augustss | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 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 augustss): The only way I know how to get around this would be to use CPP, and to me that is a serious code smell. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13773#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13773: Types are not normalized in instance declarations -------------------------------------+------------------------------------- Reporter: augustss | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 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 simonpj): It's a bit simpler than I realised. I think you are asking * That in any type pattern, the compiler should fully normalise * And then complain if any type functions remain * The evidence from this normalisation can be complete discarded. So {{{ type instance F (G Int) = blah }}} would normalise `(G Int)` to (say) `Tree [Bool]`, and then behave exactly as if you'd written {{{ type instance F (Tree [Bool]) = blah }}} If we later tried to solve a constraint involving `F (G Int)` we'd reduce the `G Int` to `Tree [Boo]]` and then (and only then) see the match with the `type instance`. I suppose that'd be straightforward, and clearly backward compatible. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13773#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13773: Types are not normalized in instance declarations -------------------------------------+------------------------------------- Reporter: augustss | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 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 Iceland_jack): Has anyone encountered more complex uses for this feature? Does it interact differently with injective families? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13773#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13773: Types are not normalized in instance declarations -------------------------------------+------------------------------------- Reporter: augustss | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 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 agree with Simon's implementation plan in comment:6 -- not hard to do. But I'm still not sold that we want to have this feature. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13773#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13773: Types are not normalized in instance declarations -------------------------------------+------------------------------------- Reporter: augustss | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 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 chshersh): I actually encountered complex use case and find this issue annoying. I'm working on library for type-safe time-units which are represented using type level rational numbers. See example here: * https://github.com/serokell/o-clock/blob/dd5026264c667feee49e2b70396a170c874... And here what I need to write in order to implement nice and pretty show instance for those time units: * https://github.com/serokell/o-clock/blob/dd5026264c667feee49e2b70396a170c874... -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13773#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13773: Types are not normalized in instance declarations -------------------------------------+------------------------------------- Reporter: augustss | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 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): Someone make a proposal, then! :) (My resistance to this has softened somewhat over time, for what that's worth.) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13773#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13773: Types are not normalized in instance declarations -------------------------------------+------------------------------------- Reporter: augustss | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 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 Artyom.Kazak): * cc: Artyom.Kazak (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13773#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC