[Haskell-cafe] Re: Unwrapping newtypes

Kevin Jardine kevinjardine at gmail.com
Thu Sep 9 05:35:52 EDT 2010


Hi Ertugrul,

if you look back earlier in this thread, you'll see that

{-# LANGUAGE GeneralizedNewtypeDeriving #-}

allows me to write genuine one line definitions for each wrapper type.

Eg.

newtype Blog = Blog Obj deriving ToObj

There is no need to code the instances as GHC will do that for you.

Figuring out how to avoid writing the instances was the point of my
original post.

Kevin

On Sep 9, 11:10 am, Ertugrul Soeylemez <e... at ertes.de> wrote:
> Kevin Jardine <kevinjard... 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.
>
> There:
>
>   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
> it.
>
> > I agree that the Foldable solution was a bit of a kludge.
>
> And not necessary either.
>
> Greets,
> Ertugrul
>
> --
> nightmare = unsafePerformIO (getWrongWife >>= sex)http://ertes.de/
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-C... at haskell.orghttp://www.haskell.org/mailman/listinfo/haskell-cafe


More information about the Haskell-Cafe mailing list