Bulat Ziganshin wrote:
Thursday, April 20, 2006, 11:54:59 AM, you wrote:
lazyGet can only be used to read something that was written with
lazyPut. lazyPut writes the offset of the end of the serialised data at
the beginning, so that lazyGet can skip over it, and subsequent gets
start from the next item in the stream.
the problem is what there is ONLY ONE read pointer, so it should be
impossible to intersperse reading with `get` and consuming structure
returned by `lazyGet`, either for BinMem or BinIO
... hmm, on the other side they don't interspersed because there is
only one call to the unsafeInterleaveIO. closures returned by lazyGet
just should be evaluated STRICTLY after all other `get` operation. and
changing the `getAt` implementation to the following:
getAt bh p = do p0 <- tellBin bh
seekBin bh p
a <- get bh
seekBin bh p0
return a
should omit even this restriction
Ah yes, I forgot about this subtle restriction. The underlying
principle is that an individual 'get' or 'lazyGet' is atomic: it
traverses the whole stream before returning a result. There may be
'lazyGet' components in the result, but each one of those is atomic in
the same sense. So the file pointer never needs to be set to two values
simultaneously.
It's a bit hacky, but it works nicely.
can you recommend me paper to read about using Haskell class system?
well, how about this?
http://www.haskell.org/haskellwiki/Research_papers/Type_systems#Type_classes
There are several papers at the level you're interested in, I think:
Lennart's "Implementing Haskell Overloading" is a good one, and you
might find "Type classes in Haskell" (Hall/Hammond/Peyton Jones/Wadler)
useful, also "Implementing Type Classes" (Peterson/Jones).
Cheers,
Simon
_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users