Since these flexible contexts and instances aren't available in the Haskell standard, I assume there are potential problems when using them. What are they? Can they lead to some ambiguity, undecidability, overlapping instances, etc.?
There is a similar question that asks only about FlexibleInstances
, not FlexibleContexts
, but the answer only says "that it's safe to use them".
I once stumbled upon the following. Answering this question, I first tried this code:
And got a compilation error and a suggestion by GHCi to add the
FlexibleContexts
option. When I did, it compiled OK. But this was actually not a right thing to do, as the constraint declaration introduced new scope for type variables, andb
ingenome
's type signature became completely unrelated to the one in the type class; yetFlexibleContexts
provided a cover for this.With the constraint specified properly at the type class level,
it passed compilation without requiring the
FlexibleContexts
option.