;; -*-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 and running OK


(define-proper-program (tests test464)


  (import (standard-library core)
	  (standard-library console-io))


  (declare :my-rec-proc <param-logical-type>)


  (define-param-logical-type :my-rec-proc (%type1 %type2)
    (:union
     (:procedure
      ((:uniform-list %type1)
       (:procedure (%type1) %type2 pure)
       (:my-rec-proc %type1 %type2))
      (:uniform-list %type2)
      pure)
     <null>))


  (define-param-logical-type :my-nonempty-rec-proc (%type1 %type2)
    (:procedure
     ((:uniform-list %type1)
      (:procedure (%type1) %type2 pure)
      (:my-rec-proc %type1 %type2))
     (:uniform-list %type2)
     pure))


  (define-param-proc my-map (%type1 %type2)
      (((l (:uniform-list %type1))
	(proc (:procedure (%type1) %type2 pure))
	(proc-next (:my-rec-proc %type1 %type2)))
       (:uniform-list %type2)
       pure)
    (match-type l
      ((<null>) null)
      ((l1 (:nonempty-uniform-list %type1))
       (begin
	 (cons (proc (car l1))
	       ((cast (:my-nonempty-rec-proc %type1 %type2) proc-next)
		(cdr l1) proc my-map))))))


  (define-simple-proc my-proc (((i <integer>)) <integer> pure)
    (+ i 1))


  (define-simple-proc main (() <none> nonpure)
    (let* ((l1 '(1 2 3 4 5))
	   (l2 (my-map l1 my-proc my-map)))
      (console-display-line l2))))
