From f8578936553468785ff1c70fb7f4b0efebfbf55d Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Mon, 26 Sep 2022 16:29:32 +0300 Subject: Add maybe concept --- examples/algebraic-types-concept.lisp | 19 ------------------- examples/maybe.lisp | 28 ++++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 19 deletions(-) delete mode 100644 examples/algebraic-types-concept.lisp create mode 100644 examples/maybe.lisp diff --git a/examples/algebraic-types-concept.lisp b/examples/algebraic-types-concept.lisp deleted file mode 100644 index 315a693..0000000 --- a/examples/algebraic-types-concept.lisp +++ /dev/null @@ -1,19 +0,0 @@ -(let just (\[a] - ["maybe" "just" a])) -(let nothing (\[] - ["maybe" "nothing"])) - -(let at (\[n seq] - (match seq - [] (nothing) - (match n - 0 (head seq) - (at (- n 1) (tail seq)))))) - -(let from-just (at 2)) -(let kind (at 1)) - -(let m (just 10)) -(match (kind m) - "just" (from-just m) - "nothing" "nothing") diff --git a/examples/maybe.lisp b/examples/maybe.lisp new file mode 100644 index 0000000..ce2cd03 --- /dev/null +++ b/examples/maybe.lisp @@ -0,0 +1,28 @@ +; LIB + +(let just (\[a] + ["maybe" "just" a])) +(let nothing (\[] + ["maybe" "nothing"])) + +(let at (\[n seq] + (match seq + [] (nothing) + (match n + 0 (head seq) + (at (- n 1) (tail seq)))))) + +(let from-just (at 2)) +(let kind (at 1)) + +(let map (\[f m] + (match (kind m) + "just" (just (f (from-just m))) + "nothing"))) + +; TESTING + +(let m (just 10)) +(match (kind m) + "just" (from-just m) + "nothing" "nothing") -- cgit v1.3