[Haskell-cafe] Re: Unwrapping newtypes

Kevin Jardine kevinjardine at gmail.com
Wed Sep 8 10:15:42 EDT 2010


Thanks Arie,

I'm going to make some of my bare Obj functions accept a ToObj
typeclass constraint and do the conversions inside there to avoid
cluttering up the wrapped object code.

Now that I know how to do this I'm going to see what more
restructuring I can do to make the difference between wrapped and bare
objects less visible (except of course where it should matter).

Kevin

On Sep 8, 3:44 pm, Arie Peterson <ar... at xs4all.nl> wrote:
> On Wed, 8 Sep 2010 05:51:22 -0700 (PDT), Kevin Jardine
>
>
>
> <kevinjard... 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
> <http://www.haskell.org/pipermail/libraries/2006-October/005950.html>
> 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.
>
> Regards,
>
> Arie
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-C... at haskell.orghttp://www.haskell.org/mailman/listinfo/haskell-cafe


More information about the Haskell-Cafe mailing list