Reputation:
I've made this data type, which has a lot of repetition in it.
data JobState = UnsanitizedData Handle
| SanitizedData Handle
| VerifiedData Handle
| JobFail Handle
I don't want any of these JobStates to ever be used without Handle. But the repetition has me suspecting I'm not expressing this correctly. Is there a better way?
Upvotes: 2
Views: 113
Reputation: 231103
One way would be to factor this out into a state value, and a wrapper that includes the handle:
data JobState = UnsanitizedData | SanitizedData | VerifiedData | JobFail
deriving (Eq, Enum, Ord, Show, Read)
data Job = Job { jobState :: JobState, jobHandle :: Handle }
-- or: data Job = Job JobState Handle
Upvotes: 9