``NS''类型的案例匹配
从sop-core
键入型号,创建一个有趣的难题。在s :: ns f xs - > ns f(x':xs)
其中xs〜'[]
是指s
的参数是居住的。然而,哈斯克尔的案件匹配迫使我对此进行匹配。这个问题有解决方案吗?
type T = NS I '[Int, String]
matchT :: T -> String
matchT = \case
Z (I n) -> show n
S (Z (I s)) -> s
S (S _) -> error "FIXME" -- not reachable
如果您删除了最后一个情况(实际上不必必要),Haskell抱怨“模式匹配(ES)是无节制的”。
The NS
type from sop-core
creates an interesting conundrum. In S :: NS f xs -> NS f (x ': xs)
where xs ~ '[]
means that the argument to the S
is inhabited. Yet Haskell's case matching forces me to match on it. Is there a resolution to this problem?
type T = NS I '[Int, String]
matchT :: T -> String
matchT = \case
Z (I n) -> show n
S (Z (I s)) -> s
S (S _) -> error "FIXME" -- not reachable
If you remove that last case (which really shouldn't be necessary), Haskell complains "Pattern match(es) are non-exhaustive".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
emptroy> emptroy> emptycoper !
Use
EmptyCase
!Real-world example