NewBinary/ BinMem and IO monad

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

NewBinary/ BinMem and IO monad

Marc Weber
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
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: NewBinary/ BinMem and IO monad

Bulat Ziganshin-2
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:[hidden email]

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: NewBinary/ BinMem and IO monad

Marc Weber
> just add unsafePerformIO:
great idea!
In my case I can also use unsafeInterleaveIO or lazyness, can't I?

Marc
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: NewBinary/ BinMem and IO monad

Marc Weber
On Sat, May 06, 2006 at 12:39:46AM +0200, Marc Weber wrote:
> > just add unsafePerformIO:
> great idea!
> In my case I can also use unsafeInterleaveIO or lazyness, can't I?
Of cause I can't. unsafePerformIO is of type IO a -> IO a.

Sorry for posting before thinking ;)

Marc
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re[2]: NewBinary/ BinMem and IO monad

Bulat Ziganshin-2
In reply to this post by Marc Weber
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:[hidden email]

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe