Improving the instances of Data.Functor.{Product,Sum}
Henning Thielemann
lemming at henning-thielemann.de
Sat Mar 14 07:29:32 UTC 2020
On Fri, 13 Mar 2020, chessai . wrote:
> Could you expound on why you try to avoid Flexible{Contexts,Instances}
> in your own code? That might be useful to look at here.
I also try to avoid FlexibleInstances. FlexibleInstances are sometimes a
consequence of multi-parameter type classes with too many parameters. E.g.
instance Convert Int a
instance Convert Integer a
which should be better a single-parameter type class on the first
parameter.
FlexibleInstances might indicate too lax instances. E.g.
instance C (A a) (B a) where
should be better
isntance (a~b) => C (A a) (B b) where
Sometimes they are a sign of non-composability. E.g.
instance StringClass String where
should be better
instance CharClass a => StringClass [a] where
or
instance (a ~ Char) => StringClass [a] where
depending, on what you need.
More information about the Libraries
mailing list