Ticket #4089 (closed bug: invalid)

Opened 3 years ago

Last modified 3 years ago

Empty Show instance + phantom type + GHCi = out of memory

Reported by: japple Owned by:
Priority: normal Milestone:
Component: GHCi Version: 6.12.2
Keywords: Cc:
Operating System: Linux Architecture: x86
Type of failure: GHCi crash Difficulty:
Test Case: Blocked By:
Blocking: Related Tickets:

Description

module ShowMemory where

data M a = M

instance Show a => Show (M a)

Load in GHCi, type "M" and then enter at the prompt.

It kills all my memory. I have no .ghci

Change History

Changed 3 years ago by pumpkin

I get the same behavior on Mac OS 10.5, using 6.12.1, also no .ghci.

Changed 3 years ago by pumpkin

This is just like doing

instance Eq M

and having a call to (==) loop between (/=) and (==) infinitely. show calls shows which calls showsPrec which calls show. I don't think this is a bug.

Changed 3 years ago by igloo

  • status changed from new to closed
  • resolution set to invalid

pumpkin is right: The default Show instance includes

show x          = shows x ""
showsPrec _ x s = show x ++ s

and

shows           =  showsPrec zeroInt

So we have

show M = shows M "" = showsPrec zeroInt M "" = show M ++ ""
Note: See TracTickets for help on using tickets.