On Fri, Feb 09, 2001 at 12:55:12PM -0800, William Lee Irwin III wrote:
> class (Eq a, Show a) => Num a where
> (+), (-), (*) :: a -> a -> a
> negate :: a -> a
> abs, signum :: a -> a
> fromInteger :: Integer -> a
> fromInt :: Int -> a -- partain: Glasgow extension
>
> ... So we have two totally inappropriate operations (fromInteger and
> fromInt), ...
I beg to differ on this point. One could provide a default
implementation for fromInt(eger) as follows, assuming a 'zero' and
'one', which do obviously fit (they are the additive and
multiplicative units):
fromInteger n | n < 0 = negate (fromInteger (-n))
fromInteger n = foldl (+) zero (repeat n one)
(Of course, one could use the algorithm in integer exponentiation to
make this efficient.)
Best,
Dylan Thurston
_______________________________________________
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe
- In hoc signo vinces (Was: Revamping the numeric ... Jerzy Karczmarczuk
- Re: In hoc signo vinces (Was: Revamping the... Marcin 'Qrczak' Kowalczyk
- Re: In hoc signo vinces (Was: Revamping the... William Lee Irwin III
- Re: In hoc signo vinces (Was: Revamping... Dylan Thurston
- Re: In hoc signo vinces (Was: Revamping the... Jerzy Karczmarczuk
- Re: In hoc signo vinces (Was: Revamping... William Lee Irwin III
- Re: In hoc signo vinces (Was: Revamping the... Marcin 'Qrczak' Kowalczyk
- Re: In hoc signo vinces (Was: Revamping the... Jerzy Karczmarczuk
- Re: In hoc signo vinces (Was: Revamping the... Marcin 'Qrczak' Kowalczyk
- Re: In hoc signo vinces (Was: Revamping the... Jerzy Karczmarczuk
- Clean numeric system? Dylan Thurston
- Deja vu: Re: In hoc signo vinces (Was: ... Laszlo Nemeth
- Re: In hoc signo vinces (Was: Revamping the... Joe Fasel
- Re: In hoc signo vinces (Was: Revamping the... William Lee Irwin III
