1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
module Data.Functor.Identity where

newtype Identity a = Identity { runIdentity :: a }
  deriving (Eq, Ord, Read, Show)

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

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

instance Monad Identity where
  m >>= k = k (runIdentity m)
  return a = Identity a