Mercurial > hg > Members > atton > similar_monad
changeset 3:3c5fbce357af
Define >>= for Similer
author | Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 31 Aug 2014 19:21:42 +0900 |
parents | a5210ec1e41b |
children | 66609010d477 |
files | similer.hs |
diffstat | 1 files changed, 10 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/similer.hs Sun Aug 31 18:41:02 2014 +0900 +++ b/similer.hs Sun Aug 31 19:21:42 2014 +0900 @@ -1,12 +1,18 @@ -{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE UndecidableInstances #-} data Similer a b = Similer a (a -> b) b instance Functor (Similer a) where fmap g (Similer a f b) = Similer a (g . f) $ g b +same :: (Eq a) => Similer a b -> Similer a b -> Bool +same (Similer a _ _ ) (Similer b _ _) = a == b + eta :: a -> Similer a a eta a = Similer a id a ---mu :: (Eq (Similer b (b -> c) c)) => Similer a (a -> (Similer b (b -> c) c)) (Similer b (b -> c) c) -> Similer b (b -> c) c -mu :: (Eq (Similer b c)) => Similer a (Similer b c) -> Similer b c -mu (Similer a f b) = if ((f a) == b) then b else undefined +mu :: (Eq b) => Similer a (Similer b c) -> Similer b c +mu (Similer a f b) = if (same (f a) b) then b else undefined + +instance (Eq a) => Monad (Similer a) where + --return x = Similer x id x + s >>= f = mu (fmap f s)