[Haskell-cafe] type keeping rounding, typeable (and a difficulty)

Greg Buchholz haskell at sleepingsquirrel.org
Thu Nov 16 17:02:51 EST 2006


isto wrote:
] > isto wrote:
] > ] 	let t = show (typeOf a)
] > ] 	in case t of
] > ] 		"Double"  -> roundDDec d a
] > ] 		"Complex Double" -> roundCDec d a
] 
] I'll guess the reason it didn't compile was different
] types at case branches (am I wrong?) 

    Correct.

] Anyhow, do you know that is it possible to choose the return type
] somehow in the spirit above?  

    Maybe you want something like...
    
> roundDec d (Left a)  = Left  (roundDDec d a)
> roundDec d (Right a) = Right (roundCDec d a)
> 
> 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

Greg Buchholz


More information about the Haskell-Cafe mailing list