#7099: 'instance Show' results in stack overflow
----------------------------+-----------------------------------------------
  Reporter:  pl             |          Owner:                
      Type:  bug            |         Status:  closed        
  Priority:  normal         |      Milestone:                
 Component:  Compiler       |        Version:  7.4.2         
Resolution:  invalid        |       Keywords:                
        Os:  Linux          |   Architecture:  x86_64 (amd64)
   Failure:  Runtime crash  |     Difficulty:  Unknown       
  Testcase:                 |      Blockedby:                
  Blocking:                 |        Related:                
----------------------------+-----------------------------------------------
Changes (by pcapriotti):

  * status:  new => closed
  * difficulty:  => Unknown
  * resolution:  => invalid


Old description:

> When I load the code below in ghci and run 'create :: C' the execution
> ends after a while with a stack overflow.  However, when I delete the
> line 'instance Show C' and erase the '--' before 'deriving (Show)' the
> command 'create :: C' delivers a 'C' as I would expect it.
>
> > module Main where[[BR]]
> >[[BR]]
> > data C = C --deriving (Show)[[BR]]
> >[[BR]]
> > instance Show C[[BR]]
> >[[BR]]
> > class T m where[[BR]]
> >       create :: m [[BR]]
> >
> > instance T C where[[BR]]
> >       create = C[[BR]]

New description:

 When I load the code below in ghci and run 'create :: C' the execution
 ends after a while with a stack overflow.  However, when I delete the line
 'instance Show C' and erase the '--' before 'deriving (Show)' the command
 'create :: C' delivers a 'C' as I would expect it.

 {{{
 module Main where

 data C = C --deriving (Show)[[BR]]

 instance Show C

 class T m where
      create :: m

 instance T C where
      create = C
 }}}

--

Comment:

 This is expected behavior. The `Show` class defines defaults for all its
 methods, and the `instance Show C` line creates an empty instance where
 all the defaults are used, resulting in a non-terminating definition of
 `show`.

 If for some reason you want a standalone `deriving` statement, use
 `-XStandaloneDeriving` and

 {{{
 deriving instance Show C
 }}}

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7099#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to