-
Notifications
You must be signed in to change notification settings - Fork 142
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
Type level nat parameter causes LH to check less #2457
Comments
Hey @kleinreact! I cannot really run this code, because LH gives me too many errors before the liquidhaskell/tests/pos/TypeLitNat.hs Line 4 in 8407040
Concretely, the below seems correct for me (i.e.,
|
Oh, I'm sry, I should have added more context on my setup. Here's the options and imports that work for me: {-@ LIQUID "" @-}
{-# LANGUAGE StandaloneKindSignatures #-}
{-# OPTIONS_GHC -fplugin=LiquidHaskell #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-@ LIQUID "--prune-unsorted" @-}
module Liquid.Test where
import Prelude
import GHC.Base (Type)
import GHC.TypeNats (Nat, Natural)
{-@ embed Natural as Int @-}
...
Yes, but in your case the p3 :: P 10
p3 = 3 + 9 instead of p3 :: P 10
p3 = P (3 + 9) That's exactly where the behavior differs between the |
Thanks to @nikivazou we also got the reproducer working with 791567f. I updated the code above accordingly. After the update the code now produces multiple
caused by using the |
Hi, now refining the return type of a data constructors is disallowed so @nikivazou 's code should be rejected. @kleinreact is this what were you trying to achieve? {-# LANGUAGE DataKinds #-}
module Fin where
import GHC.Base
import GHC.Num.Natural
import GHC.TypeNats
{-@ embed GHC.Num.Natural.Natural as int @-}
type Fin :: Nat -> Type
data Fin n where
{-@ MkFin :: forall (n :: Nat) . { i:Nat | i < n } -> Fin n @-}
MkFin :: forall n . Int -> Fin n
{-@ unFin :: forall (n :: Nat) . Fin n -> { i:Nat | i < n } @-}
unFin :: forall n . Fin n -> Int
unFin (MkFin i) = i
p0 :: Fin 10
p0 = MkFin 3
p1 :: Fin 10
p1 = MkFin $ 3 + 3
{-@ fail p2 @-}
p2 :: Fin 10
p2 = MkFin $ 9 + 3 p2 fails to TC as expected |
@AlecsFerra yes that is basically what I want, but I need However, adding a
on 98c7729. |
You need to enable at least one of the flags that reflects selectors like |
I still get the same error, also after adding the |
Uhm super weird if instead of inline you use |
Using
after the introduction of type P :: Nat -> Type
data P n where
{-@ P :: forall (n :: Nat). BoundedInteger n -> P n @-}
P :: forall n. Integer -> P n |
Oh ok, now I understand the code is triggered by the usage of typeclass code, from what I know its not well tested/maintained #2434. I don't know the specifics of how it works but I guess is has something to do with the dictionary resolution that is forgetting to bring in scope type parameters used as value |
Lets say I wanna have a bounded number type with
Num
capabilities, then I can get that for some fixed lower bound 0 and upper bound 9 as follows:LH checks the bounds in this case as expected.
However, if I parameterize the bound using a type level natural instead, e.g.
then the last definition of
p3
LH type checks, although it shouldn't. Note that only change here is the additionally introduced type level nat parameter.I'd expect the parameterized version to behave the same as the non-parameterized one in this case.
Tested with GHC 9.10 and 8c550df.
2024-12-17: Update of the reproducer to work with 791567f.
The text was updated successfully, but these errors were encountered: