Add remaining haskell book exercises
This commit is contained in:
13
Haskell-book/17/Constant.hs
Normal file
13
Haskell-book/17/Constant.hs
Normal file
@@ -0,0 +1,13 @@
|
||||
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
|
||||
Reference in New Issue
Block a user