From 2768ce6ef24e9660c444abd73f851068e1d2ffe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 12 Nov 2018 22:29:55 +0100 Subject: Add type signature comments to state-minimal. --- control/monad/state-minimal.scm | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/control/monad/state-minimal.scm b/control/monad/state-minimal.scm index 4fb40c2..aa7b1a0 100644 --- a/control/monad/state-minimal.scm +++ b/control/monad/state-minimal.scm @@ -11,30 +11,38 @@ ;;; like the Haskell version (of MonadState). But obviously ;;; without all the nice syntax. +;; newtype State = st-list -> st-list + +;; State (define ((get) st-list) "Sets the return value to the state value" (match st-list ((v st) (list st st)))) +;; v -> State (define ((put v) st-list) "Sets the state value to v, sets the return value to ()" (list '() v)) +;; State -> (v -> State) -> State (define ((bind st-proc proc) st-list) (let ((new-st-list (st-proc st-list))) (match new-st-list ((v _) ((proc v) new-st-list))))) +;; State -> State -> State (define ((then st-proc-1 st-proc-b) st-list-a) (let ((st-list-b (st-proc-1 st-list-a))) (st-proc-b st-list-b))) +;; v -> State (define ((return v) st-list) "Sets the return value to v" (cons v (cdr st-list))) +;; State -> v -> (r v) (define (run-state st-proc init) "Exec state with init as starting state value" (st-proc (list init init))) -- cgit v1.2.3