#3304: define gcd 0 0 = 0
-----------------------------+----------------------------------------------
Reporter: stevec | Owner:
Type: proposal | Status: new
Priority: normal | Component: libraries/base
Version: 6.10.3 | Severity: normal
Keywords: | Testcase:
Os: Unknown/Multiple | Architecture: Unknown/Multiple
-----------------------------+----------------------------------------------
Please make any comments on the libraries list by Tuesday 15th September
2009.
A suggestion to change 'gcd 0 0' from[[BR]]
gcd 0 0 = error "Prelude.gcd: gcd 0 0 is undefined"[[BR]]
to[[BR]]
gcd 0 0 = 0
The proposal has been discussed on [email protected]
http://www.haskell.org/pipermail/haskell-cafe/2009-May/060788.html
and there was a lot of support for the suggested change.
Current code:
libraries/base/GHC/Real.lhs
{{{
-- | @'gcd' x y@ is the greatest (positive) integer that divides both @x@
-- and @y@; for example @'gcd' (-3) 6@ = @3@, @'gcd' (-3) (-6)@ = @3@,
-- @'gcd' 0 4@ = @4...@. @'gcd' 0 0@ raises a runtime error.
gcd :: (Integral a) => a -> a -> a
gcd 0 0 = error "Prelude.gcd: gcd 0 0 is undefined"
gcd x y = gcd' (abs x) (abs y)
where gcd' a 0 = a
gcd' a b = gcd' b (a `rem` b)
}}}
Suggested code:
{{{
-- | @'gcd' x y@ is the greatest (positive) integer that divides both @x@
-- and @y@; for example @'gcd' (-3) 6@ = @3@, @'gcd' (-3) (-6)@ = @3@,
-- @'gcd' 0 4@ = @4...@. @'gcd' 0 0@ is defined to be 0.
gcd :: (Integral a) => a -> a -> a
gcd x y = gcd' (abs x) (abs y)
where gcd' a 0 = a
gcd' a b = gcd' b (a `rem` b)
}}}
[Note: I tried following the instructions at
http://www.haskell.org/haskellwiki/Library_submissions
to create a darcs patch. I successfully downloaded a copy of HEAD, but was
unable to create a patch:
$ darcs record libraries/base/GHC/Real.lhs
Recording changes in "libraries/base/GHC/Real.lhs":
No changes in selected files or directories!
I would claim that the instructions are insufficient for a darcs beginner.
]
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/3304>
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