COMPLETE pragma doesn't prevent incomplete-patterns warning

点点圈 提交于 2021-01-27 06:09:31

问题


I made two pattern views for a list-like class.

infixr 5 :<
pattern (:<) :: Stream s => Token s -> s -> s
pattern b :< bs <- (uncons -> Just (b, bs))
  where b :< bs = cons b bs

pattern Nil :: Stream s => s
pattern Nil <- (uncons -> Nothing)
  where Nil = empty

uncons signature: uncons :: (Stream s) => s -> Maybe (Token s, s).

Suppose I also have function that uses these patterns like that:

foo (b:<bs) = …
foo Nil = …

It's obvious in this case that pattern matches are exhaustive, and I would like to specify that.

So I tried using a COMPLETE pragma like that: {-# COMPLETE Nil, (:<) :: Stream #-}.

That didn't work, warning didn't go anywhere. Why didn't it? Is it possible to do what I want?


回答1:


COMPLETE pragmas can only be attached to types, not type classes. There is currently no way to specify a complete set of patterns that works for all types of a given class.



来源:https://stackoverflow.com/questions/58401723/complete-pragma-doesnt-prevent-incomplete-patterns-warning

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!