[Haskell-cafe] Re: Unwrapping newtypes

Ertugrul Soeylemez es at ertes.de
Thu Sep 9 05:10:14 EDT 2010

Kevin Jardine <kevinjardine at gmail.com> wrote:

> My goal was to find a way to define all that was needed using
> Haskell's automatic instance deriving mechanism. Haskell can
> automatically derive Foldable, which is why I was looking at that.
> However, that requires writing two lines for each wrapper newtype to
> get around the kind problem.
> I wanted one line.


  newtype Blog    = Blog    { getBlogObj    :: Obj }
  newtype Comment = Comment { getCommentObj :: Obj }
  newtype User    = User    { getUserObj    :: Obj }

  class GetObject a where getObject :: a -> Obj
  instance GetObject Blog    where getObject = getBlogObject
  instance GetObject Comment where getObject = getCommentObject
  instance GetObject User    where getObject = getUserObject

You shouldn't abuse Foldable for this purpose, unless you really mean

> I agree that the Foldable solution was a bit of a kludge.

And not necessary either.


nightmare = unsafePerformIO (getWrongWife >>= sex)

More information about the Haskell-Cafe mailing list