on develop help sign in
Merge pull request #287 from reflex-frp/aa-dynamic-num

Add Num instance for Dynamic

commit6a38fdd4ba6dd0099363b776e760ec4dd81b5c87 authorRyan Trinkle <ryan.trinkle@gmail.com> dateSun 17 Mar 2019, 23:03 (8 years ago) parent84ca5e26a450dd
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