Skip to content

Instantly share code, notes, and snippets.

@Lysxia
Last active July 21, 2019 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lysxia/e02e587ca1a08e5373301dc7d7f6a8be to your computer and use it in GitHub Desktop.
Save Lysxia/e02e587ca1a08e5373301dc7d7f6a8be to your computer and use it in GitHub Desktop.
data Path = L Path | R Path | Here
data MPath = NotFound | Conflict | Found Path
type family Search a (f :: k -> Type) :: MPath where
-- ...
Search a (f :*: g) = OrPath (Search a f) (Search a g)
Search a (K1 i c) = Check a c
type family Check a c where
Check a a = 'Found 'Here
Check a b = 'NotFound
type family OrPath (p1 :: MPath) (p2 :: MPath) :: MPath where
OrPath ('Found p) 'NotFound = 'Found ('L p)
OrPath 'NotFound ('Found p) = 'Found ('R p)
OrPath 'NotFound 'NotFound = 'NotFound
OrPath _ _ = 'Conflict
class GHas (path :: Path) (part :: Type) (f :: k -> Type) where
ghas_ :: ...
instance GHas p part f => GHas ('L p) part (f :*: g) where ...
instance GHas p part g => GHas ('R p) part (f :*: g) where ...
ghas :: (Generic a, Search part (Rep a) ~ 'Found p, GHas p part f) => ...
ghas = ghas_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment