Hi Christopher,
What you want is to make
b
(anda
) depend onf
. This can be done in several ways.With functional dependencies:
class (Integral a, Num b) => PartialSum a b f | f -> a b where partialSum :: f -> a -> b instance (Integral a, Num b) => PartialSum a b (a -> b) where partialSum f n = foldl (\u v -> u + f v) 0 [1..n]
With type families:
class PartialSum f where type End f type Res f partialSum' :: f -> End f -> Res f instance (Integral a, Num b) => PartialSum (a -> b) where type End (a -> b) = a type Res (a -> b) = b partialSum f n = foldl (\u v -> u + f v) 0 [1..n]
I can’t see though what you’re trying to achieve. Could you provide some more use cases for that class?