[Haskell-cafe] type keeping rounding, typeable (and a difficulty)
isto.aho at dnainternet.net
Wed Nov 15 16:04:52 EST 2006
I've been trying to compile the following function
(rounding to a desired degree):
roundDec :: (Num a, Typeable a) => Int -> a -> a
roundDec d a =
let t = show (typeOf a)
in case t of
"Double" -> roundDDec d a
"Complex Double" -> roundCDec d a
otherwise -> a -- or something
The two other functions are
roundCDec :: (RealFloat a) => Int -> Complex a -> Complex a
roundCDec d (c :+ b) = (roundDDec d c :+ roundDDec d b)
roundDDec :: (RealFloat a) => Int -> a -> a
roundDDec d a = a -- or somegthing
Compiler gives the following error message:
Couldn't match expected type `Complex a'
against inferred type `a1' (a rigid variable)
`a1' is bound by the type signature for `roundDec' at FFT.hs:57:17
In the second argument of `roundCDec', namely `a'
In the expression: roundCDec d a
In a case alternative: "Complex Double" -> roundCDec d a
If in the roundDDec a's are replaced with Double, there will
be similar error message from the "Double"-line. The functionality
can be written differently, but I wanted to try write rounding
having in a signature at least "(Num a) => Int -> a -> a".
Again, any help would be appreciated a lot! Thanks in advance!
More information about the Haskell-Cafe