Mercurial > hg > Members > atton > similar_monad
changeset 4:66609010d477
Define Similer example as Functor
author | Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 02 Sep 2014 11:01:25 +0900 |
parents | 3c5fbce357af |
children | 051c663a4af2 |
files | similer.hs |
diffstat | 1 files changed, 11 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/similer.hs Sun Aug 31 19:21:42 2014 +0900 +++ b/similer.hs Tue Sep 02 11:01:25 2014 +0900 @@ -13,6 +13,14 @@ 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) +double :: Int -> Similer Int Int +double x = Similer (2 * x) id (2 * x) + +twicePlus :: Int -> Similer Int (Similer Int Int) +twicePlus x = Similer x double (Similer (x + x) id $ x + x) + +plusTwo :: Int -> Similer Int (Similer Int Int) +plusTwo x = Similer x double (Similer (x + 2) id (x + 2)) + +hoge :: Eq b => Similer a b -> b +hoge (Similer x f y) = if (f x) == y then y else undefined