Skip to content

Instantly share code, notes, and snippets.

@ygrenzinger
Last active January 10, 2017 15:08
Show Gist options
  • Save ygrenzinger/0416472fcab5f3069fdc8e3ab4335d2b to your computer and use it in GitHub Desktop.
Save ygrenzinger/0416472fcab5f3069fdc8e3ab4335d2b to your computer and use it in GitHub Desktop.
Constant Applicative
newtype Constant a b = Constant { getConstant :: a } deriving (Eq, Ord, Show)
instance Functor (Constant a) where
fmap _ (Constant a) = Constant a
instance Monoid a => Applicative (Constant a) where
pure x = Constant mempty
(<*>) (Constant a) (Constant b) = Constant (a <> b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment