
I can understand "while(true) { }" producing an endless loop. Can you explain how the code I entered is interpreted to mean an unending cycle? Furthermore most systems can be interrupted, even when in a tight while(true) { } loop. In the example I gave, it seems that GHCi cannot be interrupted. (When I try it on some machines I get an out-of-memory error, but it still(!) can't be interrupted.) I think GHCi is wonderful software. But I doubt that anyone would claim that it's bug-free. I'm surprised that there is so much resistance to acknowledging what appears to be a bug. Why not just fix it? To review, how should this be interpreted? data Test = Test instance Show Test -- The problem occurs even without "where"
Test
What interpretation justifies GHCi going into an uninterruptable state at
this point?
*
-- Russ *
On Tue, Nov 16, 2010 at 9:00 AM,
On 16 November 2010 12:17, Thomas Davie
wrote: GHCi's job is to run the code you enter.
Likewise, in many other languages when you write the following you'll get an infinite rule. And it just compiles (or gets interpreted) fine.
while(true) { }
Just another perspective.
Ozgur

Hi Russ,
On 16 November 2010 18:52, Russ Abbott
I think GHCi is wonderful software. But I doubt that anyone would claim that it's bug-free. I'm surprised that there is so much resistance to acknowledging what appears to be a bug. Why not just fix it? To review, how should this be interpreted?
data Test = Test instance Show Test -- The problem occurs even without "where"
Test
What interpretation justifies GHCi going into an uninterruptable state at this point? -- Russ
It's not a bug but it should give a warning. The reason why this compiles is that there are default implementations for all members of the Show class. Unfortunately, they are defined in terms of them selves (show uses shows uses showPrec uses show). You have to define at least one to not get caught in an endless loop. But there is no way for GHC to know that. Regards, Tobias

It seems to me that there is a possibility we could reify some information that is traditionally specified in the documentation: that is, what functions must be defined by a minimal instance, which could then give GHC enough information to give meaningful warnings if not all functions for a minimal instance are proviced. Edward

On 16 November 2010 19:17, Edward Z. Yang
It seems to me that there is a possibility we could reify some information that is traditionally specified in the documentation: that is, what functions must be defined by a minimal instance, which could then give GHC enough information to give meaningful warnings if not all functions for a minimal instance are proviced.
One could use a compiler pragma the defines possible sets of minimal definitions, e.g. {-# MINIMAL_DEF Num ((+),(*),abs,signum,fromInteger,(-)), ((+),(*),abs,signum,fromInteger,negate) #-} one could even add logical notation, like: {-# MINIMAL_DEF Num ((+), (*), abs, signum, fromInteger, (-) || negate) #-}

A few answers back, Matthew Coolbeth wrote,
(show v) where v is of type Test will evaluate to (showPrec v), and that
(showPrec v) will evaluate to (show v). It should be clear that this is a
cyclic evaluation that will not terminate.
Presumably that was intentional. But why was that necessary? It seems like
strange coding. Furthermore, why isn't
instance Show Test
interpreted to mean
data Test = Test deriving (Show)
*
-- Russ *
On Tue, Nov 16, 2010 at 10:27 AM, Tobias Brandt
On 16 November 2010 19:17, Edward Z. Yang
wrote: It seems to me that there is a possibility we could reify some information that is traditionally specified in the documentation: that is, what functions must be defined by a minimal instance, which could then give GHC enough information to give meaningful warnings if not all functions for a minimal instance are proviced.
One could use a compiler pragma the defines possible sets of minimal definitions, e.g. {-# MINIMAL_DEF Num ((+),(*),abs,signum,fromInteger,(-)), ((+),(*),abs,signum,fromInteger,negate) #-}
one could even add logical notation, like: {-# MINIMAL_DEF Num ((+), (*), abs, signum, fromInteger, (-) || negate) #-}

On 16 November 2010 18:40, Russ Abbott
why isn't
instance Show Test
interpreted to mean
data Test = Test deriving (Show)
* -- Russ *
One of them is declaring an instance, the other is asking the compiler derive an instance declaration for you. I don't know why the empty one is interpreted to be an instance deriving. Maybe because in such a case there would be no way to declare an empty instance? In addition, there is yet another similar syntax. See stand-alone derivinghttp://haskell.org/ghc/docs/6.12.2/html/users_guide/deriving.html . Ozgur

Edward Z. Yang wrote:
It seems to me that there is a possibility we could reify some information that is traditionally specified in the documentation: that is, what functions must be defined by a minimal instance, which could then give GHC enough information to give meaningful warnings if not all functions for a minimal instance are provided.
It definitely should not be so easy to create runtime crashes by not providing enough method implementations at compile time. In this case, though, showsPrec and readsPrec only exist for historical reasons. Nowadays I don't think anyone would consider ReadS or ShowS for a parser or pretty-printer so complex that it needs to consider operator precedence. It would be better to deprecate them and remove them, together with the default method implementations for shows and reads. Regards, Yitz

Hi,
On 16 November 2010 17:52, Russ Abbott
I'm surprised that there is so much resistance to acknowledging what appears to be a bug. Why not just fix it?
I'd really like it, if ghci was clever enough to automatically detect the fact that you haven't provided enough function definitions for the minimal instance. Do you have a fix in mind?Other than something like annotating class declarations, which is a cool idea and has been suggested by ezyang already. What interpretation justifies GHCi going into an uninterruptible state at
this point?
This is really bad. It should still be interruptible. I think I can break my resistance and say this (ghci not being interruptible) is a bug :) Strangely, if you define two empty functions, just calling each other, this infinite loop can be easily interrupted. Try it with: f = g g = f Moreover, if you compile&run your original code, a very quick 'stack space overflow' occurs. Nothing to interrupt there. At least it doesn't eat up all your system resources as you say ghci does. I just killed the process, saved before the need to restart :) Best, Ozgur
participants (5)
-
Edward Z. Yang
-
Ozgur Akgun
-
Russ Abbott
-
Tobias Brandt
-
Yitzchak Gale