-
-
Save codedmart/c7e2fa0b91fc58cae12200d431dc0b07 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
newtype FooBar (names :: [(Symbol, id)]) a = | |
FooBar { unFooBar :: a } | |
instance | |
( Show a | |
) => HasId (FooBar '[] a) | |
where | |
type UniqId (FooBar '[] a) = () | |
mkId (FooBar _) = () | |
instance | |
( Show a | |
, HasField' name a id | |
, Show id | |
, KnownSymbol name | |
) => HasId (FooBar '[ '(name, id)] a) | |
where | |
type UniqId (FooBar '[ '(name, id)] a) = id | |
mkId (FooBar a) = getField @name a | |
instance | |
( Show a | |
, HasField' name1 a id1 | |
, Show id1 | |
, KnownSymbol name1 | |
, HasField' name2 a id2 | |
, Show id2 | |
, KnownSymbol name2 | |
) => HasId (FooBar '[ '(name1, id1), '(name2, id2)] a) | |
where | |
type UniqId (FooBar '[ '(name1, id1), '(name2, id2)] a) = (id1, id2) | |
mkId (FooBar a) = (getField @name1 a, getField @name2 a) | |
instance | |
( Show a | |
, HasField' name1 a id1 | |
, Show id1 | |
, KnownSymbol name1 | |
, HasField' name2 a id2 | |
, Show id2 | |
, KnownSymbol name2 | |
, HasField' name3 a id3 | |
, Show id3 | |
, KnownSymbol name3 | |
) => HasId (FooBar '[ '(name1, id1), '(name2, id2), '(name3, id3)] a) | |
where | |
type UniqId (FooBar '[ '(name1, id1), '(name2, id2), '(name3, id3)] a) = (id1, id2, id3) | |
mkId (FooBar a) = (getField @name1 a, getField @name2 a, getField @name3 a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment