simple cat by joining two infinite lists (intput/ouput)

Ahn Ki-yung kyagrd@bawi.org
Thu, 21 Nov 2002 00:01:51 +0900


\begin{code}

import IO

findM f [] = return Nothing
findM f (x:xs) = do { b <- f x; if b then return (Just x) else findM f xs }

isLeft (Left _) = True
isLeft _ = False

main =
	findM (>>=return.isLeft) $
		map (try . uncurry (>>=)) $
			zip (hGetCharS stdin) (hPutCharS stdout)
	where
		hGetCharS h = hGetChar h : hGetCharS h
		hPutCharS h = hPutChar h : hPutCharS h

\end{code}

Joining input list and output list by uncurried >>=
IO errors such as EOF are enclosed by try.
findM finds those EOF or IO errors.