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

Why should 0 <= VV < acc #88

Open
kishlaya opened this issue Nov 12, 2019 · 7 comments
Open

Why should 0 <= VV < acc #88

kishlaya opened this issue Nov 12, 2019 · 7 comments

Comments

@kishlaya
Copy link

vectorSum :: Vector Int -> Int

The function vectorSum gives me a strange error:

 7 |    | i < sz = go (acc + (vec ! i)) (i + 1)
                       ^^^^^^^^^^^^^^^^^
  
   Inferred type
     VV : {v : GHC.Types.Int | v == acc + ?b}
  
   not a subtype of Required type
     VV : {VV : GHC.Types.Int | VV < acc
                                && VV >= 0}
  
   In Context
     ?b : GHC.Types.Int
      
     acc : GHC.Types.Int

As a re-check, the following code gives me the same error, when executed here

import Data.Vector
vectorSum         :: Vector Int -> Int
vectorSum vec     = go 0 0
  where
    go acc i
      | i < sz    = go (acc + (vec ! i)) (i + 1)
      | otherwise = acc
    sz            = Data.Vector.length vec
@ranjitjhala
Copy link
Member

ranjitjhala commented Nov 12, 2019 via email

@kishlaya
Copy link
Author

Umm, could you give me a quick insight into why does LH think that this program won't terminate?

@ranjitjhala
Copy link
Member

ranjitjhala commented Nov 12, 2019 via email

@hafizhmakmur
Copy link

@ranjitjhala I want to note something from this problem. From chapter 2 our old problem can be solved by adding {-@ LIQUID "--reflection" @-}. Now instead it will ruin the problem for this chapter and it should not be used.

I just want to note the result of my grueling attempt to debug my failure in this very example. Thank you very much for your attention.

@ranjitjhala
Copy link
Member

ranjitjhala commented Feb 23, 2020 via email

@hafizhmakmur
Copy link

Reflection should not be used in this chapter, at least in my case. vectorSum somehow will be deemed unsafe if it's added.

@ranjitjhala
Copy link
Member

ranjitjhala commented Feb 23, 2020 via email

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