blob: fee48a63575f88229e2de684c195063c88a089d2 (
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
|
;;; Commentary:
;; 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
;;; Code:
(define-module (monad stack)
#:export (pop peek push)
#:use-module (monad)
#:use-module (monad state))
(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))))
|