Rename HList append from .: to .:.

Avoids conflicting with Data.Aeson.((.:))
This commit is contained in:
aaron levin 2016-01-10 11:43:07 +01:00
parent 33cc9958ed
commit eafc5d33bb
3 changed files with 13 additions and 13 deletions

View file

@ -38,7 +38,7 @@ module Servant.Server
-- * Config
, ConfigEntry(..)
, Config(..)
, (.:)
, (.:.)
-- * Default error type
, ServantErr(..)

View file

@ -39,16 +39,16 @@ instance Show (Config '[]) where
instance (Show a, Show (Config as)) => Show (Config (ConfigEntry tag a ': as)) where
showsPrec outerPrecedence (ConsConfig (ConfigEntry a) as) =
showParen (outerPrecedence > 5) $
shows a . showString " .: " . shows as
shows a . showString " .:. " . shows as
instance Eq (Config '[]) where
_ == _ = True
instance (Eq a, Eq (Config as)) => Eq (Config (a ': as)) where
ConsConfig x1 y1 == ConsConfig x2 y2 = x1 == x2 && y1 == y2
(.:) :: x -> Config xs -> Config (ConfigEntry tag x ': xs)
e .: cfg = ConsConfig (ConfigEntry e) cfg
infixr 5 .:
(.:.) :: x -> Config xs -> Config (ConfigEntry tag x ': xs)
e .:. cfg = ConsConfig (ConfigEntry e) cfg
infixr 5 .:.
class HasConfigEntry (cfg :: [*]) (a :: k) (val :: *) | cfg a -> val where
getConfigEntry :: proxy a -> Config cfg -> val

View file

@ -16,8 +16,8 @@ spec = do
getConfigEntrySpec :: Spec
getConfigEntrySpec = describe "getConfigEntry" $ do
let cfg1 = 0 .: EmptyConfig :: Config '[ConfigEntry "a" Int]
cfg2 = 1 .: cfg1 :: Config '[ConfigEntry "a" Int, ConfigEntry "a" Int]
let cfg1 = 0 .:. EmptyConfig :: Config '[ConfigEntry "a" Int]
cfg2 = 1 .:. cfg1 :: Config '[ConfigEntry "a" Int, ConfigEntry "a" Int]
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
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'
context "Show instance" $ do
let cfg = 1 .: 2 .: EmptyConfig
let cfg = 1 .:. 2 .:. EmptyConfig
it "has a Show instance" $ do
show cfg `shouldBe` "1 .: 2 .: EmptyConfig"
show cfg `shouldBe` "1 .:. 2 .:. EmptyConfig"
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
let cfg = (1 .: 'a' .: EmptyConfig) :<|> ('b' .: True .: EmptyConfig)
show cfg `shouldBe` "(1 .: 'a' .: EmptyConfig) :<|> ('b' .: True .: EmptyConfig)"
let cfg = (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