Hello haskell, is it possible to implement unsafeInterleaveST? why i want it: i have the following definitions: class (MonadHelper m) => Stream m h where vGetContents :: h -> m String -- default definition vGetContents h = mUnsafeInterleaveIO $ do eof <- vIsEOF h if eof then return [] else do x <- vGetChar h x `seq` return () xs <- vGetContents h return (x:xs) class (Monad m) => MonadHelper m where mUnsafeInterleaveIO :: m a -> m a instance MonadHelper IO where mUnsafeInterleaveIO = unsafeInterleaveIO instance MonadHelper (ST s) where mUnsafeInterleaveIO = id that allows to make much more efficient lazy implementation of vGetContents for streams that work in IO monad. on the other side, ST-based streams will need to build full list before returning from vGetContents. if the unsafeInterleaveST is possible, then this type of computations will become much more efficient moreover, this can be way to mix up several ST computations and to implicitly define parallelism in algorithm so that compiler can better optimize program -- Best regards, Bulat mailto:bulatz@HotPOP.com
On Mon, Feb 06, 2006 at 06:31:17PM +0300, Bulat Ziganshin wrote:
is it possible to implement unsafeInterleaveST?
I hope not. You surely shouldn't be able to implement this function without unsafe* functions, because that would break ST's guarantees. Hell, you would be able to return frozen ST computations from runST! Best regards Tomasz -- I am searching for programmers who are good at least in (Haskell || ML) && (Linux || FreeBSD || math) for work in Warsaw, Poland
Hello Tomasz, Monday, February 06, 2006, 8:29:32 PM, you wrote:
is it possible to implement unsafeInterleaveST?
TZ> I hope not. You surely shouldn't be able to implement this function TZ> without unsafe* functions, because that would break ST's guarantees. of course. i asked from language/library implementors. and of course it is already implemented and, at least in GHC, implementation is just the same as for IO, so if i will be smarter, i can done it myself TZ> Hell, you would be able to return frozen ST computations from runST! yes, i want exactly that, for the same reasons why one like the unsafe getContents implementation. if you are prefer to read entire files in memory, we are living in different worlds :) -- Best regards, Bulat mailto:bulatz@HotPOP.com
participants (2)
-
Bulat Ziganshin -
Tomasz Zielonka