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

Chapter 4 Polymorphism #130

Open
matheussbernardo opened this issue Sep 4, 2024 · 4 comments
Open

Chapter 4 Polymorphism #130

matheussbernardo opened this issue Sep 4, 2024 · 4 comments

Comments

@matheussbernardo
Copy link

Hello! I am trying to go through the tutorial. But I think type inference is not working at.

`{-@ LIQUID "--no-termination" @-}

module DemoLib where

import Data.Vector

loop :: Int -> Int -> a -> (Int -> a -> a) -> a
loop lo hi base f = go base lo
where
go acc i
| i < hi = go (f i acc) (i + 1)
| otherwise = acc

vectorSum' :: Vector Int -> Int
vectorSum' vec = loop 0 n 0 body
where
body i acc = acc + (vec ! i)
n = Data.Vector.length vec
`

It is failing with

`
**** LIQUID: UNSAFE ************************************************************

app/DemoLib.hs:20:31: error:
Liquid Type Mismatch
.
The inferred type
VV : {v : GHC.Types.Int | v == i##a17O}
.
is not a subtype of the required type
VV : {VV##694 : GHC.Types.Int | VV##694 < vlen vec##a17L}
.
in the context
i##a17O : GHC.Types.Int

  vec##a17L : {vec##a17L : (Data.Vector.Vector GHC.Types.Int) | 0 <= vlen vec##a17L}
Constraint id 8

|
20 | body i acc = acc + (vec ! i)`

@VhRvo
Copy link

VhRvo commented Sep 5, 2024

Did you put specifications in your code?

~~~~~{.spec}
loop :: lo:Nat -> hi:{Nat|lo <= hi} -> a -> (Btwn lo hi -> a -> a) -> a
~~~~~

@matheussbernardo
Copy link
Author

matheussbernardo commented Sep 5, 2024 via email

@VhRvo
Copy link

VhRvo commented Sep 6, 2024

How it going now?

@matheussbernardo
Copy link
Author

matheussbernardo commented Sep 6, 2024 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

2 participants