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

Separate overriding (Override) and generic (Generically) behaviour #15

Open
Icelandjack opened this issue Mar 17, 2022 · 0 comments
Open

Comments

@Icelandjack
Copy link

Icelandjack commented Mar 17, 2022

Soon Generically and Generically1 will be added to base 4.17, I notice that you implement generic instances for Override that duplicates the intended use of Generically.

It is possible to pass Override as an argument to Generically that makes use of the modified Generic instance of Override:

-- >> mempty @Ok
-- Ok 0 1
-- >> Ok 10 10 <> Ok 10 10
-- Ok 20 100
data Ok = Ok Int Int
  deriving (Semigroup, Monoid)
  via Generically
    (Override Ok
        '[ At "Ok" 0 (Sum Int)
         , At "Ok" 1 (Product Int)
         ]
    )

Using this pattern you separate the generic behaviour from the overriding behaviour, which will be added separately by many libraries. You could possibly define a type level constant

type Overriding :: Type -> [Type] -> Type
type Overriding a spec = Generically (Override a spec)
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