In my Haskell program, I have an ADT with many constructors:
data MyData = Con1 |
Con2 |
...
Con20
I have a function foreign export ccallthat wraps [MyData]in an array StablePtr's. After calling it, I need to determine which constructor was used to build each element.
It can be solved this way.
foreign export ccall getType :: StablePtr MyData -> IO CInt
getType (Con1) = return 1
getType (Con2) = return 2
...
but then I will need to manually define these constants in the C header. This is error prone, so I wonder if there is a way to get GHC to do this work for me.
source
share