Rename HList append from .: to .:.
Avoids conflicting with Data.Aeson.((.:))
This commit is contained in:
parent
33cc9958ed
commit
eafc5d33bb
3 changed files with 13 additions and 13 deletions
|
@ -38,7 +38,7 @@ module Servant.Server
|
||||||
-- * Config
|
-- * Config
|
||||||
, ConfigEntry(..)
|
, ConfigEntry(..)
|
||||||
, Config(..)
|
, Config(..)
|
||||||
, (.:)
|
, (.:.)
|
||||||
|
|
||||||
-- * Default error type
|
-- * Default error type
|
||||||
, ServantErr(..)
|
, ServantErr(..)
|
||||||
|
|
|
@ -39,16 +39,16 @@ instance Show (Config '[]) where
|
||||||
instance (Show a, Show (Config as)) => Show (Config (ConfigEntry tag a ': as)) where
|
instance (Show a, Show (Config as)) => Show (Config (ConfigEntry tag a ': as)) where
|
||||||
showsPrec outerPrecedence (ConsConfig (ConfigEntry a) as) =
|
showsPrec outerPrecedence (ConsConfig (ConfigEntry a) as) =
|
||||||
showParen (outerPrecedence > 5) $
|
showParen (outerPrecedence > 5) $
|
||||||
shows a . showString " .: " . shows as
|
shows a . showString " .:. " . shows as
|
||||||
|
|
||||||
instance Eq (Config '[]) where
|
instance Eq (Config '[]) where
|
||||||
_ == _ = True
|
_ == _ = True
|
||||||
instance (Eq a, Eq (Config as)) => Eq (Config (a ': as)) where
|
instance (Eq a, Eq (Config as)) => Eq (Config (a ': as)) where
|
||||||
ConsConfig x1 y1 == ConsConfig x2 y2 = x1 == x2 && y1 == y2
|
ConsConfig x1 y1 == ConsConfig x2 y2 = x1 == x2 && y1 == y2
|
||||||
|
|
||||||
(.:) :: x -> Config xs -> Config (ConfigEntry tag x ': xs)
|
(.:.) :: x -> Config xs -> Config (ConfigEntry tag x ': xs)
|
||||||
e .: cfg = ConsConfig (ConfigEntry e) cfg
|
e .:. cfg = ConsConfig (ConfigEntry e) cfg
|
||||||
infixr 5 .:
|
infixr 5 .:.
|
||||||
|
|
||||||
class HasConfigEntry (cfg :: [*]) (a :: k) (val :: *) | cfg a -> val where
|
class HasConfigEntry (cfg :: [*]) (a :: k) (val :: *) | cfg a -> val where
|
||||||
getConfigEntry :: proxy a -> Config cfg -> val
|
getConfigEntry :: proxy a -> Config cfg -> val
|
||||||
|
|
|
@ -16,8 +16,8 @@ spec = do
|
||||||
getConfigEntrySpec :: Spec
|
getConfigEntrySpec :: Spec
|
||||||
getConfigEntrySpec = describe "getConfigEntry" $ do
|
getConfigEntrySpec = describe "getConfigEntry" $ do
|
||||||
|
|
||||||
let cfg1 = 0 .: EmptyConfig :: Config '[ConfigEntry "a" Int]
|
let cfg1 = 0 .:. EmptyConfig :: Config '[ConfigEntry "a" Int]
|
||||||
cfg2 = 1 .: cfg1 :: Config '[ConfigEntry "a" Int, ConfigEntry "a" Int]
|
cfg2 = 1 .:. cfg1 :: Config '[ConfigEntry "a" Int, ConfigEntry "a" Int]
|
||||||
|
|
||||||
it "gets the config if a matching one exists" $ do
|
it "gets the config if a matching one exists" $ do
|
||||||
|
|
||||||
|
@ -28,20 +28,20 @@ getConfigEntrySpec = describe "getConfigEntry" $ do
|
||||||
getConfigEntry (Proxy :: Proxy "a") cfg2 `shouldBe` 1
|
getConfigEntry (Proxy :: Proxy "a") cfg2 `shouldBe` 1
|
||||||
|
|
||||||
it "allows to distinguish between different config entries with the same type by tag" $ do
|
it "allows to distinguish between different config entries with the same type by tag" $ do
|
||||||
let cfg = 'a' .: 'b' .: EmptyConfig :: Config '[ConfigEntry 1 Char, ConfigEntry 2 Char]
|
let cfg = 'a' .:. 'b' .:. EmptyConfig :: Config '[ConfigEntry 1 Char, ConfigEntry 2 Char]
|
||||||
getConfigEntry (Proxy :: Proxy 1) cfg `shouldBe` 'a'
|
getConfigEntry (Proxy :: Proxy 1) cfg `shouldBe` 'a'
|
||||||
|
|
||||||
context "Show instance" $ do
|
context "Show instance" $ do
|
||||||
let cfg = 1 .: 2 .: EmptyConfig
|
let cfg = 1 .:. 2 .:. EmptyConfig
|
||||||
it "has a Show instance" $ do
|
it "has a Show instance" $ do
|
||||||
show cfg `shouldBe` "1 .: 2 .: EmptyConfig"
|
show cfg `shouldBe` "1 .:. 2 .:. EmptyConfig"
|
||||||
|
|
||||||
it "bracketing works" $ do
|
it "bracketing works" $ do
|
||||||
show (Just cfg) `shouldBe` "Just (1 .: 2 .: EmptyConfig)"
|
show (Just cfg) `shouldBe` "Just (1 .:. 2 .:. EmptyConfig)"
|
||||||
|
|
||||||
it "bracketing works with operators" $ do
|
it "bracketing works with operators" $ do
|
||||||
let cfg = (1 .: 'a' .: EmptyConfig) :<|> ('b' .: True .: EmptyConfig)
|
let cfg = (1 .:. 'a' .:. EmptyConfig) :<|> ('b' .:. True .:. EmptyConfig)
|
||||||
show cfg `shouldBe` "(1 .: 'a' .: EmptyConfig) :<|> ('b' .: True .: EmptyConfig)"
|
show cfg `shouldBe` "(1 .:. 'a' .:. EmptyConfig) :<|> ('b' .:. True .:. EmptyConfig)"
|
||||||
|
|
||||||
it "does not typecheck if key does not exist" $ do
|
it "does not typecheck if key does not exist" $ do
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue