COMPLETE pragma doesn't prevent incomplete-patterns warning

Viewed 144

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 Answers

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.

Related