[Haskell-cafe] question about GADT and deriving automatically a Show instance

Adam Gundry adam.gundry at strath.ac.uk
Fri May 17 17:44:19 CEST 2013


Hi TP,

On 17/05/13 15:32, TP wrote:
| [...]
|
| So I modify my code by removing "deriving Show", and adding the line:
| ----------------------------
| instance Show (Person gender)
| ----------------------------
|
| But now, I obtain:
|
| $ runghc test_show.hs
| GHC stack-space overflow: current limit is 536870912 bytes.
| Use the `-K<size>' option to increase it.
|
| Why (I imagine this is because there is an infinite loop in the
construction
| of the show function)? Is there any workaround?

To use standalone deriving, you need to write

> deriving instance Show (Person gender)

and everything will work fine. By writing

> instance Show (Person gender)

you are instead giving an instance with no methods, and the default
methods in the Show class contain a loop (so that one can define either
show or showsPrec).

Hope this helps,

Adam

P.S. You might like to check out the new DataKinds extension, which
would allow Male and Female to be data constructors rather than type
constructors.


-- 
The University of Strathclyde is a charitable body, registered in
Scotland, with registration number SC015263.



More information about the Haskell-Cafe mailing list