[Haskell-cafe] Writing a Storable instance for a C union

Simon Marechal simon at banquise.net
Fri Dec 13 16:44:33 UTC 2013


On 12/13/2013 05:00 PM, Nikita Karetnikov wrote:
> Could anyone explain how to write a Storable instance for MyStruct?
> (The key field allows to determine the type of a value inside the
> union.)

You can peek the "key", and then, depending on its value, return a
different constructor :

data MyStruct = MyStructOne Foo
              | MyStructFour Integer
              | MyStructTwenty [Blah]




More information about the Haskell-Cafe mailing list