aboutsummaryrefslogtreecommitdiff
path: root/Haskell-book/18/Instance/src/Identity.hs
blob: 13cd1b2d074aaea32c91b4625db65a826e1de241 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
module Identity where

import Test.QuickCheck
import Test.QuickCheck.Checkers

newtype Identity a = Identity a
    deriving (Eq, Ord, Show)

instance Functor Identity where
    fmap f (Identity x) = Identity $ f x

instance Applicative Identity where
    pure = Identity
    (Identity f) <*> x = fmap f x

instance Monad Identity where
    return = pure
    (Identity x) >>= f = f x

instance Arbitrary a => Arbitrary (Identity a) where
    arbitrary = fmap Identity $ arbitrary

instance Eq a => EqProp (Identity a) where
    (=-=) = eq