@@ -1,43 +1,33 @@
1module TypeClasses where
1module TypeClasses where
3−import Prelude (($))
3+import Prelude
8−instance Show String where
11test1 = \_ -> show "testing"
5test1 = \_ -> show "testing"
13−f :: forall a. (TypeClasses.Show a) => a -> String
7+f :: forall a. (Prelude.Show a) => a -> String
14f x = show x
8f x = show x
16test2 = \_ -> f "testing"
10test2 = \_ -> f "testing"
18−test7 :: forall a. (Show a) => a -> String
12+test7 :: forall a. (Prelude.Show a) => a -> String
19test7 = show
13test7 = show
21test8 = \_ -> show $ "testing"
15test8 = \_ -> show $ "testing"
23data Data a = Data a
17data Data a = Data a
25−instance (TypeClasses.Show a) => TypeClasses.Show (Data a) where
19+instance (Prelude.Show a) => Prelude.Show (Data a) where
26 show (Data a) = "Data (" ++ show a ++ ")"
20 show (Data a) = "Data (" ++ show a ++ ")"
28test3 = \_ -> show (Data "testing")
22test3 = \_ -> show (Data "testing")
31− ret :: forall a. a -> m a
32− (>>=) :: forall a b. m a -> (a -> m b) -> m b
34−instance TypeClasses.Monad Data where
24+instance Prelude.Monad Data where
35 ret = Data
25 ret = Data
36 (>>=) (Data a) f = f a
26 (>>=) (Data a) f = f a
38data Maybe a = Nothing | Just a
28data Maybe a = Nothing | Just a
40−instance TypeClasses.Monad Maybe where
30+instance Prelude.Monad Maybe where
41 ret = Just
31 ret = Just
42 (>>=) Nothing _ = Nothing
32 (>>=) Nothing _ = Nothing
43 (>>=) (Just a) f = f a
33 (>>=) (Just a) f = f a
@@ -49,20 +39,30 @@ test5 = \_ -> Just 1 >>= \n -> ret (n + 1)
50module TypeClasses2 where
40module TypeClasses2 where
52import TypeClasses
43import TypeClasses
54−instance (TypeClasses.Show a) => TypeClasses.Show [a] where
45+instance (Prelude.Show a) => Prelude.Show [a] where
55 show [] = "[]"
46 show [] = "[]"
56− show (x:xs) = TypeClasses.show x ++ ", " ++ TypeClasses.show xs
47+ show (x:xs) = show x ++ ", " ++ show xs
58test6 = \_ -> show ["testing"]
49test6 = \_ -> show ["testing"]
60−instance TypeClasses.Monad (->) r where
51+instance Prelude.Monad (->) r where
61 ret a r = a
52 ret a r = a
62 (>>=) f g r = g (f r) r
53 (>>=) f g r = g (f r) r
59+test9 _ = runReader 0 $ do
64module Main where
63module Main where
66import TypeClasses
66import TypeClasses
68main = Trace.trace (test7 "Done")
68main = Trace.trace (test7 "Done")