Skip to content

Instantly share code, notes, and snippets.

@dmwit
Created October 28, 2019 20:38
Show Gist options
  • Save dmwit/791f05023c4f88114efadfdb903e88c3 to your computer and use it in GitHub Desktop.
Save dmwit/791f05023c4f88114efadfdb903e88c3 to your computer and use it in GitHub Desktop.
{-# LANGUAGE DeriveFunctor #-}
import Control.Monad.Zip
data Zip f a = P a | V (f a)
deriving (Eq, Ord, Read, Show, Functor)
instance MonadZip f => Applicative (Zip f) where
pure = P
P f <*> P x = P (f x)
P f <*> V xs = V (f <$> xs)
V fs <*> P x = V (($x) <$> fs)
V fs <*> V xs = V (mzipWith ($) fs xs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment