git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Inserted Apply into hierarchy.
e0526d3joneshf
examples/passing/Do.purs+9−7
@@ -8,17 +8,19 @@ instance functorMaybe :: Functor Maybe where
8 (<$>) f Nothing = Nothing
8 (<$>) f Nothing = Nothing
9 (<$>) f (Just x) = Just (f x)
9 (<$>) f (Just x) = Just (f x)
10
10
11−instance applicativeMaybe :: Applicative Maybe where
11+instance applyMaybe :: Apply Maybe where
12− pure = Just
13 (<*>) (Just f) (Just x) = Just (f x)
12 (<*>) (Just f) (Just x) = Just (f x)
14 (<*>) _ _ = Nothing
13 (<*>) _ _ = Nothing
15
14
15+instance applicativeMaybe :: Applicative Maybe where
16+ pure = Just
17+
16instance monadMaybe :: Prelude.Monad Maybe where
18instance monadMaybe :: Prelude.Monad Maybe where
17 return = Just
19 return = Just
18 (>>=) Nothing _ = Nothing
20 (>>=) Nothing _ = Nothing
19 (>>=) (Just a) f = f a
21 (>>=) (Just a) f = f a
20
22
21−test1 = \_ -> do
23+test1 = \_ -> do
22 Just "abc"
24 Just "abc"
23
25
24test2 = \_ -> do
26test2 = \_ -> do
@@ -43,14 +45,14 @@ test5 mx my mz = do
43 z <- mz
45 z <- mz
44 Just (z + sum + 1)
46 Just (z + sum + 1)
45
47
46−test6 mx = \_ -> do
48+test6 mx = \_ -> do
47− let
49+ let
48 f :: forall a. Maybe a -> a
50 f :: forall a. Maybe a -> a
49 f (Just x) = x
51 f (Just x) = x
50 Just (f mx)
52 Just (f mx)
51
53
52−test8 = \_ -> do
54+test8 = \_ -> do
53− Just (do
55+ Just (do
54 Just 1)
56 Just 1)
55
57
56test9 = \_ -> (+) <$> Just 1 <*> Just 2
58test9 = \_ -> (+) <$> Just 1 <*> Just 2
examples/passing/MonadState.purs+4−2
@@ -15,10 +15,12 @@ runState s (State f) = f s
15instance functorState :: Functor (State s) where
15instance functorState :: Functor (State s) where
16 (<$>) = liftM1
16 (<$>) = liftM1
17
17
18−instance appState :: Applicative (State s) where
18+instance applyState :: Apply (State s) where
19− pure = return
20 (<*>) = ap
19 (<*>) = ap
21
20
21+instance applicativeState :: Applicative (State s) where
22+ pure = return
23+
22instance monadState :: Prelude.Monad (State s) where
24instance monadState :: Prelude.Monad (State s) where
23 return a = State $ \s -> Tuple s a
25 return a = State $ \s -> Tuple s a
24 (>>=) f g = State $ \s -> case runState s f of
26 (>>=) f g = State $ \s -> case runState s f of
examples/passing/Superclasses3.purs+3−1
@@ -24,9 +24,11 @@ runMTrace (MTrace a) = a
24instance functorMTrace :: Functor MTrace where
24instance functorMTrace :: Functor MTrace where
25 (<$>) = liftM1
25 (<$>) = liftM1
26
26
27+instance applyMTrace :: Apply MTrace where
28+ (<*>) = ap
29+
27instance applicativeMTrace :: Applicative MTrace where
30instance applicativeMTrace :: Applicative MTrace where
28 pure = return
31 pure = return
29− (<*>) = ap
30
32
31instance monadMTrace :: Monad MTrace where
33instance monadMTrace :: Monad MTrace where
32 return = MTrace <<< return
34 return = MTrace <<< return
examples/passing/TypeClasses.purs+13−7
@@ -24,10 +24,12 @@ test3 = \_ -> show (Data "testing")
24instance functorData :: Functor Data where
24instance functorData :: Functor Data where
25 (<$>) = liftM1
25 (<$>) = liftM1
26
26
27−instance appData :: Applicative Data where
27+instance applyData :: Apply Data where
28− pure = return
29 (<*>) = ap
28 (<*>) = ap
30
29
30+instance applicativeData :: Applicative Data where
31+ pure = return
32+
31instance monadData :: Prelude.Monad Data where
33instance monadData :: Prelude.Monad Data where
32 return = Data
34 return = Data
33 (>>=) (Data a) f = f a
35 (>>=) (Data a) f = f a
@@ -37,10 +39,12 @@ data Maybe a = Nothing | Just a
37instance functorMaybe :: Functor Maybe where
39instance functorMaybe :: Functor Maybe where
38 (<$>) = liftM1
40 (<$>) = liftM1
39
41
40−instance appMaybe :: Applicative Maybe where
42+instance applyMaybe :: Apply Maybe where
41− pure = return
42 (<*>) = ap
43 (<*>) = ap
43
44
45+instance applicativeMaybe :: Applicative Maybe where
46+ pure = return
47+
44instance monadMaybe :: Prelude.Monad Maybe where
48instance monadMaybe :: Prelude.Monad Maybe where
45 return = Just
49 return = Just
46 (>>=) Nothing _ = Nothing
50 (>>=) Nothing _ = Nothing
@@ -60,10 +64,12 @@ test6 = \_ -> show ["testing"]
60instance functorFunction :: Functor ((->) r) where
64instance functorFunction :: Functor ((->) r) where
61 (<$>) = liftM1
65 (<$>) = liftM1
62
66
63−instance appFunction :: Applicative ((->) r) where
67+instance applyFunction :: Apply ((->) r) where
64− pure = return
65 (<*>) = ap
68 (<*>) = ap
66
69
70+instance applicativeFunction :: Applicative ((->) r) where
71+ pure = return
72+
67instance monadFunction :: Prelude.Monad ((->) r) where
73instance monadFunction :: Prelude.Monad ((->) r) where
68 return a r = a
74 return a r = a
69 (>>=) f g r = g (f r) r
75 (>>=) f g r = g (f r) r
@@ -75,6 +81,6 @@ runReader r f = f r
75test9 _ = runReader 0 $ do
81test9 _ = runReader 0 $ do
76 n <- ask
82 n <- ask
77 return $ n + 1
83 return $ n + 1
78−
84+
79main = Debug.Trace.trace (test7 "Done")
85main = Debug.Trace.trace (test7 "Done")
80
86
prelude/prelude.purs+7−3
@@ -59,10 +59,12 @@ module Prelude where
59
59
60 infixl 4 <*>
60 infixl 4 <*>
61
61
62− class (Functor f) <= Applicative f where
62+ class (Functor f) <= Apply f where
63− pure :: forall a. a -> f a
64 (<*>) :: forall a b. f (a -> b) -> f a -> f b
63 (<*>) :: forall a b. f (a -> b) -> f a -> f b
65
64
65+ class (Apply f) <= Applicative f where
66+ pure :: forall a. a -> f a
67+
66 liftA1 :: forall f a b. (Applicative f) => (a -> b) -> f a -> f b
68 liftA1 :: forall f a b. (Applicative f) => (a -> b) -> f a -> f b
67 liftA1 f a = pure f <*> a
69 liftA1 f a = pure f <*> a
68
70
@@ -390,9 +392,11 @@ module Control.Monad.Eff where
390 instance functorEff :: Functor (Eff e) where
392 instance functorEff :: Functor (Eff e) where
391 (<$>) = liftA1
393 (<$>) = liftA1
392
394
395+ instance applyEff :: Apply (Eff e) where
396+ (<*>) = ap
397+
393 instance applicativeEff :: Applicative (Eff e) where
398 instance applicativeEff :: Applicative (Eff e) where
394 pure = return
399 pure = return
395− (<*>) = ap
396
400
397 instance monadEff :: Monad (Eff e) where
401 instance monadEff :: Monad (Eff e) where
398 return = retEff
402 return = retEff