somme ex2 and ex3 text
[tt2015.git] / a3 / code / Generics / GenMonad.icl
diff --git a/a3/code/Generics/GenMonad.icl b/a3/code/Generics/GenMonad.icl
deleted file mode 100644 (file)
index 7b99b9e..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-implementation module GenMonad\r
-\r
-import StdGeneric, StdMaybe, StdList, StdFunc\r
-\r
-generic gMapLM a b :: a:a -> m:(m b:b) | Monad m, [m <= b]\r
-gMapLM{|c|} x                                          = ret x\r
-gMapLM{|PAIR|} fx fy (PAIR x y)        = fx x >>= \x1 -> fy y >>= \y1 -> ret (PAIR x1 y1)  \r
-gMapLM{|EITHER|} fl fr x                       = mapMEITHER fl fr x \r
-gMapLM{|CONS|} f (CONS x)                      = f x >>= ret o CONS\r
-gMapLM{|FIELD|} f (FIELD x)                    = f x >>= ret o FIELD\r
-gMapLM{|OBJECT|} f (OBJECT x)          = f x >>= ret o OBJECT\r
\r
-generic gMapRM a b :: a:a -> m:(m b:b) | Monad m, [m <= b]\r
-gMapRM{|c|} x                                          = ret x\r
-gMapRM{|PAIR|} fx fy (PAIR x y)                = fy y >>= \y1 -> fx x >>= \x1 -> ret (PAIR x1 y1)  \r
-gMapRM{|EITHER|} fl fr x                       = mapMEITHER fl fr x \r
-gMapRM{|CONS|} f (CONS x)                      = f x >>= ret o CONS\r
-gMapRM{|FIELD|} f (FIELD x)                    = f x >>= ret o FIELD\r
-gMapRM{|OBJECT|} f (OBJECT x)          = f x >>= ret o OBJECT\r
-\r
-derive gMapLM [], Maybe, (,), (,,), (,,,), (,,,,), (,,,,,), (,,,,,,), (,,,,,,,)\r
-derive gMapRM [], Maybe, (,), (,,), (,,,), (,,,,), (,,,,,), (,,,,,,), (,,,,,,,)\r
-\r
-mapMEITHER fl fr (LEFT x) = fl x >>= ret o LEFT\r
-mapMEITHER fl fr (RIGHT x) = fr x >>= ret o RIGHT \r
-\r
-//----------------------------------------------------------------------       \r
-instance Monad Maybe where\r
-       ret x = Just x\r
-       (>>=) Nothing f = Nothing\r
-       (>>=) (Just x) f = f x\r
-\r
-instance Monad [] where\r
-       ret x = [x]\r
-       //(>>=) xs f = flatten (map f xs)       // uniqueness typing makes it a problem because f is shared\r
-       (>>=) [x:xs] f = f x\r
-\r
-//-----------------------\r
-// state monad \r
-\r
-//retStMonad :: .a -> .(StMonad .s .a)\r
-retStMonad x = {st_monad = (\s -> (x, s))} \r
-\r
-//bindStMonad :: !.(StMonad .a .b) .(.b -> .(StMonad .a .c)) -> .(StMonad .a .c)\r
-bindStMonad {st_monad} f = {st_monad  = \s -> let (a, s1) = st_monad s in (f a).st_monad s1}\r
-\r
-mapFst f (x, y) = (f x, y)\r
-\r
-//mapStMonad :: .(a:a -> .b) !v:(StMonad s:s a:a) -> .(StMonad s:s .b), [v <= a,v <= s]\r
-mapStMonad f {st_monad} = {st_monad = mapFst f o st_monad}\r
-\r
-instance Monad (StMonad .s) where\r
-       ret x           = retStMonad x\r
-       (>>=) x f       = bindStMonad x f\r
-\r
-derive bimap (,)       \r
-derive bimap StMonad   
\ No newline at end of file