-
Notifications
You must be signed in to change notification settings - Fork 18
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
enforcing tag uniqueness #33
Comments
Certainly would be a desirable addition. I think it can be done with |
Ah, so the Generics code has a type-level list of all the tags used? I
have not dug into your implementation details.
…--
see shy jo
|
It does, sort of. The structure of the message can be traversed and field tags extracted at compile time, here's the basic idea: {-# language DataKinds #-}
{-# language KindSignatures #-}
{-# language PolyKinds #-}
{-# language TypeFamilies #-}
{-# language TypeOperators #-}
{-# language UndecidableInstances #-}
import GHC.Generics
import GHC.TypeLits
data Field (n :: Nat) a
type family Concat (x :: [k]) (y :: [k]) :: [k] where
Concat (x ': xs) ys = x ': Concat xs ys
Concat '[] ys = ys
type family FieldTags (f :: * -> *) :: [Nat] where
FieldTags (M1 i c a) = FieldTags a
FieldTags (a :*: b) = Concat (FieldTags a) (FieldTags b)
FieldTags (a :+: b) = Concat (FieldTags a) (FieldTags b)
FieldTags (K1 i (Field n a)) = '[n] Applying
|
"Each tag must be unique within a given message, though this is not currently checked or enforced."
I really like this library, but keeping the tags unique has felt like walking on eggshells when using it. Perhaps there could be some way to enforce tag uniqueness?
The text was updated successfully, but these errors were encountered: