
15 Nov
2010
15 Nov
'10
4:20 p.m.
On Mon, Nov 15, 2010 at 6:43 PM, Ling Yang
... One alternate way of doing this, however, is instancing the typeclasses of the ordinary values with their monadic versions:
instance (Num a) => Num (Prob a) where (+) = liftM2 (+) (*) = liftM2 (*) abs = liftM abs signum = liftM signum fromInteger = return . fromInteger
instance (Fractional a) => Fractional (Prob a) where fromRational = return . fromRational (/) = liftM2 (/)
You may also like to look at Conal Elliott's applicative-numbers package: http://hackage.haskell.org/package/applicative-numbers Bas