开发者

Is there a better way to express this type?

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 a开发者_如何学运维ny 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?


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜