Overlapping instances

class SomeClass (m :: Type -> Type)

instance someClassArray :: SomeClass Array

instance someClassNewtype :: (Newtype (t a) (m a), SomeClass m) => SomeClass t

This gives me the error

  Overlapping type class instances found for

    Control.MonadPlus.SomeClass t

  The following instances were found:

    Control.MonadPlus.someClassArray
    Control.MonadPlus.someClassNewtype


in type class instance

  Control.MonadPlus.SomeClass t
PureScript(OverlappingInstances)

I don’t understand this.

Newtype
Array

Array is not a Newtype. I don’t see how they’re overlapping. Does the compiler not see the (Newtype (t a) (m a), SomeClass m) dependency?

Correct, those constraints are checked after picking the instance based just on the part after the =>, so SomeClass t will overlap with everything.

There’s lots of discussion in this space at https://github.com/purescript/purescript/issues/3596

You can use instance chains to make the error go away, but it might not really be what you want

1 Like

Instance chains seems sufficient. Thank you, very cool.