[Haskell-cafe] (no subject)
Donald Bruce Stewart
dons at cse.unsw.edu.au
Thu May 24 05:30:59 EDT 2007
leaveye.guo:
> To read the handle openBinaryFile returns, both the hGetBuf and
> hGetBufNonBlocking needs one parameter _buf_ of type Ptr a.
> I can not get one data of that type.
>
> In the doc, there is only nullPtr, and also some type cast functions.
> I failed to find some other buffer-maker function.
>
> What should I do ?
I mean, what problem are you trying to solve? Ptrs aren't the usual way
to manipulate files in Haskell.
Here, for example, is a small program to print the first byte of a
binary file:
import System.IO
import qualified Data.ByteString as B
main = do
h <- openBinaryFile "a.out" ReadMode
s <- B.hGetContents h
print (B.head s)
When run:
$ ./a.out
127
Note there's no mallocs or pointers involved.
-- Don
More information about the Haskell-Cafe
mailing list