Skip to content

fix type instance conflict#3

Open
GuillaumedeVolpiano wants to merge 1 commit into
Shou:masterfrom
GuillaumedeVolpiano:master
Open

fix type instance conflict#3
GuillaumedeVolpiano wants to merge 1 commit into
Shou:masterfrom
GuillaumedeVolpiano:master

Conversation

@GuillaumedeVolpiano
Copy link
Copy Markdown

Fixes #1
Not sure it's the best way to do it, but for now, it's the only one I've found.

@habibalamin
Copy link
Copy Markdown

habibalamin commented May 30, 2026

Take this with a grain of salt, because I only have a thin grasp of type-level programming, but I think this makes more sense:

type family (<+>) (a :: k1) (b :: k2) :: Constraint
type instance (<+>) _ [] = (() :: Constraint)
type instance (<+>) [] _ = (() :: Constraint)
-type instance (<+>) (c ': cs) (a :: Type) = (c a, a <+> cs)
-type instance (<+>) c (a ': as) = (c a, c <+> as)
+type instance (<+>) (c ': cs) (a ': as) = (c a, cs <+> a, c <+> as)
infixl 9 <+>

If either are empty, it's already bailed, so we know both have at least one element, so we apply the first element of each list to each other, then each element of the rest of the first list to the first element of the second list and each element of the rest of the second list to the first element of the first list.

I dunno why GHC is saying [] <+> _ conflicts with c <+> (a ': as), but ironically, I think the added pattern match for (c ': cs) <+> (a ': as) is covered by the existing (c ': cs) <+> a, which GHC doesn't fail the build for. So I remove that line as well (it builds both with and without that line removed, but I dunno if the second match will be hit if we don't remove the first line).

@Shou are we off track here?

Edit: I guess each element of both lists has to also be applied to each other, so:

-type instance (<+>) (c ': cs) (a ': as) = (c a, cs <+> a, c <+> as)
+type instance (<+>) (c ': cs) (a ': as) = (c a, cs <+> a, c <+> as, cs <+> as)

@habibalamin
Copy link
Copy Markdown

Hey, @GuillaumedeVolpiano, since you already have the repo forked, if you think my solution makes more sense, would you go ahead and apply it on your PR?; I can't be bothered to make another PR.

@habibalamin
Copy link
Copy Markdown

How would you even write type-level tests for type-level functions? I think this library needs a test suite.

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 this pull request may close these issues.

type-operators-0.2.0.0 does not build with GHC 9.4

2 participants