You can use OverlappingInstances
pragma in this case as Box (a,a)
is more specific than Box (a,b)
so compiler will choose the right instance for you.
Informally, you say a
is more specific than b
if you can instantiate b
to a
. Another definition can be, if you unify a
and b
you get a
. For example, in (a,b)
you can put b
=a
, so (a,a)
is more specific than (a,b)
.
If compiler can not find the most specific instance it will throw error even with OverlappingInstances
.