Hello libraries list,
(Warning: this whole message may be a waste of time, you may wish to skip it.)
I'd like to inquire about the possibility of a Floating instance for Data.Fixed. (Unfortunately, not knowing of the existence of this list or the appropriate procedure, I created a trac ticket to ask about this, because that was the only forum I knew of. It's
https://ghc.haskell.org/trac/ghc/ticket/10297. Sorry.)
The original idea was along these lines:
lift :: (HasResolution a) => (Double -> Double) -> Fixed a -> Fixed a
lift f = realToFrac . f . realToFrac
instance (HasResolution a) => Floating (Fixed a) where
pi = realToFrac pi
sin = lift sin
-- etc, similar lift2 function for (**), logBase
This allows the use of transcendental functions on Fixed values. Conceptually, transcendental functions on fixed point values aren't problematic, and are actually pretty widely used in certain gaming/simulation/signal processing applications.
I've since learned that this may not be a good idea. A commenter (Scott Turner) on the haskell-cafe mailing list astutely raised the issue that because Data.Fixed uses the arbitrary-size Integer type, it's impossible to correctly compute these functions for all possible Fixed values without an arbitrary precision implementation, simply converting through Double like this won't always work.