view paper/src/deltaM_definition.hs @ 92:0354d3693324 default tip

Added tag paper_final for changeset 6a12eb22be8c
author Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
date Sun, 01 Mar 2015 13:08:51 +0900
parents 1181b4facaf9
children
line wrap: on
line source

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

-- DeltaM utils

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

-- DeltaM instance definitions

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)