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

Support ghc 9.6 #31

Closed
wants to merge 5 commits into from
Closed

Conversation

alexfmpe
Copy link
Contributor

On top of #30

@@ -54,7 +54,7 @@ pattern Some x = This x
#endif

-- Do not export this type family, it must remain empty. It's used as a way to trick GHC into not unifying certain type variables.
type family Skolem :: k -> k
data family Skolem :: k -> k
Copy link
Contributor Author

@alexfmpe alexfmpe Apr 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spent a couple hours adding traces and very confused on why a gazillion instances were being returned until I remembered about obsidiansystems/dependent-sum-template#7

Shouldn't the chunk of code that's equal between the two libs be re-used instead?

type family Skolem :: k -> k
skolemize :: Set Name -> Type -> Type
skolemize rigids t = case t of
ForallT bndrs cxt t' -> ForallT bndrs cxt (skolemize (Set.difference rigids (Set.fromList (map tvName bndrs))) t')
AppT t1 t2 -> AppT (skolemize rigids t1) (skolemize rigids t2)
SigT t1 k -> SigT (skolemize rigids t1) k
VarT v -> if Set.member v rigids
then AppT (ConT ''Skolem) (VarT v)
else t
InfixT t1 n t2 -> InfixT (skolemize rigids t1) n (skolemize rigids t2)
UInfixT t1 n t2 -> UInfixT (skolemize rigids t1) n (skolemize rigids t2)
ParensT t1 -> ParensT (skolemize rigids t1)
_ -> t
reifyInstancesWithRigids :: Set Name -> Name -> [Type] -> Q [InstanceDec]
reifyInstancesWithRigids rigids cls tys = reifyInstances cls (map (skolemize rigids) tys)
-- | Determine the type variables which occur freely in a type.
freeTypeVariables :: Type -> Set Name
freeTypeVariables t = case t of
ForallT bndrs _ t' -> Set.difference (freeTypeVariables t') (Set.fromList (map tvName bndrs))
AppT t1 t2 -> Set.union (freeTypeVariables t1) (freeTypeVariables t2)
SigT t1 _ -> freeTypeVariables t1
VarT n -> Set.singleton n
_ -> Set.empty

https://github.com/obsidiansystems/dependent-sum-template/blob/846df3885404b3c343453a2aa786eb6433a346d5/src/Data/GADT/TH/Internal.hs#L38-L63

@alexfmpe alexfmpe mentioned this pull request Apr 10, 2024
@alexfmpe alexfmpe changed the title Bump ghc 9.6 Support ghc 9.6 Apr 11, 2024
@ali-abrar ali-abrar closed this May 28, 2024
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.

3 participants