
20 Nov
2002
20 Nov
'02
10:01 a.m.
\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.