-----------------------------------------------------------------------------
-- |
-- module      :  Control.Monad.Identity
-- Copyright   :  (c) Evgeniy Permyakov 2010
-- License     :  BSD-style (see the LICENSE file in the distribution)
--
-- Maintainer  :  permeakra@gmail.com
-- Stability   :  experimental 
-- Portability :  portable (haskell - 2010)

-- this module implements identity monad to be base of monad transoformers stack.
module Control.Monad.Identity (Identity, identity, runIdentity) where

-- | this is identity monad (and functor) that can be freely packed/unpacked without loss of data
newtype Identity a = Identity a 


-- | Pach pure data into identity monad
identity :: a -> Identity a
identity = Identity

-- | unpack value from identity monad
runIdentity :: Identity a -> a
runIdentity (Identity a) = a

instance Monad Identity where
 return = Identity
 m >>= k = k $ runIdentity m

instance Functor Identity where
 fmap f = Identity . f . runIdentity



