Last active
September 20, 2022 21:53
-
-
Save Lysxia/b1708d00f2ea766a270ad28c182bfd2f to your computer and use it in GitHub Desktop.
Quantified constraint trick
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE | |
ConstraintKinds, | |
FlexibleContexts, | |
FlexibleInstances, | |
MultiParamTypeClasses, | |
QuantifiedConstraints, | |
RankNTypes, | |
ScopedTypeVariables, | |
TypeApplications, | |
UndecidableInstances #-} | |
{-# OPTIONS_GHC -Wno-simplifiable-class-constraints #-} | |
module DG where | |
import GHC.Generics | |
class RepBimap a a' b b' rep rep' where | |
repBimap :: (a -> a') -> (b -> b') -> rep -> rep' | |
gbimap :: forall f a a' b b'. GBimap f => (a -> a') -> (b -> b') -> f a b -> f a' b' | |
gbimap f g = | |
with @(RepBimapRep a a' b b' f) -- Not needed since GHC 9.2 | |
(to @_ @() . repBimap f g . from @_ @()) | |
with :: forall c r. (c => r) -> (c => r) | |
with x = x | |
class (forall a b. Generic (f a b), forall a a' b b'. RepBimapRep a a' b b' f) => GBimap f | |
instance (forall a b. Generic (f a b), forall a a' b b'. RepBimapRep a a' b b' f) => GBimap f | |
class RepBimap a a' b b' (Rep (f a b) ()) (Rep (f a' b') ()) => RepBimapRep a a' b b' f | |
instance RepBimap a a' b b' (Rep (f a b) ()) (Rep (f a' b') ()) => RepBimapRep a a' b b' f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment