Skip to content

Commit 0b60d08

Browse files
committed
Do notation example
1 parent e387cc2 commit 0b60d08

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

Main.hs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ compile input = do
5151
case P.compile modules of
5252
Left error ->
5353
return $ Response $ Left error
54-
Right (js, externs, _) ->
54+
Right (js, externs, _) ->
5555
return $ Response $ Right $ Compiled js externs
5656

5757
str :: String -> String
@@ -201,6 +201,27 @@ examples =
201201
, "isEven 0 = true"
202202
, "isEven n = isOdd (n - 1)"
203203
]))
204+
, ("do",
205+
("Do Notation",
206+
unlines [ "module DoNotation where"
207+
, ""
208+
, "data Maybe a = Nothing | Just a"
209+
, ""
210+
, "bindMaybe Nothing _ = Nothing"
211+
, "bindMaybe (Just a) f = f a"
212+
, ""
213+
, "maybe = { ret: Just, bind: bindMaybe }"
214+
, ""
215+
, "isEven n | n % 2 == 0 = Just {}"
216+
, "isEven _ = Nothing"
217+
, ""
218+
, "evenSum a b = maybe do"
219+
, " n <- a"
220+
, " m <- b"
221+
, " let sum = n + m"
222+
, " isEven sum"
223+
, " return sum"
224+
]))
204225
]
205226

206227
page :: Maybe String -> Maybe Response -> ActionM ()

0 commit comments

Comments
 (0)