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


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


  (declare <my-rec-proc> :union)


  (define <my-rec-proc> (:union
			 (:procedure
			  ((:uniform-list <integer>)
			   (:procedure (<integer>) <integer> pure)
			   <my-rec-proc>)
			  (:uniform-list <integer>)
			  pure)
			 <null>))


  (define <my-nonempty-rec-proc>
    (:procedure
     ((:uniform-list <integer>)
      (:procedure (<integer>) <integer> pure)
      <my-rec-proc>)
     (:uniform-list <integer>)
     pure))


  (define-simple-proc my-map (((l (:uniform-list <integer>))
			       (proc (:procedure (<integer>) <integer> pure))
			       (proc-next <my-rec-proc>))
			      (:uniform-list <integer>)
			      pure)
    (match-type l
      ((<null>) null)
      ((l1 (:nonempty-uniform-list <integer>))
       (begin
	 (cons (proc (car l1))
	       ((cast <my-nonempty-rec-proc> 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))))
