Hello minh, Wednesday, April 5, 2006, 10:41:02 PM, you wrote:
but in 1/, i have to choose between different kind of array representation (and i dont know which one is better) and it seems to me that the resulting code (compiled) would have to be the same.
no, the code will be slightly different. IOUArray will allocate space in the GHC's heap, while malloc - in the C heap (ghc's heap is additional storey on the C heap) btw, `getElems` is VERY INEEFECIENT way - it will convert entire array to the list before return
for example, the couples (hGet*,peek/readArray) could be written in one line; also, one line for the reading/reconstructing more-than-one-Word8 value.
is it already possible ? would it be interesting to add such capabilities to haskell ? (i think so) i can try to add it but i need some pointers about how to do it.
i don't see much problems here, just add peek16LE and other procedures like it and you can use trivial code: idLength <- peek8 a 1 x <- peek16LE a 8 peek8 a i = do (x::Word8) <- peekByteOff a i return (fromIntegral x) peek16LE a i = do (x::Word8) <- peekByteOff a i (y::Word8) <- peekByteOff a (i+1) return (fromIntegral x + fromIntegral y * 256 ) there are a couple of binary I/O libs (including my own one :) ), i just don't think you need such power here. of course, if you want to read data sequentially, binary i/o lib will be preferable. with my lib you can write smth like this: -- Create new MemBuf filled with data from file h <- readFromFile "test" -- Read header fields sequentially idLength <- getWord8 h x <- getWord16le h .... i attached here a part of my library docs where this described in much more details :) the lib itself is at http://freearc.narod.ru/Streams.tar.gz -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com