;; -*-theme-d-*-

;; Copyright (C) 2016 Tommi Höynälänmaa
;; Distributed under GNU Lesser General Public License version 3,
;; see file doc/LGPL-3.

(define-interface (standard-library promise)


  (import (standard-library core))


  (define-param-logical-type :promise (%type)
    (:procedure () %type pure))


  (define-param-logical-type :nonpure-promise (%type)
    (:procedure () %type nonpure))


  (declare make-promise (:param-proc (%type)
				     ((:procedure () %type pure))
				     (:promise %type)
				     pure))

  (define-syntax delay
    (syntax-rules ()
      ((delay expression)
       (make-promise (lambda-automatic (() pure) expression)))))


  (declare force (:param-proc (%type)
			      ((:promise %type))
			      %type
			      pure))


  (declare make-nonpure-promise (:param-proc (%type)
					    ((:procedure () %type nonpure))
					    (:nonpure-promise %type)
					    pure))


  (define-syntax delay-nonpure
    (syntax-rules ()
      ((delay expression)
       (make-nonpure-promise (lambda-automatic (() nonpure) expression)))))


  (declare force-nonpure (:param-proc (%type)
				      ((:nonpure-promise %type))
				      %type
				      nonpure)))
