Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

COMPLETE pragma doesn't prevent incomplete-patterns warning

Tags:

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?

like image 814
grepcake Avatar asked Oct 15 '19 19:10

grepcake


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.

like image 199
Li-yao Xia Avatar answered Nov 14 '22 22:11

Li-yao Xia