[Haskell-cafe] DefaultSignature versus overlapping instance

Ole Krüger itstheimp at gmail.com
Wed Nov 2 14:45:40 UTC 2016


It seems the formatting got mutilated, so I am posting this in proper
format, again. I apologize for the spam.

Ahoy,

I have the following type class.

-- | An entity whose underlying information spans zero or more columns
class ResultEntity a where
    -- | Build an instance of @a@
    parseEntity :: RowParser a

    default parseEntity :: (EligibleDataType meta cons a) => RowParser a
    parseEntity = parseGeneric

The EligibleDataType constraint allows me to construct a RowParser with the
help of generics.
It is so minimal that I am considering to transform the hole thing into
this.

-- | An entity whose underlying information spans zero or more columns
class ResultEntity a where
    -- | Build an instance of @a at .
    parseEntity :: RowParser a

instance {-# OVERLAPPABLE #-} (EligibleDataType meta cons a) =>
ResultEntity a where
    parseEntity = parseGeneric

This makes defining new instances of ResultEntity obsolete for types that
already satisfy the EligibleDataType constraint (basically everything that
has a Generic instance).
And it is still possible to provide a hand-rolled instance.

Undecidable and overlapping instances seem like a big no-no. Even after
reading up on them, I can't get rid of the feeling that this might be
dangerous.
Is it dangerous? I am targeting GHC 8.0.1 with this.

- Ole
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20161102/87be8568/attachment.html>


More information about the Haskell-Cafe mailing list