Daniel Cartwright
2018-03-27 14:22:40 UTC
I see this as being generally (as in, to the users of Haskell as a whole)
useful:
newtype Ap f a = Ap { getAp :: f a }
deriving (Applicative, Eq, Foldable, Functor, Generic, Generic1
,Monad, Ord, Read, Show, Traversable)
Some hand-written instances:
instance (Applicative f, Semigroup a) => Semigroup (Ap f a) where
(Ap x) <> (Ap y) = Ap $ liftA2 (<>) x y
instance (Applicative f, Monoid a) => Monoid (Ap f a) where
mempty = Ap $ pure mempty
useful:
newtype Ap f a = Ap { getAp :: f a }
deriving (Applicative, Eq, Foldable, Functor, Generic, Generic1
,Monad, Ord, Read, Show, Traversable)
Some hand-written instances:
instance (Applicative f, Semigroup a) => Semigroup (Ap f a) where
(Ap x) <> (Ap y) = Ap $ liftA2 (<>) x y
instance (Applicative f, Monoid a) => Monoid (Ap f a) where
mempty = Ap $ pure mempty