Well you may say that it's a mistake, but
that's the behaviour specified by the language report (as you request).
The default methods for show and showsprec are each
defined in terms of each other.
If you specify one or the other, you're fine. If you specify
neither you get an inifiniite loop.
It's hard for the compiler to be sure when you've done this.
Even a termination analysis may not work becuase it's hard
to distinguish divergence from (error "urk").
But I agree it's rather counterintuitive. I'm just not sure
how to improve matters
Incidentally,there *is* a way to derive the standard instances
data A = A deriving( Show )
Simon
| -----Original Message-----
| From: Michael Marte [mailto:[EMAIL PROTECTED]]
| Sent: 30 August 2000 08:05
| To: [EMAIL PROTECTED]
| Cc: Michael Marte
| Subject: Undefined methods: bad behaviour
|
|
| Hi,
|
| look at the following example:
|
|
| module Main where
|
| data A = A
| instance Show A
|
| main = do print A
|
|
| This program does not work, it just loops eating all the heap
| (ghc-4.08-1). With respect to the Haskell 98 Report (4.3.2), this
| behaviour is ok. ("If no binding is given for some class
| method then the
| corresponding default class method in the class declaration
| is used (if
| present); if such a default does not exist then the class
| method of this
| instance is bound to undefined and no compile-time error results.")
| However, the looping behaviour is not very helpful. Why not print a
| message like "Calling undefined class method type.class.method"?
|
| (In my eyes, the rule cited above is nonsense. This default
| behaviour is
| not intuitive. Why not derive the standard instances? In a large
| project, each module may need its own instances. Some modules require
| special stuff, for others the default instances might be
| sufficient. For
| the latter modules, it would be *very helpful* to have some means to
| derive the standard instances. AFAIK, ghc-4.06 did it the way
| I like it,
| but in ghc-4.07 this was changed and all my programs were broken. Is
| there any reason for doing it the way prescribed by the
| Haskell Report?)
|
| Michael
|
|
|
|