diff src/deltaM_definition.hs @ 49:ba7f0b5454ab

Add description for DeltaM definition
author Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
date Sun, 15 Feb 2015 14:07:07 +0900
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/deltaM_definition.hs	Sun Feb 15 14:07:07 2015 +0900
@@ -0,0 +1,25 @@
+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)