[Haskell-cafe] generic putback
dgorin at dc.uba.ar
Sun May 15 17:17:48 CEST 2011
I think you need to change the type of putback slightly:
putback :: a -> IO a -> IO (IO a)
putback a action =
do next <- newIORef a
return (do r <- readIORef next; writeIORef next =<< action; return r)
do getChar' <- putback 'a' getChar
str <- sequence $ take 10 $ repeat getChar'
On May 15, 2011, at 4:33 PM, Sergey Mironov wrote:
> Hi Cafe. I wonder if it is possible to write a IO putback function
> with following interface
> putback :: a -> IO a -> IO a
> putback x io = ???
> where io is some action like reading from file or socket.
> I want putback to build new action which will return x on first call,
> and continue executing io after that.
> Thanks in advance!
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe