Haskell : runGetState and lists
Hello I am trying to write a simple binary parser in Haskell using the runGetState monad.
However, I am faced with the problem of parsing a list of fields and I am stuck.
The problem is that the list of fields can change from time to time thus I want to construct the list fields and then read them in using a map. Code snippet below:
readField field_type =
case (field_type) of
0 -> A1 <$> getWord8
132 -> A2 <$> getWord16be
134 -> A3 <$> getWord32be
parseData fields = return $ map (\x -> readField x) a
(fdata,input,no) <- return (runGetState 开发者_StackOverflow(parseData [132,134,0]) input no)
I tried the above solution without luck. Can anyone tell me what I am doing wrong?
Looks like it should be something like
parseData = mapM readField
精彩评论