
Firstly I'm assuming that GHC's strictness analyser notices things like (bottom = bottom) or could easily do so - please correct me if I'm wrong. GHC in its RTS already throws Nontermination exception in some cases. I think it would be nice if, when the compiler detected nontermination, to replace it with an exception and emit a warning message (hmm... if GHC Core loses source code information, a warning message might be difficult). Is there any intentional use of certain nontermination? This is inspired by the problem that supplying default definitions for class methods that refer to each other (such as Eq's (==) and (/=)), doesn't warn you if you don't define them and only yields your program not to terminate, when you run it! (noticed on haskell-prime list.) Even if it can't be detected automatically, maybe a pragma for classes to tell the compiler what documentation often tells users: {-# MINIMAL_INSTANCE Eq (==) OR (/=) #-} or for Data.Bits.Bits "Minimal complete definition: .&., .|., xor, complement, (shift or (shiftL and shiftR)), (rotate or (rotateL and rotateR)), bitSize and isSigned. " {-# MINIMAL_INSTANCE Bits (.&.) AND (.|.) AND xor AND complement AND (shift OR (shiftL AND shiftR)) AND (rotate OR (rotateL AND rotateR)) AND bitSize AND isSigned #-} Except that Bits is a stupid class in which you're *supposed to* leave bitSize undefined for unlimited-precision types like Integer... GHC already warns if you don't define bitSize... Maybe "AND" --> "," , "OR" --> "|" or something Thoughts? Isaac

On Fri, Aug 10, 2007 at 01:32:48PM -0300, Isaac Dupree wrote:
GHC in its RTS already throws Nontermination exception in some cases. I think it would be nice if, when the compiler detected nontermination, to replace it with an exception and emit a warning message (hmm... if GHC Core loses source code information, a warning message might be difficult). Is there any intentional use of certain nontermination?
One possible use for nontermination would be as a workaround for something like Catch (which defines its own workarounds, but if it didnt...). Catch complains if your code calls error, so you could define your own: myerror :: String -> a myerror s = myerror s The type of this function guarantees that it is either non-terminating or generates an exception, so if powerful static checking prevented a programmer from writing an exception-generating code, the desperate programmer always has the fallback of generating non-terminating code (a good reason for allowing error in the language, I suppose). -- David Roundy Department of Physics Oregon State University
participants (2)
-
David Roundy
-
Isaac Dupree