Skip to content

Instantly share code, notes, and snippets.

@Lysxia Lysxia/GHas.hs
Last active Jul 21, 2019

What would you like to do?
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
You can’t perform that action at this time.