RE: Possible bug/omission in Numeric library?
| However, I would guess that changing the type signature of | the current showInt function is unacceptable for Haskell'98. | Maybe we should consider adding the more general version | under a new name like showIntBase, together with | show{Dec,Oct,Hex}? This would break no existing code, and | clear up the slight anomaly in the current capability of the | Haskell'98 library. Hmm. This is another unforced change, but admittedly to the libraries, which have received much less attention and in some cases (like this) look more accidental than deliberate. So I've been using a lower bar for modifications to the Libraries than to the Report. As you say, we can't change the type of showInt. I suppose we could add: showIntAtBase :: Integral a = a-- base - (a - Char) -- digit to char - a-- number to show. - ShowS showOct, showHex :: Integral a = a - ShowS Q1: But would we really want showDec too? Identical to existing showInt? I am disinclined to use K-F's extra generality for H98, nice though it is. Too different from readInt. Also, GHC's NumExts has doubleToFloat :: Double - Float floatToDouble :: Float - Double Q2: If we are going to run round adding functions to Numeric, should we add those too? It's hard to know where to stop... but if that conversion is what you want to do, H98 doesn't give a good way to do it. Simon ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
Re: Possible bug/omission in Numeric library?
As you say, we can't change the type of showInt. I suppose we could add: showIntAtBase :: Integral a=20 =3D a-- base - (a - Char) -- digit to char - a-- number to show. - ShowS showOct, showHex :: Integral a =3D a - ShowS Q1: But would we really want showDec too? Identical to existing showInt? I only suggested it for consistency of naming. However, since showInt is not the dual of readInt, we can't have consistency anyway. Regards, Malcolm ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
Re: Possible bug/omission in Numeric library?
Also, GHC's NumExts has doubleToFloat :: Double - Float floatToDouble :: Float - Double Q2: If we are going to run round adding functions to Numeric, should we add those too? It's hard to know where to stop... but if that conversion is what you want to do, H98 doesn't give a good way to do it. Haskell already has fromRealFrac which does the same job (ignoring NaNs, -0, etc.). AFAIK, the only reason you'd use these shortcuts is if you're using a compiler that can't optimize fromRealFrac (i.e., you're not using HBC or GHC) or exploring the limits of Haskell's support for IEEE arithmetic. My feeling is that this is something of an unforced change. Adding functions can break code (though the fix is easy) so, whilst I agree that the bar is lower for libraries and for adding functions, I think we should still exercise some restraint. This is especially true since it's not clear that this is the right thing to do (since we have fromRealFrac already) and it is hard to remove features once you've added them. -- Alastair Reid[EMAIL PROTECTED]http://www.cs.utah.edu/~reid/ ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
RE: Possible bug/omission in Numeric library?
There is something strange about the Haskell'98 Numeric library, which I think could be considered a bug of sorts. There are functions readDec, readOct, readHex :: (Integral a) = ReadS a which read an integer from a string in base 10, 8, or 16, but there are no corresponding show functions to convert an integer to a string using base 8 or 16. The sole function given is showInt :: (Integral a) = a - ShowS which shows a number in base 10 only. I think you'll agree that it is odd that you can read a certain number format but cannot show it? Yes indeed. GHC and Hugs have showHex, showOct, showBin and showIntAtBase in NumExts: http://www.haskell.org/ghc/docs/latest/set/sec-numexts.html Cheers, Simon ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
Re: Possible bug/omission in Numeric library?
Hi! In fact, we might want to be slightly more general. Why don't go for a general base conversion, much like Malcolms idea but without converting every digit to a Char. Say something like toBase :: (Integral a) = a - a - [a] toBase base n | n 0 = error Numeric.toBase: can't convert negative numbers | otherwise = theDigits n [] where theDigits n r = let (n',d) = quotRem n base r' = d : r in if n' == 0 then r' else theDigits n' r' Then the showInt function becomes showInt :: (Integral a) = a - (Int-Char) - a - ShowS showInt base intToDig n r = foldr (\ i r - intToDig (fromIntegral i) : r) r (toBase base n) but we can also use toBase by itself. We could also have an analogous fromBase, of course. Cheers, /kff ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell