有没有更好的方式来表达这种类型?
我制作了这种数据类型,其中有很多重复。
data JobState = UnsanitizedData Handle
| SanitizedData Handle
| VerifiedData Handle
| JobFail Handle
我不希望在没有 Handle 的情况下使用这些 JobStates 中的任何一个。但重复让我怀疑我没有正确表达这一点。有更好的办法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种方法是将其分解为状态值和包含句柄的包装器:
One way would be to factor this out into a state value, and a wrapper that includes the handle: