1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
{-# LANGUAGE NoImplicitPrelude #-}
module Data.Floating.Types where
foreign import bpcall "Num:" intToDouble :: Int -> Double
foreign import bpcall "Num:" integerToDouble :: Integer -> Double
class FloatConvert a b where
toFloating :: a -> b
instance FloatConvert Integer Double where
toFloating = integerToDouble
instance FloatConvert Int Double where
toFloating = intToDouble
instance {-# INCOHERENT #-} FloatConvert a a where
toFloating x = x
{- NOTE: Problems with defaults.
The geometric distribution is currently specified as:
geometric :: Double -> Geometric
geometric pSuccess = Geometric (toFloating pSuccess)
We need to specify that pSuccess is Double because otherwise
expressions like (geometric p) would have an ambiguous type
such as (forall a.FloatConvert a Prob => a)
If we could add a (Num a) constraint and avoid disabling defaulting
when constraints from outside the standard library are used, then
we could default to Double.
Alternatively, if the hypothetical extension to multi-parameter
type-classes from the NamedDefaults proposal was ever proposed
and implemented, then we could do something like:
default FloatConvert a b => {a ~ b}
That would default to Prob instead. Hmm...
-}
|