I'm writing an open source patch to use a font library, or rather the haskell bindings to a font library in C (FTGL). I'm pointing to the Font type in one of the data structures, which is defined as follows:
我正在编写一个开源补丁来使用字体库,或者更确切地说是haskell绑定到C(FTGL)中的字体库。我指向其中一个数据结构中的Font类型,其定义如下:
type Font = Ptr Font_Opaque
data Font_Opaque
Unfortunately, to fit into the data structure of the library I'm patching, this type needs to be an instance of Data. Ptr already is, but Font_Opaque obviously isn't, so the compiler complains.
不幸的是,为了适应我正在修补的库的数据结构,这种类型需要是Data的一个实例。 Ptr已经是,但Font_Opaque显然不是,所以编译器抱怨。
As it's an opaque type I'm not sure how to proceed ... how to implement Data Font_Opaque in a more or less sensible way? Is there a sensible way?
因为它是一个不透明的类型,我不知道如何继续......如何以一种或多或少的合理方式实现Data Font_Opaque?有明智的方法吗?
1 个解决方案
#1
As the comment by András Kovács suggests, using the StandaloneDeriving language extension
正如AndrásKovács的评论建议的那样,使用StandaloneDeriving语言扩展
{-# LANGUAGE StandaloneDeriving -#}
and then:
deriving instance Data Font_Opaque
did the trick, at least where the compiler is concerned. I'll report back if this affects the program in any way. Thanks!
诀窍,至少在编译器方面。如果这会以任何方式影响程序,我会报告回来。谢谢!
#1
As the comment by András Kovács suggests, using the StandaloneDeriving language extension
正如AndrásKovács的评论建议的那样,使用StandaloneDeriving语言扩展
{-# LANGUAGE StandaloneDeriving -#}
and then:
deriving instance Data Font_Opaque
did the trick, at least where the compiler is concerned. I'll report back if this affects the program in any way. Thanks!
诀窍,至少在编译器方面。如果这会以任何方式影响程序,我会报告回来。谢谢!