[Haskell-cafe] Re: Unwrapping newtypes

Arie Peterson ariep at xs4all.nl
Wed Sep 8 09:44:19 EDT 2010

On Wed, 8 Sep 2010 05:51:22 -0700 (PDT), Kevin Jardine
<kevinjardine at gmail.com> wrote:
> Ah, I was missing an important piece of the puzzle.
> If I write:
> class ToObj a where
>     toObj :: a -> Obj
> instance ToObj Obj where
>     toObj a = a
> then
> newtype Blog = Blog Obj deriving ToObj
> works!

This post
describes a general mini-library for this situation (having a
structure-indicating newtype of an underlying type). The 'Unpack' class
is a generalised version of your 'ToObj' class. Maybe it is useful to
compare (or even use), especially the smart ways in which you can use
this class to hide much of the wrapping/unwrapping.



More information about the Haskell-Cafe mailing list