I can put constraints superclass; I can put constraints on particular methods in the class; I can put extra constraints on instances for the class. Constraints are implemented as dictionary-passing. Does that mean different overloadings for a method get different numbers of dictionary arguments? Consider:
class Bar1 a -- just some classes
class Bar2 a
class Bar3 a
class Bar4 a
class Bar5 a
class (Bar1 a, Bar2 a) => Foo a where
foo :: Bar3 b => a -> b -> Bool -- `b` is not in class head
instance (Bar1 (Maybe a), Bar2 (Maybe a), -- needed from superclass
-- ?but (Bar3 b) not needed (nor could it be expressed)
Bar4 (Maybe a), Bar5 a) -- additional instance-specific, Bar5 is for part of instance head
=> Foo (Maybe a) where
foo x y = True
As I understand from this q, the Bar
s not having methods doesn't matter.
So different instances of Foo
might have different instance-specific constraints, some maybe for the whole instance head, some for only part -- like Bar5 a
within the Maybe a
. Does that mean that function foo
specialised for (Maybe a)
needs a different number of dictionaries passed, vs say for Int
? How is that organised?
Reason for asking is this thread, where SPJ talks about "bindSet
takes two Ord
parameters at
run-time, whereas ordinary bind
does not". (Yes quite true, but bindSet
is not a method of a class.) I'm wondering if there's already a mechanism for a method's instances taking different numbers of dictionary parameters?