[Haskell-cafe] bug in ghci ?

Pasqualino "Titto" Assini tittoassini at gmail.com
Thu Jul 8 09:36:53 EDT 2010


Thanks for the explanation.

What I meant is not that is a bug that it recurses but rather the fact
that the compiler will accept this incomplete definition without
complaining.

This problem has bitten me twice while trying to use automatic
derivation of a data type in another file.

In my innocence I wrote:

instance Show Test

rather than

deriving  instance Show Test

I didn't notice the error as GHC seemed to be happy and then when I
tried to use it: BANG!

Very confusing.

I suppose that Haskell has spoiled me, if it compiles I assume that it
will work :-)

Best,

     titto



On 8 July 2010 14:29, Daniel Fischer <daniel.is.fischer at web.de> wrote:
> On Thursday 08 July 2010 15:20:13, Pasqualino "Titto" Assini wrote:
>> Hi,
>>
>> I just noticed that in ghci:
>>
>>
>> data Test = Test String
>>
>> instance Show Test
>>
>> show $ Test "Hello"
>>
>>
>>
>> Will result in infinite recursion.
>>
>> Is this a known bug?
>
> It's not a bug.
>
> There are default methods in Show for show in terms of showsPrec and for
> showsPrec in terms of show.
> You need to define at least one of the two to get a working Show instance,
> otherwise trying to evaluate (show stuff) will lead to infinite recursion,
> it's the same with e.g. Eq.
>
> Might be a worthwhile feature request to let the compiler emit a warning on
> every instance declaration where no method is defined.
>
>>
>>
>> Thanks,
>>
>>
>>             titto
>



-- 
Pasqualino "Titto" Assini, Ph.D.
http://quicquid.org/


More information about the Haskell-Cafe mailing list