generic-lens
generic-lens copied to clipboard
Const and Identity instances for `HasAny`
https://hackage.haskell.org/package/generic-optics-2.2.1.0/docs/Data-Generics-Product-Any.html
Basically,
instance {-# OVERLAPPING #-} HasAny () s s () () where
the = united
instance HasAny s s s s s where
the = castOptic equality
Usage:
>>> human ^. the @()
() -- Always type checks and returns ()
>>> human ^. the @Human == human
True -- ^ equivalent to `id`
Do these make sense? With this in place, I am able to simplify the API of https://github.com/EmaApps/ema/pull/108
If breaking the self-referential record fields case is a concern (which is valid) we can derive on types from the k -> Type kind instead, viz.:
instance HasAny (Const () :: k -> Type) s s () () where
the = united
instance HasAny (Identity :: Type -> Type) s s s s where
the = castOptic equality