#3304: define gcd 0 0 = 0
-----------------------------+----------------------------------------------
  Reporter:  stevec          |          Owner:                  
      Type:  proposal        |         Status:  closed          
  Priority:  normal          |      Milestone:  7.2.1           
 Component:  libraries/base  |        Version:  7.1             
Resolution:  fixed           |       Keywords:                  
  Testcase:                  |      Blockedby:                  
Difficulty:  Unknown         |             Os:  Unknown/Multiple
  Blocking:                  |   Architecture:  Unknown/Multiple
   Failure:  None/Unknown    |  
-----------------------------+----------------------------------------------

Comment(by daniel.is.fischer):

 Thanks.

 The only feasible ways to throw an exception I see are
 {{{
 case {- abs $ -} gcd' (abs x) (abs y) of
   g | g < 0 -> overflowError
     | otherwise -> g
 }}}
 or
 {{{
 let x' = abs x
     y' = abs y
 in if x' < 0 || y' < 0 then overflowError else gcd' x' y'
 }}}
 In the former case, the `abs` on the result would be much better, or you'd
 get an overflowError half the time when one argument is minBound for
 signed bounded types, which would be hard to predict and understand. In
 the latter case, you'd get consistent and predictable exceptions, but
 unnecessarily many, in my opinion.

 I would prefer to not throw an exception, however, because often you can
 carry on perfectly well with a negative result.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/3304#comment:16>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to