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

Const and Identity instances for HasAny #148

Open
srid opened this issue Jun 30, 2022 · 1 comment
Open

Const and Identity instances for HasAny #148

srid opened this issue Jun 30, 2022 · 1 comment

Comments

@srid
Copy link

srid commented Jun 30, 2022

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 srid/ema#108

@srid
Copy link
Author

srid commented Jun 30, 2022

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

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

No branches or pull requests

1 participant