@@ -1,43 +1,33 @@
11module TypeClasses where
22
3−import Prelude (($))
4−
5−class Show a where
6− show :: a -> String
7−
8−instance Show String where
9− show s = s
3+import Prelude
104
115test1 = \_ -> show "testing"
126
13−f :: forall a. (TypeClasses.Show a) => a -> String
7+f :: forall a. (Prelude.Show a) => a -> String
148f x = show x
159
1610test2 = \_ -> f "testing"
1711
18−test7 :: forall a. (Show a) => a -> String
12+test7 :: forall a. (Prelude.Show a) => a -> String
1913test7 = show
2014
2115test8 = \_ -> show $ "testing"
2216
2317data Data a = Data a
2418
25−instance (TypeClasses.Show a) => TypeClasses.Show (Data a) where
19+instance (Prelude.Show a) => Prelude.Show (Data a) where
2620 show (Data a) = "Data (" ++ show a ++ ")"
2721
2822test3 = \_ -> show (Data "testing")
2923
30−class Monad m where
31− ret :: forall a. a -> m a
32− (>>=) :: forall a b. m a -> (a -> m b) -> m b
33−
34−instance TypeClasses.Monad Data where
24+instance Prelude.Monad Data where
3525 ret = Data
3626 (>>=) (Data a) f = f a
3727
3828data Maybe a = Nothing | Just a
3929
40−instance TypeClasses.Monad Maybe where
30+instance Prelude.Monad Maybe where
4131 ret = Just
4232 (>>=) Nothing _ = Nothing
4333 (>>=) (Just a) f = f a
@@ -49,20 +39,30 @@ test5 = \_ -> Just 1 >>= \n -> ret (n + 1)
4939
5040module TypeClasses2 where
5141
42+import Prelude
5243import TypeClasses
5344
54−instance (TypeClasses.Show a) => TypeClasses.Show [a] where
45+instance (Prelude.Show a) => Prelude.Show [a] where
5546 show [] = "[]"
56− show (x:xs) = TypeClasses.show x ++ ", " ++ TypeClasses.show xs
47+ show (x:xs) = show x ++ ", " ++ show xs
5748
5849test6 = \_ -> show ["testing"]
5950
60−instance TypeClasses.Monad (->) r where
51+instance Prelude.Monad (->) r where
6152 ret a r = a
6253 (>>=) f g r = g (f r) r
54+
55+ask r = r
56+
57+runReader r f = f r
58+
59+test9 _ = runReader 0 $ do
60+ n <- ask
61+ ret $ n + 1
6362
6463module Main where
6564
65+import Prelude
6666import TypeClasses
6767
6868main = Trace.trace (test7 "Done")