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

Using intermediate type variables prevents deducing (1 <= 2^n) #65

Open
lmbollen opened this issue Aug 18, 2022 · 2 comments · Fixed by #67
Open

Using intermediate type variables prevents deducing (1 <= 2^n) #65

lmbollen opened this issue Aug 18, 2022 · 2 comments · Fixed by #67

Comments

@lmbollen
Copy link
Member

lmbollen commented Aug 18, 2022

Using an intermediate type variable in your function and binding it to 2^n prevents the deduction that it is greater or equal to 1.

This reproducer:

{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeApplications #-}

module Example.Project where

import Clash.Prelude

works :: forall n . SNat n -> SNat (CLog 2 (2^n))
works SNat = SNat @(CLog 2 (2^n))

fails :: forall a b  . (b ~ (2^a)) => SNat a -> SNat (CLog 2 b)
fails SNat = SNat @(CLog 2 b)

produces the following error:

[1 of 1] Compiling Example.Project  ( src/Example/Project.hs, interpreted )

src/Example/Project.hs:12:14: error:
    Could not deduce: (1 <=? b) ~ 'True arising from a use of SNat
    from the context: b ~ (2 ^ a)
      bound by the type signature for:
                 fails :: forall (a :: Nat) (b :: Nat).
                          (b ~ (2 ^ a)) =>
                          SNat a -> SNat (CLog 2 b)
      at src/Example/Project.hs:11:1-63
   |
12 | fails SNat = SNat @(CLog 2 b)
   |              ^^^^^^^^^^^^^^^^
Failed, no modules loaded.
@rowanG077
Copy link
Member

@lmbollen I will take a look at this tonight. Probably somewhere a substitution is missing.

@martijnbastiaan
Copy link
Member

Partially fixes, mr. GitHub :-)

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

Successfully merging a pull request may close this issue.

3 participants