blob: 3b67f604844a83f1c13e5b46273be9534b03d520 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
;; (read-enable 'curly-infix)
;;; Examples:
;;; These are do in the conext of the optional monad.
(add-to-load-path (dirname (current-filename)))
(use-modules (control monad)
(data monoid)
(data optional)
(data writer))
(do x <- (just 10)
x) ; => 10
(do let y = (just 10)
x <- y
(+ x 5)) ; => 15
(do x <- (nothing)
(+ x 5)) ; => [Nothing]
(do x <- (just 10)
y <- (just 20)
(+ x y)) ; => 30
;;;
;; Int -> Writer Int String
(define (log-number n)
(writer n (format #f "Got nuber: ~a" n)))
(do a <- (log-number 3)
b <- (log-number 5)
(writer (* a b) ""))
;; => [Writer 15, "Got nuber: 3, Got nuber: 5, "]
|