[Haskell-beginners] Data and Typeable for an opaque type

Elise Huard haskell at elisehuard.be
Tue Apr 28 09:37:49 UTC 2015


Hi,

I'm working on an open source patch, but stumbled upon the following
problem: I'm introducing a type that is basically a pointer in a FFI
library, pointing to an opaque type (which I'm told is common
practice).

-- | An opaque type encapsulating a font in C.
data Font_Opaque
type Font = Ptr Font_Opaque

The problem is that insertion in the current code would require this
to be an instance of Data and Typeable.

In this case (gloss library) I've not 100% understood why that's a
requirement, I've been grepping (case-insensitive) for typeOf, constr,
gfold, and I've not found any obvious use.

Anyway, the rough-and-ready approach for this would be to manually
define instances of Data and Typeable for the opaque type - my
question is: what would sensible implementations look like for such a
type?

Thank you,

Elise


More information about the Beginners mailing list