While the answers so far are correct in that it's not possible to do in general, it is almost possible to do in your case. It seems to me like you were given this as a task, so I'll only give you some hints/pointers:
- it's not possible to do in general, for two arbitrary functions of type
a -> b
- so it must mean that you're supposed to use something additional that you've been provided
- in mathematics, for two functions to be, it is often considered enough for them to be equal "on all points", i.e. for all input values x, f(x) == g(x)
- in your case, you can indeed check that the results are equal - you have an
Eq b
, allowing you to compare the results of two functions of type a -> b
- the only thing you need to figure out is - do you have something else, which would allow you to check all values of type
a
?
The answer is no, but only because I don't think it's possible to do without an additional constraint on what a
should be (what other instances it should have) - you can already "go through" values of type a
by using Enum
, but you don't really know "where to start".