From e650a80856edc1d1df1f163c3f84082455717fa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 18 Mar 2019 18:43:51 +0100 Subject: Compleately redid file structure. --- monad/stack.scm | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 monad/stack.scm (limited to 'monad/stack.scm') diff --git a/monad/stack.scm b/monad/stack.scm new file mode 100644 index 0000000..8d25303 --- /dev/null +++ b/monad/stack.scm @@ -0,0 +1,24 @@ +(define-module (monad stack) + #:export (pop peek push) + #:use-module (monad) + #:use-module (monad state)) + +;;; Simple stateful stack module for showing the state monad +;;; in action. These functions assume that they are in a +;;; (state list) monad. But dynamic types! + +;;; TODO test these for empty stack + +(define (pop) + (do st <- (get) + let top = (car st) + (put (cdr st)) + (return-state top))) + +(define (peek) + (do st <- (get) + (return-state (car st)))) + +(define (push v) + (do st <- (get) + (put (cons v st)))) -- cgit v1.2.3