git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Inserted Apply into hierarchy.
commite0526d3bf21d21edeca6f44b6752a9d94551d654 authorjoneshf <jones3.hardy@gmail.com> dateSun 6 Apr 2014, 19:52 (13 years ago) parent8537e25
5 files changed+36−20
examples/passing/Do.purs+9−7 examples/passing/MonadState.purs+4−2 examples/passing/Superclasses3.purs+3−1 examples/passing/TypeClasses.purs+13−7 prelude/prelude.purs+7−3
examples/passing/Do.purs+9−7
@@ -8,17 +8,19 @@ instance functorMaybe :: Functor Maybe where
88 (<$>) f Nothing = Nothing
99 (<$>) f (Just x) = Just (f x)
1010
11−instance applicativeMaybe :: Applicative Maybe where
12− pure = Just
11+instance applyMaybe :: Apply Maybe where
1312 (<*>) (Just f) (Just x) = Just (f x)
1413 (<*>) _ _ = Nothing
1514
15+instance applicativeMaybe :: Applicative Maybe where
16+ pure = Just
17+
1618instance monadMaybe :: Prelude.Monad Maybe where
1719 return = Just
1820 (>>=) Nothing _ = Nothing
1921 (>>=) (Just a) f = f a
2022
21−test1 = \_ -> do
23+test1 = \_ -> do
2224 Just "abc"
2325
2426test2 = \_ -> do
@@ -43,14 +45,14 @@ test5 mx my mz = do
4345 z <- mz
4446 Just (z + sum + 1)
4547
46−test6 mx = \_ -> do
47− let
48+test6 mx = \_ -> do
49+ let
4850 f :: forall a. Maybe a -> a
4951 f (Just x) = x
5052 Just (f mx)
5153
52−test8 = \_ -> do
53− Just (do
54+test8 = \_ -> do
55+ Just (do
5456 Just 1)
5557
5658test9 = \_ -> (+) <$> Just 1 <*> Just 2
examples/passing/MonadState.purs+4−2
@@ -15,10 +15,12 @@ runState s (State f) = f s
1515instance functorState :: Functor (State s) where
1616 (<$>) = liftM1
1717
18−instance appState :: Applicative (State s) where
19− pure = return
18+instance applyState :: Apply (State s) where
2019 (<*>) = ap
2120
21+instance applicativeState :: Applicative (State s) where
22+ pure = return
23+
2224instance monadState :: Prelude.Monad (State s) where
2325 return a = State $ \s -> Tuple s a
2426 (>>=) f g = State $ \s -> case runState s f of
examples/passing/Superclasses3.purs+3−1
@@ -24,9 +24,11 @@ runMTrace (MTrace a) = a
2424instance functorMTrace :: Functor MTrace where
2525 (<$>) = liftM1
2626
27+instance applyMTrace :: Apply MTrace where
28+ (<*>) = ap
29+
2730instance applicativeMTrace :: Applicative MTrace where
2831 pure = return
29− (<*>) = ap
3032
3133instance monadMTrace :: Monad MTrace where
3234 return = MTrace <<< return
examples/passing/TypeClasses.purs+13−7
@@ -24,10 +24,12 @@ test3 = \_ -> show (Data "testing")
2424instance functorData :: Functor Data where
2525 (<$>) = liftM1
2626
27−instance appData :: Applicative Data where
28− pure = return
27+instance applyData :: Apply Data where
2928 (<*>) = ap
3029
30+instance applicativeData :: Applicative Data where
31+ pure = return
32+
3133instance monadData :: Prelude.Monad Data where
3234 return = Data
3335 (>>=) (Data a) f = f a
@@ -37,10 +39,12 @@ data Maybe a = Nothing | Just a
3739instance functorMaybe :: Functor Maybe where
3840 (<$>) = liftM1
3941
40−instance appMaybe :: Applicative Maybe where
41− pure = return
42+instance applyMaybe :: Apply Maybe where
4243 (<*>) = ap
4344
45+instance applicativeMaybe :: Applicative Maybe where
46+ pure = return
47+
4448instance monadMaybe :: Prelude.Monad Maybe where
4549 return = Just
4650 (>>=) Nothing _ = Nothing
@@ -60,10 +64,12 @@ test6 = \_ -> show ["testing"]
6064instance functorFunction :: Functor ((->) r) where
6165 (<$>) = liftM1
6266
63−instance appFunction :: Applicative ((->) r) where
64− pure = return
67+instance applyFunction :: Apply ((->) r) where
6568 (<*>) = ap
6669
70+instance applicativeFunction :: Applicative ((->) r) where
71+ pure = return
72+
6773instance monadFunction :: Prelude.Monad ((->) r) where
6874 return a r = a
6975 (>>=) f g r = g (f r) r
@@ -75,6 +81,6 @@ runReader r f = f r
7581test9 _ = runReader 0 $ do
7682 n <- ask
7783 return $ n + 1
78−
84+
7985main = Debug.Trace.trace (test7 "Done")
8086
prelude/prelude.purs+7−3
@@ -59,10 +59,12 @@ module Prelude where
5959
6060 infixl 4 <*>
6161
62− class (Functor f) <= Applicative f where
63− pure :: forall a. a -> f a
62+ class (Functor f) <= Apply f where
6463 (<*>) :: forall a b. f (a -> b) -> f a -> f b
6564
65+ class (Apply f) <= Applicative f where
66+ pure :: forall a. a -> f a
67+
6668 liftA1 :: forall f a b. (Applicative f) => (a -> b) -> f a -> f b
6769 liftA1 f a = pure f <*> a
6870
@@ -390,9 +392,11 @@ module Control.Monad.Eff where
390392 instance functorEff :: Functor (Eff e) where
391393 (<$>) = liftA1
392394
395+ instance applyEff :: Apply (Eff e) where
396+ (<*>) = ap
397+
393398 instance applicativeEff :: Applicative (Eff e) where
394399 pure = return
395− (<*>) = ap
396400
397401 instance monadEff :: Monad (Eff e) where
398402 return = retEff