2010/11/9 C K Kashyap <[email protected]>:
> I think I can restate my problem like this ---
>
> If I have a list of actions as follows -
>
> import Data.Word
> import Data.Binary.Get
>
> data MyAction = A1 (Get Word8) | A2 (Get Word16)
>
> a = A1 getWord8
> b = A2 getWord16be
>
> listOfActions = [a,b,a]
>
> How can I execute the "listOfActions" inside of a Get Monad and get
> the output as a list?

Since you want the result as a list, by somehow mapping over a list of
action, and since lists are homogeneous in Haskell, you need each
action to have the same result type. Something like:

performAction :: MyAction -> Get Int
performAction A1 = getWord8 >>= return . someHypotheticalWordToIntYouWouldLike

Notice that I have rewritten your

data MyAction = A1 (Get Word8)

as simply

data MyAction = A1

because it seems your A1 action will always be getWord8.

Now, you don't need specifically a list of MyAction and map
performAction on it: you can achieve the same thing with:

sequence [getWord8 >>= return . someHypotheticalWordToIntYouWouldLike, ...]

Cheers,
Thu
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to