Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: Data and Typeable for an opaque type (Ertugrul S?ylemez)
----------------------------------------------------------------------
Message: 1
Date: Tue, 28 Apr 2015 16:29:42 +0200
From: Ertugrul S?ylemez <[email protected]>
To: Elise Huard <[email protected]>, The Haskell-Beginners Mailing
List - Discussion of primarily beginner-level topics related to
Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Data and Typeable for an opaque type
Message-ID: <[email protected]_W_723V_1_36_000>
Content-Type: text/plain; charset="us-ascii"
> data Font_Opaque
> type Font = Ptr Font_Opaque
>
> [...]
>
> 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?
Manual instances of those are usually highly questionable. While you
probably won't blow up anything with a manual Data instance, a manual
Typeable instance is in the critical danger zone alongside unsafeCoerce.
First of all Ptr is already Typeable and for concrete types like
Font_Opaque you can derive Typeable. That makes Font Typeable.
If you need a Data instance for processing, then one way to get it is to
build an isomorphism between Font and a regular Haskell type. Start by
rewriting Font to be a newtype wrapper. Derive Data for the helper type
and write the Data instance for Font in terms of it. This might save
you a lot of work, or it may create even more work depending on the API
you're depending on.
Final alternative: You do what many of us have done many times. In
some cases implementing a Haskell variant of a foreign library from
scratch is more efficient than trying to deal with a clumsy C API.
Often this is not an option, but when it is, it's usually a good one.
Greets,
Ertugrul
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 472 bytes
Desc: not available
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150428/a42ed748/attachment-0001.sig>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 82, Issue 43
*****************************************