Hi Felipe,
On Tue, Nov 9, 2010 at 3:53 PM, Felipe Almeida Lessa
felipe.le...@gmail.com wrote:
On Tue, Nov 9, 2010 at 8:10 AM, C K Kashyap ckkash...@gmail.com wrote:
] I think I can restate my problem like this ---
]
] If I have a list of actions as follows -
]
] import Data.Word
] import
I'd use a parser combinator library that has word8 word16, word32
combinators. The latter should really have big and little endian
versions word16be, word16le, word32be, word32le.
Data.Binary should provide this and Attoparsec I think. Usually I roll
my own, but only because I had my own
Thanks Stephen,
On Tue, Nov 9, 2010 at 2:53 PM, Stephen Tetley stephen.tet...@gmail.com wrote:
I'd use a parser combinator library that has word8 word16, word32
combinators. The latter should really have big and little endian
versions word16be, word16le, word32be, word32le.
Data.Binary
2010/11/9 C K Kashyap ckkash...@gmail.com:
Thanks Stephen,
On Tue, Nov 9, 2010 at 2:53 PM, Stephen Tetley stephen.tet...@gmail.com
wrote:
I'd use a parser combinator library that has word8 word16, word32
combinators. The latter should really have big and little endian
versions word16be,
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
2010/11/9 C K Kashyap ckkash...@gmail.com:
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
On Tue, Nov 9, 2010 at 8:10 AM, C K Kashyap ckkash...@gmail.com wrote:
] 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
If we change the code a bit,
data MyAction = A1 Word8 | A2 Word16
a,b :: Get MyAction
a = A1 $ getWord8
b = A2 $ getWord16be
listOfActions :: [Get MyAction]
listOfActions = [a,b,a]
Now, we know how to execute the list of actions, and get the output as list.
Using the following guys:
2010/11/9 Ozgur Akgun ozgurak...@gmail.com:
If we change the code a bit,
data MyAction = A1 Word8 | A2 Word16
a,b :: Get MyAction
a = A1 $ getWord8
b = A2 $ getWord16be
listOfActions :: [Get MyAction]
listOfActions = [a,b,a]
Now, we know how to execute the list of actions, and get the
The original question was (I believe) how to drive the parsing with a
list of Actions, not the result be a list of Actions.
Yes ... the result needs to be a list of plain values - Int's
But I did not follow why you have dropped the word16
--
Regards,
Kashyap
Thanks Ozgur and Felipe,
Could you also show how I could actually use it to parse a bytestring please?
import qualified Data.ByteString.Lazy as BS
import Control.Applicative (($))
import Data.Word
import Data.Binary.Get
data MyAction = A1 Word8 | A2 Word16
a,b :: Get MyAction
a = A1 $
Okay, I think I got it .. I went with Ozgur's example -
data MyAction m = A1 (m Word8) | A2 (m Word16)
a = A1 getWord8
b = A2 getWord16be
listOfActions = [a,b,a]
newtype Id a = Id a
getAction :: MyAction Get - Get (MyAction Id)
getAction (A1 act) = A1 . Id $ act
getAction (A2 act) = A2 . Id
Oops .. I made a mistake .. I had gone with Felipe's solution -
getActions :: [MyAction Get] - Get [MyAction Id]
getActions = mapM getAction
--
Felipe.
Felpe, could you please confirm if
bs = BS.pack [1,0,2,4]
toVal (A1 (Id v)) = fromIntegral v :: Int
toVal (A2 (Id v)) = fromIntegral
13 matches
Mail list logo