on develop help sign in
Add Num instance for Dynamic
commit6a450ddba31d831553d39bfb5ecd14db1987e010 authorAli Abrar <aliabrar@gmail.com> dateSun 17 Mar 2019, 22:53 (8 years ago) parent84ca5e2
1 file changed+9
src/Reflex/Class.hs+9
src/Reflex/Class.hs+9
@@ -548,6 +548,15 @@ instance (Reflex t, Num a) => Num (Behavior t a) where
548548 negate = fmap negate
549549 signum = fmap signum
550550
551+instance (Num a, Reflex t) => Num (Dynamic t a) where
552+ (+) = liftA2 (+)
553+ (*) = liftA2 (*)
554+ abs = fmap abs
555+ signum = fmap signum
556+ fromInteger = pure . fromInteger
557+ negate = fmap negate
558+ (-) = liftA2 (-)
559+
551560instance (Reflex t, Semigroup a) => Semigroup (Behavior t a) where
552561 a <> b = pull $ liftM2 (<>) (sample a) (sample b)
553562 sconcat = pull . fmap sconcat . mapM sample