# HG changeset patch # User Yasutaka Higa # Date 1409623285 -32400 # Node ID 66609010d47766f6c3c4d6baae6918390a747f52 # Parent 3c5fbce357af25dba55f124238bd948c9fb2175b Define Similer example as Functor diff -r 3c5fbce357af -r 66609010d477 similer.hs --- 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