Skip to content

Investigate "‘p0’ is untouchable" that derails type reconstruction #87

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

Closed
Mikolaj opened this issue Feb 25, 2023 · 1 comment
Closed

Comments

@Mikolaj
Copy link
Owner

Mikolaj commented Feb 25, 2023

Here

nestedGather :: forall r. ADReady r
             => TensorOf 2 r -> TensorOf 2 r
nestedGather t =
  tgather
          (2 :$ 2 :$ ZS)
          (tgather
                   (2 :$ 3 :$ 4 :$ 4 :$ ZS) t
                   (\(k1 :. k2 :. k3 :. ZI) -> k1 + k2 + k3 :. ZI))
          (\(i1 :. i2 :. ZI) -> i1 :. i2 :. i1 + i2 :. i2 :. ZI)

we have all the information needed to reconstruct all types, but it's not possible and the root cause is probably

test/simplified/TestGatherSimplified.hs:35:61: error:
    • Couldn't match type ‘p0’ with ‘1’ arising from a use of ‘:.’
    • ‘p0’ is untouchable
        inside the constraints: n4 ~ 0
        bound by a pattern with pattern synonym:
                   ZI :: forall (n :: GHC.Num.Natural.Natural) i.
                         () =>
                         (n ~ 0) => Index n i,
                 in a lambda abstraction
        at test/simplified/TestGatherSimplified.hs:35:41-42
    • In the expression: k1 + k2 + k3 :. ZI

Let's investigate where it comes from. E.g., whether the problem comes from the KnownNat constraint in our :. pattern synonym. If the code type-checks fine when using ::: instead (and a newtype wrapper) then this may be the case.

This is important in order to lower the number of type applications the end user of our library needs to be adding. Here is a version that type-checks thanks to type applications. It's not too bad, but the code is now too complex and the user writes all list in their fully sized form, instead of using the simpler IsList syntax, which sadly forgets all type-level Nat information.

nestedGather :: forall r. ADReady r
             => TensorOf 2 r -> TensorOf 2 r
nestedGather t =
  tgather @r @2
          (2 :$ 2 :$ ZS)
          (tgather @r @3
                   (2 :$ 3 :$ 4 :$ 4 :$ ZS) t
                   (\(k1 :. k2 :. k3 :. ZI) -> k1 + k2 + k3 :. ZI))
          (\(i1 :. i2 :. ZI) -> i1 :. i2 :. i1 + i2 :. i2 :. ZI)
@Mikolaj Mikolaj added the help wanted Extra attention is needed label Feb 25, 2023
@Mikolaj Mikolaj removed the help wanted Extra attention is needed label Mar 17, 2025
@Mikolaj
Copy link
Owner Author

Mikolaj commented Mar 17, 2025

This problem may still persist, but the types have changed so much that reproducing it require work, so let's instead close the issue and open a new one as needed.

@Mikolaj Mikolaj closed this as completed Mar 17, 2025
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

1 participant