
14 Dec
2013
14 Dec
'13
11:46 a.m.
It's as simple as :
peek p = do v0 <- peekByteOff p 0 case v0 of 1 -> MyStruct <$> peekByteOff p 4 2 -> FooStruct <$> peek...
But this function can only have a single type, hence my suggestion that you should create a union type to represent the C union :
type SomeUnion = MyStruct Byte | FooStruct Integer | ...
Yes, but I also want to poke, so SomeUnion must be an instance of Storable. Could you show how to define it properly or provide a workaround? I’m attaching some code, which is in the public domain, to demonstrate the problem. It was generated using c2hsc and hsc2hs. The lines marked with XXX were either modified or added by me.