Hi guys,
Thanks for all the previous help I'm having with serialization in Haskell, I couldn't have gotten as far as I have without the help from this group. Many thanks!
Now I've put you in a good mood, maybe you can help me with my latest problem... :-)
I have the following code which reads strings from a handle;
import qualified Data.ByteString.Lazy.UTF8 as UTF
readNames 0 _ = []
readNames n h = do
length <- fmap (fromIntegral . runGet getWord32be) $ L.hGet h 4
name <- L.hGet h length
(UTF.toString name) : readNames (n-1) h
Where n is the number of names remaining to read and h is the handle to the stream that I'm reading from. It is my intention that this function would return a [String] of all the names. I'm sure further explainations probably aren't necessary, but just in case;
- "length" becomes equal to some number (represented by four bytes) which describes the length of the string to read
- "name" becomes the string I'm trying to read
- Then I add that String to the list and go again
But the problem I'm getting is this;
Couldn't match expected type `[a]' against inferred type `IO b'
In a stmt of a 'do' expression:
length <- fmap (fromIntegral . runGet getWord32be) $ L.hGet h 4
In the expression:
do { length <- fmap (fromIntegral . runGet getWord32be)
$ L.hGet h 4;
name <- L.hGet h length;
(UTF.toString name) : readNames (n - 1) h }