From 5dcf423d97ee6dbb4adf8f18094b4a0c99772f3a Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Thu, 6 Mar 2025 15:55:13 +0100 Subject: Add state demo --- samples/fun/deepthought_state.bruijn | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 samples/fun/deepthought_state.bruijn (limited to 'samples') diff --git a/samples/fun/deepthought_state.bruijn b/samples/fun/deepthought_state.bruijn new file mode 100644 index 0000000..5f5cb36 --- /dev/null +++ b/samples/fun/deepthought_state.bruijn @@ -0,0 +1,18 @@ +# state monad example: logger/writer + +:import std/Combinator . +:import std/List . +:import std/Number . +:import std/Monad/State . + +log [[[[0 (1 ++ 2) 3]]]] + +deepthought answer >>= [correct >>= [check >>= [return]]] + answer log (+42) "Finding answer... " + correct log (0 =? (+42)) "Checking answer... " + check 0 (log [[0]] "Is correct!") (log [[0]] "Is false!") + return pure 2 + +:test (deepthought [[0]]) ([0 (+42) "Finding answer... Checking answer... Is correct!"]) + +main [deepthought [[0]] [[0]]] -- cgit v1.2.3