When I have a data type like the following in haskell:
data A ctx = A (forall a. ctx a => a -> a)
Then I can put functions that work on values of types of a given class into this datatype:
> A (+3) :: A Num
A (+3) :: A Num :: A Num
But is it also possible to put functions which have multiple constraints into this datatype? I tried this:
> :t ((+ 3) . succ)
((+ 3) . succ) :: (Enum c, Num c) => c -> c
> :t A ((+ 3) . succ) :: A (Enum,Num)
Expecting one more argument to `Enum'
In an expression type signature: A (Enum, Num)
In the expression: A ((+ 3) . succ) :: A (Enum, Num)
So this doesn't work. How is it possible to do what I want, or is it impossible? I know one solution would be to use a "dummy" data type and a type family, but I don't want to do that if there is another way because of the it's complexity. Also, I this example I could have just used (+1) instead of succ, but there are more complex cases where such a transformation to just one class is not possible.
class (Num a, Enum a) => Foo a
? – Diffusion