박신환
2018-05-06 00:40:19 UTC
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)
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)