view prepaper/src/DeltaM.hs @ 72:109c5bc7e276

fix
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 17 Feb 2015 16:40:06 +0900
parents c75ba6313e39
children
line wrap: on
line source

data DeltaM m a = DeltaM (Delta (m a)) deriving (Show)


unDeltaM :: DeltaM m a -> Delta (m a)
unDeltaM (DeltaM d) = d

headDeltaM :: DeltaM m a -> m a
headDeltaM (DeltaM d) = headDelta d

tailDeltaM :: DeltaM m a -> DeltaM m a
tailDeltaM (DeltaM d) = DeltaM $ tailDelta d

mu' :: (Functor m, Monad m) => DeltaM m (DeltaM m a) -> DeltaM m a
mu' d@(DeltaM (Mono _))    = DeltaM $ Mono $ (>>= id) $ fmap headDeltaM $ headDeltaM d
mu' d@(DeltaM (Delta _ _)) = DeltaM $ Delta ((>>= id) $ fmap headDeltaM $ headDeltaM d)
                                            (unDeltaM (mu' (fmap tailDeltaM (tailDeltaM d))))

instance (Functor m, Monad m) => Monad (DeltaM m) where
    return x = DeltaM $ Mono $ return x
    d >>= f  = mu' $ fmap f d