Monoid over reciprocal of reciprocal sum
박신환
ndospark320 at naver.com
Sun May 6 00:52:09 UTC 2018
e.g. Parallel resistors, serial capacitors, parallel inductors.
EDIT: Corrected typo.
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 (RecipSum 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/7b74363a/attachment.html>
More information about the Libraries
mailing list