Hello,<div><br></div><div>This post is (hopefully) literate Haskell. I recently noticed that there are two ways to specify instances in a common situation. Suppose I have something like this:</div><div><br></div><div>> {-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, NoMonomorphismRestriction, OverlappingInstances #-}</div>
<div>> </div><div>> data A = A</div><div>> data B = B</div><div>> data C = C</div><div>> </div><div>> newtype Repr a = Repr { unRepr :: State MyState a }</div><div>> </div><div>> class SomeClass a b where</div>
<div>> </div><div><br></div><div>If I want to make instances of SomeClass for Repr, A and Repr, B, I have two choices:</div><div><br></div><div>> instance SomeClass Repr A where</div><div>> instance SomeClass Repr B where</div>
<div>></div><div><br></div><div>or I can introduce a new class and make an instance with a context,</div><div><br></div><div><div>> class RClass c where</div><div>> </div><div>> instance RClass A where</div><div>
> instance RClass B where</div><div>> -- no C instance for RClass</div></div><div>> </div><div>> instance RClass x => SomeClass Repr x</div><div><br></div><div>is there any reason to prefer one form over the other? Of course the first requires more instance declarations, but they're auto-generated so that doesn't bother me.</div>
<div><br></div><div>Thanks,</div><div>John L.</div>