{-# LANGUAGE BangPatterns #-}
module Darcs.Util.StrictIdentity (
StrictIdentity(..),
runStrictIdentity)
where
import Darcs.Prelude
import Control.Monad.Fix
newtype StrictIdentity a = StrictIdentity {forall a. StrictIdentity a -> a
runStrictIdentity_ :: a }
runStrictIdentity :: StrictIdentity a -> a
runStrictIdentity :: forall a. StrictIdentity a -> a
runStrictIdentity !StrictIdentity a
ma = case StrictIdentity a -> a
forall a. StrictIdentity a -> a
runStrictIdentity_ (StrictIdentity a -> a) -> StrictIdentity a -> a
forall a b. (a -> b) -> a -> b
$! StrictIdentity a
ma of
!a
res -> a
res
{-# INLINE runStrictIdentity #-}
instance Applicative StrictIdentity where
{-# INLINE pure #-}
pure :: forall a. a -> StrictIdentity a
pure !a
a = a -> StrictIdentity a
forall a. a -> StrictIdentity a
StrictIdentity (a -> StrictIdentity a) -> a -> StrictIdentity a
forall a b. (a -> b) -> a -> b
$! a
a
{-# INLINE (<*>) #-}
<*> :: forall a b.
StrictIdentity (a -> b) -> StrictIdentity a -> StrictIdentity b
(<*>) StrictIdentity (a -> b)
a StrictIdentity a
b = do a -> b
f <- StrictIdentity (a -> b)
a ; a
v <- StrictIdentity a
b ; b -> StrictIdentity b
forall a. a -> StrictIdentity a
forall (m :: * -> *) a. Monad m => a -> m a
return (b -> StrictIdentity b) -> b -> StrictIdentity b
forall a b. (a -> b) -> a -> b
$! (a -> b
f (a -> b) -> a -> b
forall a b. (a -> b) -> a -> b
$! a
v)
instance Functor StrictIdentity where
{-# INLINE fmap #-}
fmap :: forall a b. (a -> b) -> StrictIdentity a -> StrictIdentity b
fmap !a -> b
f !StrictIdentity a
m = b -> StrictIdentity b
forall a. a -> StrictIdentity a
StrictIdentity (b -> StrictIdentity b) -> b -> StrictIdentity b
forall a b. (a -> b) -> a -> b
$! (a -> b
f (a -> b) -> a -> b
forall a b. (a -> b) -> a -> b
$! (StrictIdentity a -> a
forall a. StrictIdentity a -> a
runStrictIdentity StrictIdentity a
m))
instance Monad StrictIdentity where
{-# INLINE return #-}
return :: forall a. a -> StrictIdentity a
return = a -> StrictIdentity a
forall a. a -> StrictIdentity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
{-# INLINE (>>=) #-}
(!StrictIdentity a
m) >>= :: forall a b.
StrictIdentity a -> (a -> StrictIdentity b) -> StrictIdentity b
>>= (!a -> StrictIdentity b
k) = a -> StrictIdentity b
k (a -> StrictIdentity b) -> a -> StrictIdentity b
forall a b. (a -> b) -> a -> b
$! StrictIdentity a -> a
forall a. StrictIdentity a -> a
runStrictIdentity StrictIdentity a
m
instance MonadFix StrictIdentity where
{-# INLINE mfix #-}
mfix :: forall a. (a -> StrictIdentity a) -> StrictIdentity a
mfix !a -> StrictIdentity a
f = a -> StrictIdentity a
forall a. a -> StrictIdentity a
StrictIdentity (a -> StrictIdentity a) -> a -> StrictIdentity a
forall a b. (a -> b) -> a -> b
$! ((a -> a) -> a
forall a. (a -> a) -> a
fix (StrictIdentity a -> a
forall a. StrictIdentity a -> a
runStrictIdentity (StrictIdentity a -> a) -> (a -> StrictIdentity a) -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> StrictIdentity a
f))