完成编译指示不能防止出现不完整的模式警告 [英] COMPLETE pragma doesn't prevent incomplete-patterns warning

查看:57
本文介绍了完成编译指示不能防止出现不完整的模式警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为一个类似列表的类制作了两种模式视图.

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 签名: uncons :: ::(Stream s)=>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.

所以我尝试使用完整的杂注表示: {-#COMPLETE Nil,(:<)::流#-} .

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?

推荐答案

COMPLETE 编译指示只能附加到类型,而不能附加在类型类上.当前尚无法指定适用于给定类的所有类型的完整模式集.

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.

这篇关于完成编译指示不能防止出现不完整的模式警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆