aboutsummaryrefslogtreecommitdiff
path: root/guix/store.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2015-01-17 23:19:13 +0100
committerLudovic Courtès <ludo@gnu.org>2015-01-17 23:45:48 +0100
commit4e190c2803be09ea7d500087cb1a2e3efeb27ab5 (patch)
tree80ceecb89e1585ce138946bb48086be5f7201574 /guix/store.scm
parent81a97734e04fa40412b2d44ccfae1b4796257648 (diff)
downloadgnu-guix-4e190c2803be09ea7d500087cb1a2e3efeb27ab5.tar
gnu-guix-4e190c2803be09ea7d500087cb1a2e3efeb27ab5.tar.gz
store: Make '%store-monad' an alias for '%state-monad'.
* guix/store.scm (define-alias): New macro. (%store-monad, store-return, store-bind): Define as aliases of the corresponding %STATE-MONAD part. (store-lift, text-file, interned-file): Return STORE as a second value. (run-with-store): Use 'run-with-state'. * guix/packages.scm (set-guile-for-build, package-file): Return STORE as a second value. * guix/monads.scm: Remove part of the module commentary.
Diffstat (limited to 'guix/store.scm')
-rw-r--r--guix/store.scm38
1 files changed, 15 insertions, 23 deletions
diff --git a/guix/store.scm b/guix/store.scm
index 6fd34bc643..c3a1c57943 100644
--- a/guix/store.scm
+++ b/guix/store.scm
@@ -852,25 +852,15 @@ be used internally by the daemon's build hook."
;;; Store monad.
;;;
-;; return:: a -> StoreM a
-(define-inlinable (store-return value)
- "Return VALUE from a monadic function."
- ;; The monadic value is just this.
- (lambda (store)
- value))
-
-;; >>=:: StoreM a -> (a -> StoreM b) -> StoreM b
-(define-inlinable (store-bind mvalue mproc)
- "Bind MVALUE in MPROC."
- (lambda (store)
- (let* ((value (mvalue store))
- (mresult (mproc value)))
- (mresult store))))
+(define-syntax-rule (define-alias new old)
+ (define-syntax new (identifier-syntax old)))
-;; This is essentially a state monad
-(define-monad %store-monad
- (bind store-bind)
- (return store-return))
+;; The store monad allows us to (1) build sequences of operations in the
+;; store, and (2) make the store an implicit part of the execution context,
+;; rather than a parameter of every single function.
+(define-alias %store-monad %state-monad)
+(define-alias store-return state-return)
+(define-alias store-bind state-bind)
(define (store-lift proc)
"Lift PROC, a procedure whose first argument is a connection to the store,
@@ -878,7 +868,7 @@ in the store monad."
(define result
(lambda args
(lambda (store)
- (apply proc store args))))
+ (values (apply proc store args) store))))
(set-object-property! result 'documentation
(procedure-property proc 'documentation))
@@ -898,7 +888,8 @@ taking the store as its first argument."
"Return as a monadic value the absolute file name in the store of the file
containing TEXT, a string."
(lambda (store)
- (add-text-to-store store name text '())))
+ (values (add-text-to-store store name text '())
+ store)))
(define* (interned-file file #:optional name
#:key (recursive? #t))
@@ -909,8 +900,9 @@ When RECURSIVE? is true, the contents of FILE are added recursively; if FILE
designates a flat file and RECURSIVE? is true, its contents are added, and its
permission bits are kept."
(lambda (store)
- (add-to-store store (or name (basename file))
- recursive? "sha256" file)))
+ (values (add-to-store store (or name (basename file))
+ recursive? "sha256" file)
+ store)))
(define %guile-for-build
;; The derivation of the Guile to be used within the build environment,
@@ -925,7 +917,7 @@ permission bits are kept."
connection."
(parameterize ((%guile-for-build guile-for-build)
(%current-system system))
- (mval store)))
+ (run-with-state mval store)))
;;;