git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Another exampleg
commit85af234687e45e9ba59b7215532d6e03cce62312 authorPhil Freeman <paf31@cantab.net> dateSun 15 Mar 2015, 15:43 (12 years ago) parentb432994
1 file changed+29−4
examples/passing/RebindableSyntax.purs+29−4
examples/passing/RebindableSyntax.purs+29−4
@@ -1,12 +1,37 @@
11module Main where
22
3−example :: String
4−example = do
3+example1 :: String
4+example1 = do
55 "Do"
66 " notation"
77 " for"
8− " monoids"
8+ " Semigroup"
99 where
1010 (>>=) x f = x <> f unit
1111
12−main = Debug.Trace.trace example
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
37+ Debug.Trace.trace $ runConst example2