;; -*-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 stream)


  (import (standard-library core)
	  (standard-library promise)
	  (standard-library text-file-io))


  (define-param-logical-type :stream (%type)
    (:union (:pair (:promise %type) (:promise (:stream %type))) <null>))


  (define-param-logical-type :nonempty-stream (%type)
    (:pair (:promise %type) (:promise (:stream %type))))


  (define-param-logical-type :nonpure-stream (%type)
    (:union (:pair (:nonpure-promise %type)
		   (:nonpure-promise (:nonpure-stream %type))) <null>))


  (define-param-logical-type :nonempty-nonpure-stream (%type)
    (:pair (:nonpure-promise %type)
	   (:nonpure-promise (:nonpure-stream %type))))


  (declare stream-next (:param-proc (%type) ((:stream %type))
				    (:stream %type)
				    pure))


  (declare stream-value (:param-proc (%type) ((:stream %type))
				     %type
				     pure))


  (declare stream-empty? (:param-proc (%type) ((:stream %type))
				      <boolean>
				      pure))


  (declare stream->list (:param-proc (%type) ((:stream %type))
				     (:uniform-list %type)
				     pure))


  (declare list->stream (:param-proc (%type) ((:uniform-list %type))
				     (:stream %type)
				     pure))


  (declare nonpure-stream-next (:param-proc (%type) ((:nonpure-stream %type))
					    (:nonpure-stream %type)
					    nonpure))


  (declare nonpure-stream-value (:param-proc (%type) ((:nonpure-stream %type))
					     %type
					     nonpure))


  (declare nonpure-stream-empty? (:param-proc (%type) ((:nonpure-stream %type))
					      <boolean>
					      pure))


  (declare nonpure-stream->list (:param-proc (%type) ((:nonpure-stream %type))
					     (:uniform-list %type)
					     nonpure))


  (declare stream-map (:param-proc (%type1 %type2)
				   ((:procedure (%type1) %type2 pure)
				    (:stream %type1))
				   (:stream %type2)
				   pure))


  (declare stream-map-nonpure (:param-proc (%type1 %type2)
					   ((:procedure (%type1) %type2 nonpure)
					    (:stream %type1))
					   (:nonpure-stream %type2)
					   nonpure))


  (declare stream-for-each (:param-proc (%type1)
					((:procedure (%type1) <none> nonpure)
					 (:stream %type1))
					<none>
					nonpure))


  (declare nonpure-stream-map (:param-proc (%type1 %type2)
					   ((:procedure (%type1) %type2 nonpure)
					    (:nonpure-stream %type1))
					   (:nonpure-stream %type2)
					   nonpure))


  (declare nonpure-stream-for-each
	   (:param-proc (%type1)
			((:procedure (%type1) <none> nonpure)
			 (:nonpure-stream %type1))
			<none>
			nonpure))


  (declare make-input-expr-stream (:procedure (<input-port>)
					      (:nonpure-stream <object>)
					      nonpure)))
