On Sat, 3 Jan 2009, Henning Thielemann wrote:
I think I now have general Applicative functionality ...
I hope the following is a proper Monad implementation. In contrast to
Applicative a Writer for sequencing actions does no longer work, instead I
need a State monad.
newtype LazyIO a = LazyIO {runLazyIO :: StateT RunAll IO a}
data RunAll = RunAll
deriving Show
instance Monad LazyIO where
return x = LazyIO $ return x
x >>= f = LazyIO $
mapStateT unsafeInterleaveIO . runLazyIO . f =<<
mapStateT unsafeInterleaveIO (runLazyIO x)
instance MonadIO LazyIO where
liftIO m = LazyIO $ StateT $ \RunAll -> fmap (\x->(x,RunAll)) m
evalLazyIO :: LazyIO a -> IO a
evalLazyIO =
flip evalStateT RunAll . runLazyIO
I'll write some tests and upload it to Hackage.
Thank you for being a patient audience. ;-)
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe