Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Totality checker too strict ? #1928

Closed
nicolabotta opened this issue Feb 17, 2015 · 3 comments
Closed

Totality checker too strict ? #1928

nicolabotta opened this issue Feb 17, 2015 · 3 comments

Comments

@nicolabotta
Copy link

The following code

> import Data.Vect
> import Data.Vect.Quantifiers
> import Data.Fin

> %default total

> instance Uninhabited (Elem {a} x Nil) where
>   uninhabited Here impossible                                                                                          
>   uninhabited (There p) impossible      

> lookup : {A : Type} -> 
>          (a : A) -> (as : Vect n A) -> Elem a as -> Fin n
> lookup a  Nil        prf        = absurd prf
> lookup a (a :: as)   Here       = FZ
> lookup a (a' :: as) (There prf) = FS (lookup a as prf)

> indexLookupLemma : {A : Type} -> 
>                    (x : A) -> (xs : Vect n A) -> (prf : Elem x xs) -> 
>                    index (lookup x xs prf) xs = x
> indexLookupLemma x  Nil        prf        = absurd prf
> indexLookupLemma x (x :: xs)   Here       = Refl
> indexLookupLemma x (x' :: xs) (There prf) = 
>   let ih = indexLookupLemma x xs prf in rewrite ih in Refl

> lookupIndexLemma : {A : Type} -> 
>                    (k : Fin n) -> (xs : Vect n A) -> (prf : Elem (index k xs) xs) ->
>                    lookup (index k xs) xs prf = k
> lookupIndexLemma  k      Nil       prf        = absurd prf
> lookupIndexLemma  FZ    (x :: xs)  Here       = Refl
> lookupIndexLemma (FS k) (x :: xs) (There prf) = 
>   let ih = lookupIndexLemma k xs prf in rewrite ih in Refl

type checks but lookupIndexLemma appears not to be total:

*VectProperties> :total lookupIndexLemma
VectProperties.lookupIndexLemma is not total as there are missing cases

I understand that "is not total as there are missing cases" judgements have to be read as "might not be total". Thus, this is not an issue in the same sense as #1917 is. But I tought of reporting it because, in the specific case, I would have expected that, if indexLookupLemma is checked to be total, so would lookupIndexLemma. Am I missing something obvious here ? Thanks, Nicola

@falsifian
Copy link

What about the case lookupIndexLemma FZ (x :: xs) (There prf) ?

@nicolabotta
Copy link
Author

Good point but even adding a

> lookupIndexLemma  FZ    (x :: xs) (There prf) = ?lookupIndexLemma_meta1

case does not make lookupIndexLemma pass the totality check.

@edwinb
Copy link
Contributor

edwinb commented Sep 6, 2015

According to :missing, you need to add the following:

> lookupIndexLemma  FZ    (x :: xs) (There prf) = ?foo
> lookupIndexLemma (FS _) (_ :: _)  Here        = ?bar

So I think this is behaving correctly.

@edwinb edwinb closed this as completed Sep 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants