Last active
March 8, 2020 16:02
-
-
Save kuribas/35c318b4f4b835d289acab3b51796a77 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class GToHttpApiData a where | |
gToQueryParam :: (String -> String) -> a f -> Text | |
instance GToHttpApiData b => GToHttpApiData (D1 m b) where | |
gToQueryParam pref (M1 x) = gToQueryParam pref x | |
instance (GToHttpApiData (a f), GToHttpApiData (b f)) | |
=> GToHttpApiData (a f :+: b f) where | |
gToQueryParam pref (L1 a) = gToQueryParam pref a | |
gToQueryParam pref (R1 a) = gToQueryParam pref a | |
instance KnownSymbol consName => | |
(GToHttpApiData (C1 ('MetaCons consName p c) U1)) where | |
gToQueryParam pref _ = Text.pack $ pref $ symbolVal (Proxy :: Proxy consName) | |
genericToHttpApiData :: (Generic a, GToHttpApiData (Rep a)) | |
=> (String -> String) -> a -> Text | |
genericToHttpApiData pref = gToQueryParam pref . from | |
data Test = Test1 | Test2 | |
genericToHttpApiData id Test1 | |
{- -- <interactive>:107:1-28: error: | |
• No instance for (GToHttpApiData | |
(C1 ('MetaCons "Test" 'PrefixI 'False) U1 | |
:+: C1 ('MetaCons "Test2" 'PrefixI 'False) U1)) | |
arising from a use of ‘genericToHttpApiData’ | |
• In the expression: genericToHttpApiData id Test | |
In an equation for ‘it’: it = genericToHttpApiData id Test-} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment