aboutsummaryrefslogtreecommitdiffstats
path: root/examples/purity-test.milch
blob: 6e8faea47e2ad01d1b6da507eb4a337e252ca74d (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
; utils

(let! println! (\![x]
    (print! (fmt "{0}\n" [x]))))

; pure vs. impure demo

; this is a pure function
(let! f (\[x] x))

(f 10) ; works

; this is an impure function
(let! g! (\![x] (println! x)))

(g! "foo") ; works

; this is a pure function that tries to call an impure function
(let! h (\[x] (g! x)))

(h "bar")
; error: cannot call impure function in pure context
;   when calling function g! at examples/purity-test.milch:19:15
;   in a function definition at examples/purity-test.milch:19:12
;   when calling function h at examples/purity-test.milch:21:1