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

derivedArgDict doesn't work when an index is another parameter #57

Open
bglgwyng opened this issue Dec 2, 2024 · 0 comments
Open

derivedArgDict doesn't work when an index is another parameter #57

bglgwyng opened this issue Dec 2, 2024 · 0 comments

Comments

@bglgwyng
Copy link

bglgwyng commented Dec 2, 2024

There are issues with derivedArgDict here and I think I found another one.
I want to define Foo with two type parameters a and b. And the usage of a(b is ok) in the place of b causes the issue.

data Foo a b where
  Foo :: Foo a Int -- ok
  Bar :: Foo a (a) -- not ok

deriveGEq ''Foo
deriveGCompare ''Foo
deriveGShow ''Foo
deriveArgDict ''Foo -- fails

So I expanded TH.

data Foo a b where
  Foo :: Foo a Int -- ok
  Bar :: Foo a [a] -- not ok

deriveGEq ''Foo
deriveGCompare ''Foo
deriveGShow ''Foo
instance (c_a3QI3 Int, c_a3QI3 [a_a3QzU]) =>
         Has c_a3QI3 (Foo a_a3QI2) where
  argDict
    = \case
        Foo {} -> Dict
        Bar {} -> Dict

I think the a_a3QzU is not correct. So I corrected it as follows.

data Foo a b where
  Foo :: Foo a Int -- ok
  Bar :: Foo a [a] -- not ok

deriveGEq ''Foo
deriveGCompare ''Foo
deriveGShow ''Foo
instance (c Int, c [a]) =>
         Has c (Foo a) where
  argDict
    = \case
        Foo {} -> Dict
        Bar {} -> Dict

Then it worked!

First, is the hand-written instance correct?
Also, can the instance be derived?

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