开发者

Haskell : runGetState and lists

开发者 https://www.devze.com 2023-02-22 03:50 出处:网络
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.

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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号