Monoid over reciprocal of reciprocal sum

박신환 ndospark320 at naver.com
Sun May 6 00:40:19 UTC 2018


e.g. Parallel resistors, serial capacitors, parallel inductors.
 
newtype RecipSum a = RecipSum {getRecipSum :: a}
 
instance Fractional a => Semigroup (RecipSum a) where
    RecipSum x <> RecipSum y = RecipSum (recip (recip x + recip y))
    sconcat (x :| xs) = mconcat (x : xs). 
    stimes n (RecipSum x) = RecipSum (x / fromIntegral n) 
 
instance Fractional a => Monoid (ResipSum a) where
    mempty = RecipSum (1 / 0)
    mconcat xs = RecipSum (recip . getSum $ foldMap (Sum . recip . getRecipSum) xs)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20180506/41e76ddf/attachment.html>


More information about the Libraries mailing list