newtype WrappedApplicative f a = WrapApplicative (f a)
deriving
(Functor, Show)
deriving newtype
Applicative
instance (Applicative f, Num a) => Num (WrappedApplicative f a) where
(+) = liftA2 (+)
(*) = liftA2 (*)
negate = fmap negate
fromInteger = pure . fromInteger
abs = fmap abs
signum = fmap signum
instance (Applicative f, Fractional a) => Fractional (WrappedApplicative f a) where
recip = fmap recip
fromRational = pure . fromRational
instance (Applicative f, Floating a) => Floating (WrappedApplicative f a) where
pi = pure pi
sqrt = fmap sqrt
exp = fmap exp
log = fmap log
sin = fmap sin
cos = fmap cos
asin = fmap asin
atan = fmap atan
acos = fmap acos
sinh = fmap sinh
cosh = fmap cosh
asinh = fmap asinh
atanh = fmap atanh
acosh = fmap acosh
instance (Applicative f, Semigroup s) => Semigroup (WrappedApplicative f s) where
(<>) = liftA2 (<>)
instance (Applicative f, Monoid m) => Monoid (WrappedApplicative f m) where
mempty = pure mempty
mappend = liftA2 mappend
Last active
November 26, 2017 18:19
-
-
Save Icelandjack/dab7111ba9ee2d1e25cf8728f7864e06 to your computer and use it in GitHub Desktop.
Newtype wrappers for deriving
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Getting
pure
,(<*>)
fromunit
,(**)