Created
December 24, 2018 16:21
-
-
Save Solonarv/0a84ee87299072f9d7bb8d7d9567d012 to your computer and use it in GitHub Desktop.
Pointwise Semigroup lifting via MonadZip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
newtype Pointwise f a = Pointwise { getPointwise :: f a } | |
deriving newtype (Functor, Applicative, Alternative, Monad, MonadPlus, MonadZip) | |
deriving stock (Eq, Ord, Show, Read) | |
instance (MonadZip f, Semigroup a) => Semigroup (Pointwise f a) where | |
Pointwise xs <> Pointwise ys = Pointwise (mzipWith (<>) xs ys) | |
-- Now Maybe (Pointwise (Vector (Sum a))) is the monoid you're looking for |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment