;; -*-theme-d-*-

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

;; Expected results: translation error
;;   The purpose of this test is to test the error message.


(define-proper-program (tests test461)


  (import (standard-library core)
	  (standard-library stream)
	  (standard-library promise)
	  (standard-library console-io)
	  (standard-library object-string-conversion))


  (define-param-proc my-stream-map (%type1 %type2)
		     (((proc (:procedure (%type1) %type2 pure))
		       (stm (:stream %type1)))
		      (:stream %type2)
		      pure)
    (match-type stm
      ((<null>) null)
      ((stm2 (:nonempty-stream %type1))
       (cons (proc (car stm2))
	     (delay (my-stream-map proc (stream-next stm2)))))))


  (define-param-proc my-stream-map-nonpure (%type1 %type2)
		     (((proc (:procedure (%type1) %type2 nonpure))
		       (stm (:stream %type1)))
		      (:nonpure-stream %type2)
		      nonpure)
    (match-type stm
      ((<null>) null)
      ((stm2 (:nonempty-stream %type1))
       (cons (proc (car stm2))
	     (delay-nonpure 
	      (my-stream-map-nonpure proc (stream-next stm2)))))))


  (define-simple-proc main (() <none> nonpure)
    (let* ((l1 '(1 2 3 4 5))
	   (stm (list->stream l1))
	   (stm2 (my-stream-map
		  (lambda (((i <integer>)) <integer> pure) (+ i 1))
		  stm))
	   (l2 (stream->list stm2))
	   (stm3 (my-stream-map
		  (lambda (((i <integer>)) <real> pure) (+ i 0.5))
		  stm))
	   (l3 (stream->list stm3))
	   (stm4 (my-stream-map-nonpure
		  (lambda (((i <integer>)) <string> nonpure)
		    (console-display-line "*")
		    (object->string i))
		  stm))
	   (l4 (nonpure-stream->list stm4)))
      (console-display-line l2)
      (console-display-line l3)
      (console-display-line l4))))
