Mercurial > hg > Members > atton > delta_monad
comparison similer.hs @ 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 |
comparison
equal
deleted
inserted
replaced
3:3c5fbce357af | 4:66609010d477 |
---|---|
11 eta a = Similer a id a | 11 eta a = Similer a id a |
12 | 12 |
13 mu :: (Eq b) => Similer a (Similer b c) -> Similer b c | 13 mu :: (Eq b) => Similer a (Similer b c) -> Similer b c |
14 mu (Similer a f b) = if (same (f a) b) then b else undefined | 14 mu (Similer a f b) = if (same (f a) b) then b else undefined |
15 | 15 |
16 instance (Eq a) => Monad (Similer a) where | 16 double :: Int -> Similer Int Int |
17 --return x = Similer x id x | 17 double x = Similer (2 * x) id (2 * x) |
18 s >>= f = mu (fmap f s) | 18 |
19 twicePlus :: Int -> Similer Int (Similer Int Int) | |
20 twicePlus x = Similer x double (Similer (x + x) id $ x + x) | |
21 | |
22 plusTwo :: Int -> Similer Int (Similer Int Int) | |
23 plusTwo x = Similer x double (Similer (x + 2) id (x + 2)) | |
24 | |
25 hoge :: Eq b => Similer a b -> b | |
26 hoge (Similer x f y) = if (f x) == y then y else undefined |