Files
book-exercises/Haskell-book/17/Constant.hs

14 lines
330 B
Haskell

module Constant where
newtype Constant a b =
Constant { getConstant :: a }
deriving (Eq, Ord, Show)
instance Functor (Constant a) where
fmap _ (Constant x) = Constant x
instance Monoid a
=> Applicative (Constant a) where
pure x = Constant mempty
(Constant x) <*> (Constant y) = Constant $ mappend x y