
5 May
2018
5 May
'18
8:52 p.m.
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)