[Haskell-cafe] DefaultSignature versus overlapping instance

Ole Krüger itstheimp at gmail.com
Tue Nov 1 23:29:38 UTC 2016


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 at .
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). 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/20161101/418ced49/attachment.html>


More information about the Haskell-Cafe mailing list