~jojo/Carth

ref: 55fb4f948f1f3797078b584dc60b4f7dd68b37ed Carth/examples/list-monad.carth -rw-r--r-- 484 bytes
55fb4f94JoJo Check `cast` in Infer instead of Gen 4 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) "]"))