[GHC] #14260: Type family in instance signature confuses GHC

#14260: Type family in instance signature confuses GHC -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.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: -------------------------------------+------------------------------------- This works: {{{#!hs class F a where type T a u :: T a -> a -> a newtype W a = W a instance F (W a) where type T (W a) = T a u = undefined instance F () where type T () = T (W ()) u _ = undefined }}} Remove one argument to `u` and you get {{{#!hs • Reduction stack overflow; size = 201 When simplifying the following type: T (W ()) Use -freduction-depth=0 to disable this check (any upper bound you could choose might fail unpredictably with minor updates to GHC, so disabling the check is recommended if you're sure that type checking should terminate) • In the expression: undefined In an equation for ‘u’: u = undefined In the instance declaration for ‘F ()’ }}} It is also not accepted to {{{#!hs u :: T (W ()) -> () -> () u _ = id @() }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14260 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14260: Type family in instance signature confuses GHC -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.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 RyanGlScott): You //almost// pulled the wool over my eyes and made me think that GHC was infinitely looping without provocation. But then I realized that you conveniently left off some important language extensions needed to compile this code :) {{{#!hs {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE UndecidableInstances #-} }}} The fact that you have to enable `UndecidableInstances` should be an important clue as to what's happening. You have these two type family instances: {{{#!hs type T () = T (W ()) type T (W a) = T a }}} So if you have `u :: T (W ()) -> () -> (); u = undefined`, GHC attempts to generalize the type `T (W ()) -> () -> ()`, and thus reduce `T (W ())`. But that means: {{{ T (W ()) -> T () -> T (W ()) -> ... }}} Bam. Stack overflow. So I claim there is no bug here, only reckless use of `UndecidableInstances` and type families. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14260#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14260: Type family in instance signature confuses GHC -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 8.2.1 Resolution: invalid | 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 RyanGlScott): * status: new => closed * resolution: => invalid -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14260#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC