[Haskell-cafe] Re: Unwrapping newtypes
kevinjardine at gmail.com
Wed Sep 8 10:15:42 EDT 2010
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).
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
> 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.
> Haskell-Cafe mailing list
> Haskell-C... at haskell.orghttp://www.haskell.org/mailman/listinfo/haskell-cafe
More information about the Haskell-Cafe