git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Maybe monad
commit974621e1021613e31c5ca41a18e21828da5de26e authorPhil Freeman <paf31@cantab.net> dateTue 26 Nov 2013, 14:45 (13 years ago) parent674d94d
1 file changed+11
examples/passing/Monad.ps+11
examples/passing/Monad.ps+11
@@ -7,9 +7,20 @@ id :: Monad Id
77id = { ret : Id
88 , bind : \ma f -> case ma of Id a -> f a }
99
10+data Maybe a = Nothing | Just a
11+
12+maybe :: Monad Maybe
13+maybe = { ret : Just
14+ , bind : \ma f -> case ma of
15+ Nothing -> Nothing
16+ Just a -> f a
17+ }
18+
1019test :: forall m. Monad m -> m Number
1120test = \m -> m.bind (m.ret 1) (\n1 ->
1221 m.bind (m.ret "Test") (\n2 ->
1322 m.ret n1))
1423
1524test1 = test id
25+
26+test2 = test maybe