NewBinary/ BinMem and IO monad

I'm trying to write some true type library (implementing only the tables I need at the moment). When loading a font file it doesn't make sense to "parse" every table which isn't needed. So lazyness of haskell would perfectly meet requirements here. My problem: NewBinary supports memory buffers. After loading a file to mem it can't change anymore so I no longer need an IO monad. It looks like this: bh <- readBinMem "file" b::Word8 <- get bh Of cause I can't remove the monad here because bh contains an internal pointer to the current position... but it might be done returning the new pointer: (bh2,b::Word8) = get bh ? Then I would be able to lazily parse the tables eg: getTable1 bh = do bh = seek bh offset -- seek to the beginning of the table get binary data and build internal representation return list of glyph and outlines and ... of cause this mem should be readonly then.. Would it make sense to implement this? Does it already exist? Marc

Hello Marc, Thursday, May 4, 2006, 2:21:58 AM, you wrote:
getTable1 bh = do bh = seek bh offset -- seek to the beginning of the table get binary data and build internal representation return list of glyph and outlines and ...
just add unsafePerformIO: getTable1 bh = unsafePerformIO $ do seek bh offset -- seek to the beginning of the table get binary data and build internal representation return list of glyph and outlines and ... -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

Hello Marc, Saturday, May 6, 2006, 2:39:46 AM, you wrote:
just add unsafePerformIO: great idea! In my case I can also use unsafeInterleaveIO or lazyness, can't I?
sorry, i don't remember your case, next time add more citation. in general 'unsafeInterleaveIO' can be used only in IO context, if you want to create computation that will be executed only later: contents <- unsafeInterleaveIO (readFile name) if you don't have IO context, you can't use this function -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com
participants (2)
-
Bulat Ziganshin
-
Marc Weber