git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Another exampleg
85af234Phil Freeman
examples/passing/RebindableSyntax.purs+29−4
@@ -1,12 +1,37 @@
1module Main where
1module Main where
2
2
3−example :: String
3+example1 :: String
4−example = do
4+example1 = do
5 "Do"
5 "Do"
6 " notation"
6 " notation"
7 " for"
7 " for"
8− " monoids"
8+ " Semigroup"
9 where
9 where
10 (>>=) x f = x <> f unit
10 (>>=) x f = x <> f unit
11
11
12+(*>) :: forall f a b. (Apply f) => f a -> f b -> f b
13+(*>) fa fb = const id <$> fa <*> fb
14+
15+newtype Const a b = Const a
16+
17+runConst :: forall a b. Const a b -> a
18+runConst (Const a) = a
19+
20+instance functorConst :: Functor (Const a) where
21+ (<$>) _ (Const a) = Const a
22+
23+instance applyConst :: (Semigroup a) => Apply (Const a) where
24+ (<*>) (Const a1) (Const a2) = Const (a1 <> a2)
25+
26+example2 :: Const String Unit
27+example2 = do
28+ Const "Do"
29+ Const " notation"
30+ Const " for"
31+ Const " Apply"
32+ where
33+ (>>=) x f = x *> f unit
34+
35+main = do
36+ Debug.Trace.trace example1
12−main = Debug.Trace.trace example
37+ Debug.Trace.trace $ runConst example2