When I have a data type such as haskell:
data A ctx = A (forall a. ctx a => a -> a)
Then I can put functions that work with the values of the types of this class into this data type:
> A (+3) :: A Num A (+3) :: A Num :: A Num
But is it also possible to put functions that have several limitations in this data type? 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 will not work. How can I do what I want, or is it impossible? I know that one solution would be to use the "dummy" data type and type family, but I don't want to do this if there is another way because of its complexity. In addition, in this example, I could just use (+1) instead of succ, but there are more complicated cases when such a conversion to only one class is impossible.
source share