~jojo/Carth

ref: 749208029494a7c48ce04444a513424f4b998416 Carth/examples/list-monad.carth -rw-r--r-- 484 bytes
74920802JoJo update TODO 6 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
(import list)
(import io)

(define main
  (flip io/for (<o display show-triple)
        (list/iter (let1 ns (list 1 2 3 4 5 6 7 8 9)
                     (do list/bind
                         (<- x ns)
                         (<- y ns)
                         (<- z ns)
                         (list/when (=s x y z)
                                    (list [x y z])))))))

(define (show-triple [a b c])
  (apps str-append "[" (show-int a) " " (show-int b) " " (show-int c) "]"))