I have a data type :
data BuildException a = KillBuild JobID a Stage
| FailBuild JobID a Stage
| CancelBuild JobID a Stage
| StopBuild JobID a Stage
deriving Typeable
where a has to have an instance for class Foo. I remember reading (in RWH, maybe) that
while it was possible to have class constraints in a data definition, it was not desirable.
What’s the proper way to do this then?
Simply apply the type constraints on functions that need it. For example:
There might even be some functions that don’t need the
Fooconstraint, which might make it possible for the client of your API to use a subset of it without having to define theFooconstraint! That wouldn’t be possible if it was part of the data record definition.