changeset 11:e8a5df54480e

Define sample for Monad style
author Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
date Tue, 02 Sep 2014 16:25:53 +0900
parents 7c7efee7891f
children 158ae705cd16
files similer.hs
diffstat 1 files changed, 14 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/similer.hs	Tue Sep 02 16:12:34 2014 +0900
+++ b/similer.hs	Tue Sep 02 16:25:53 2014 +0900
@@ -1,11 +1,11 @@
-{-# LANGUAGE GADTs, MultiParamTypeClasses #-}
+{-# LANGUAGE GADTs #-}
 
 data Similer a = (Eq a) => Similer a (a -> a) a
 
 instance (Eq a) => Eq (Similer a) where
   s == ss = same s == same ss
 
-same :: Similer a -> a
+same :: (Eq a) => Similer a -> a
 same (Similer x f y) = if (f x) == y then y else undefined
 
 mu :: (Eq a) => Similer (Similer a) -> Similer a
@@ -26,9 +26,9 @@
   return x = Similer x id x
   s >>= f  = mu (eqmap f s)
 
-{-
-eta :: a -> Similer a a
-eta a = Similer a id a
+similer :: (Eq a) => (a -> a) -> (a -> a) -> a -> a
+similer f g x = same $ Similer x g (f x)
+
 
 
 double :: Int -> Int
@@ -40,13 +40,15 @@
 plusTwo :: Int -> Int
 plusTwo x = x + 2
 
+-- samples
 
-similer :: (Show b, Eq b) => (a -> b) -> (a -> b) -> a -> b
-similer f g x = same $ Similer x g (f x)
-
+{-
+*Main> same $ Main.return 100 Main.>>= (\x -> Similer x twicePlus  $ double x)
+200
 
--- samples
-sameExample            = map (similer twicePlus double)  [1..10]
-nonSameExample         = map (similer twicePlus plusTwo) [1..10]
-nonSameExampleSpecific = map (similer twicePlus plusTwo) [2]
+*Main> same $ Main.return 2 Main.>>= (\x -> Similer x plusTwo $ double x)
+4
+
+*Main> same $ Main.return 100 Main.>>= (\x -> Similer x plusTwo $ double x)
+*** Exception: Prelude.undefined
 -}