diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2022-12-05 14:19:12 +0200 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2022-12-05 14:21:53 +0200 |
| commit | 4002b8988c799a904ef1f359d4267ef4ad80cba3 (patch) | |
| tree | dbb67560f3a44c57df4b0e960861f60605ceb45f /examples/purity-test.milch | |
| parent | bba047ae945ae7d7899d6e2c1610923bcedb0442 (diff) | |
Rename project to Milch
Diffstat (limited to 'examples/purity-test.milch')
| -rw-r--r-- | examples/purity-test.milch | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/examples/purity-test.milch b/examples/purity-test.milch new file mode 100644 index 0000000..6e8faea --- /dev/null +++ b/examples/purity-test.milch @@ -0,0 +1,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 |
