\documentclass{article}
\usepackage{open-axiom}
\begin{document}
\title{src/algebra ituple.spad}
\author{Clifton J. Williamson}
\maketitle

\begin{abstract}
\end{abstract}
\tableofcontents
\eject

\section{domain ITUPLE InfiniteTuple}

<<domain ITUPLE InfiniteTuple>>=
import CoercibleTo OutputForm
import Boolean
import Stream
)abbrev domain ITUPLE InfiniteTuple
++ Infinite tuples for the interpreter
++ Author: Clifton J. Williamson
++ Date Created: 16 February 1990
++ Date Last Updated: February 5, 2011
++ Keywords:
++ Examples:
++ References:
++ Description:
++   This package implements 'infinite tuples' for the interpreter.
++   The representation is a stream.
InfiniteTuple(S:Type): Exports == Implementation where
  Exports == CoercibleTo OutputForm with
    map: (S -> S, %) -> %
      ++ map(f,t) replaces the tuple t
      ++ by \spad{[f(x) for x in t]}.
    filterWhile: (S -> Boolean, %) -> %
      ++ filterWhile(p,t) returns \spad{[x for x in t while p(x)]}.
    filterUntil: (S -> Boolean, %) -> %
      ++ filterUntil(p,t) returns \spad{[x for x in t while not p(x)]}.
    select: (S -> Boolean, %) -> %
      ++ select(p,t) returns \spad{[x for x in t | p(x)]}.
    generate: (S -> S,S) -> %
      ++ generate(f,s) returns \spad{[s,f(s),f(f(s)),...]}.
    construct: % -> Stream S
      ++ construct(t) converts an infinite tuple to a stream.
  Implementation == add
    Rep == Stream S
    generate(f,x) == per generate(f,x)$Stream(S)
    filterWhile(f, x) == per filterWhile(f,rep x)$Stream(S)
    filterUntil(f, x) == per filterUntil(f,rep x)$Stream(S)
    select(f, x) == per select(f,rep x)$Stream(S)
    construct x == rep x
    map(f,x) == per map(f, rep x)$Stream(S)
    coerce(x: %): OutputForm == rep(x)::OutputForm

@

\section{package ITFUN2 InfiniteTupleFunctions2}

<<package ITFUN2 InfiniteTupleFunctions2>>=
import Type
import InfiniteTuple
import Stream
)abbrev package ITFUN2 InfiniteTupleFunctions2
++ Description:
++   Functions defined on streams with entries in two sets.
InfiniteTupleFunctions2(A:Type,B:Type): Exports == Implementation where
  macro IT == InfiniteTuple
  Exports == Type with
    map: ((A -> B),IT A) -> IT B
      ++ \spad{map(f,[x0,x1,x2,...])} returns \spad{[f(x0),f(x1),f(x2),..]}.
  Implementation == add

    map(f,x) ==
      map(f,x pretend Stream(A))$StreamFunctions2(A,B) pretend IT(B)

@

\section{package ITFUN3 InfiniteTupleFunctions3}

<<package ITFUN3 InfiniteTupleFunctions3>>=
import Type
import InfiniteTuple
import Stream
)abbrev package ITFUN3 InfiniteTupleFunctions3
InfiniteTupleFunctions3(A:Type, B:Type,C:Type): Exports
 == Implementation where
   ++ Functions defined on streams with entries in two sets.
   IT   ==> InfiniteTuple
   ST   ==> Stream
   SF3  ==> StreamFunctions3(A,B,C)
   FUN  ==> ((A,B)->C)
   Exports ==> with
     map: (((A,B)->C), IT A, IT B) -> IT C
	++ map(f,a,b) \undocumented
     map: (((A,B)->C), ST A, IT B) -> ST C
	++ map(f,a,b) \undocumented
     map: (((A,B)->C), IT A, ST B) -> ST C
	++ map(f,a,b) \undocumented

   Implementation ==> add

     map(f:FUN, s1:IT A, s2:IT B):IT C ==
       map(f, s1 pretend Stream(A), s2 pretend Stream(B))$SF3 pretend IT(C)
     map(f:FUN, s1:ST A, s2:IT B):ST C ==
       map(f, s1, s2 pretend Stream(B))$SF3
     map(f:FUN, s1:IT A, s2:ST B):ST C ==
       map(f, s1 pretend Stream(A), s2)$SF3

@

\section{License}

<<license>>=
--Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd.
--All rights reserved.
--
--Redistribution and use in source and binary forms, with or without
--modification, are permitted provided that the following conditions are
--met:
--
--    - Redistributions of source code must retain the above copyright
--      notice, this list of conditions and the following disclaimer.
--
--    - Redistributions in binary form must reproduce the above copyright
--      notice, this list of conditions and the following disclaimer in
--      the documentation and/or other materials provided with the
--      distribution.
--
--    - Neither the name of The Numerical ALgorithms Group Ltd. nor the
--      names of its contributors may be used to endorse or promote products
--      derived from this software without specific prior written permission.
--
--THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
--IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
--TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
--PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
--OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
--EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
--PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
--PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
--LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
--NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
--SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@
<<*>>=
<<license>>

<<domain ITUPLE InfiniteTuple>>
<<package ITFUN2 InfiniteTupleFunctions2>>
<<package ITFUN3 InfiniteTupleFunctions3>>
@
\eject
\begin{thebibliography}{99}
\bibitem{1} nothing
\end{thebibliography}
\end{document}