-
Notifications
You must be signed in to change notification settings - Fork 10
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 equality constraints aren't used by solver #13
Comments
Actually
|
Thanks for the report, and simple test case. I'll try to look into this over the weekend. |
The following example, even simpler, cuts right to the crux of the issue:
|
I strongly believe that this is because |
Of course, it's tricky if we also want to support chains of equalities like in
so it seems that from the |
This means that: > (KnownNat n, n ~ (m+1)) ~ KnownNat m However, this does need the `ghc-typlits-natnormalise` plugin, as this pluging creates the following contraints: > (KnownNat n, n ~ (m+1), KnownNat m ~ KnownNat (n-1), 1 <= n) And only `ghc-typelits-natnormalise` knows that `n ~ m + 1` implies `1 <= n`. This partially solves #13, as it still doesn't find the fixpoint of all possible substitutions. This will be in a follow-up patch.
{-# LANGUAGE DataKinds, TypeOperators, TypeFamilies #-}
{-# OPTIONS_GHC -fplugin GHC.TypeLits.KnownNat.Solver #-}
{-# OPTIONS_GHC -fplugin GHC.TypeLits.Normalise #-}
{-# OPTIONS_GHC -dcore-lint #-}
module EqTest where
import GHC.TypeLits
foo :: (KnownNat n, n ~ (m+1)) => proxy m -> Integer
foo m = natVal m works with the above mentioned patch |
Just ran into a similar issue: {-# LANGUAGE AllowAmbiguousTypes, DataKinds, TypeFamilies, TypeOperators #-}
{-# OPTIONS_GHC -fplugin GHC.TypeLits.KnownNat.Solver #-}
{-# OPTIONS_GHC -fplugin GHC.TypeLits.Normalise #-}
{-# OPTIONS_GHC -dcore-lint #-}
module EqTest where
import Numeric.Natural
import GHC.TypeNats
foo :: (KnownNat n, KnownNat m, k ~ (n + m)) => proxy k -> Natural
foo = natVal This produces the following error:
I'm on GHC 8.6.5, and using |
The following code fails to typecheck:
The error message is as follows (on GHC 8.0.2):
To highlight, the relevant parts of the context are:
But isn't this exactly the situation that the plugin was designed to handle?
The text was updated successfully, but these errors were encountered: