json-autotype 0.2.4.0 → 0.2.5.0
raw patch · 4 files changed
+24/−20 lines, 4 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Data.Aeson.AutoType.Alternative: FirstAlt :: a -> Alt a b
- Data.Aeson.AutoType.Alternative: SecondAlt :: b -> Alt a b
- Data.Aeson.AutoType.Alternative: data Alt a b
- Data.Aeson.AutoType.Alternative: instance (Eq a, Eq b) => Eq (Alt a b)
- Data.Aeson.AutoType.Alternative: instance (FromJSON a, FromJSON b) => FromJSON (Alt a b)
- Data.Aeson.AutoType.Alternative: instance (Ord a, Ord b) => Ord (Alt a b)
- Data.Aeson.AutoType.Alternative: instance (Show a, Show b) => Show (Alt a b)
- Data.Aeson.AutoType.Alternative: instance (ToJSON a, ToJSON b) => ToJSON (Alt a b)
+ Data.Aeson.AutoType.Alternative: AltLeft :: a -> (:|:) a b
+ Data.Aeson.AutoType.Alternative: AltRight :: b -> (:|:) a b
+ Data.Aeson.AutoType.Alternative: data (:|:) a b
+ Data.Aeson.AutoType.Alternative: instance (Eq a, Eq b) => Eq (a :|: b)
+ Data.Aeson.AutoType.Alternative: instance (FromJSON a, FromJSON b) => FromJSON (a :|: b)
+ Data.Aeson.AutoType.Alternative: instance (Ord a, Ord b) => Ord (a :|: b)
+ Data.Aeson.AutoType.Alternative: instance (Show a, Show b) => Show (a :|: b)
+ Data.Aeson.AutoType.Alternative: instance (ToJSON a, ToJSON b) => ToJSON (a :|: b)
- Data.Aeson.AutoType.Alternative: fromEither :: Either a b -> Alt a b
+ Data.Aeson.AutoType.Alternative: fromEither :: Either a b -> a :|: b
- Data.Aeson.AutoType.Alternative: toEither :: Alt a b -> Either a b
+ Data.Aeson.AutoType.Alternative: toEither :: a :|: b -> Either a b
Files
- Data/Aeson/AutoType/Alternative.hs +17/−16
- Data/Aeson/AutoType/CodeGen.hs +5/−2
- Data/Aeson/AutoType/Format.hs +1/−1
- json-autotype.cabal +1/−1
Data/Aeson/AutoType/Alternative.hs view
@@ -1,31 +1,32 @@-{-# LANGUAGE ViewPatterns #-}+{-# LANGUAGE ViewPatterns, TypeOperators #-} module Data.Aeson.AutoType.Alternative(- Alt(..)+ (:|:)(..) , toEither, fromEither ) where import Data.Aeson import Control.Applicative -data Alt a b = FirstAlt a- | SecondAlt b+data a :|: b = AltLeft a+ | AltRight b deriving(Show,Eq,Ord)+infixr 5 :|: -toEither :: Alt a b -> Either a b-toEither (FirstAlt a) = Left a-toEither (SecondAlt b) = Right b+toEither :: a :|: b -> Either a b+toEither (AltLeft a) = Left a+toEither (AltRight b) = Right b -fromEither :: Either a b -> Alt a b-fromEither (Left a) = FirstAlt a-fromEither (Right b) = SecondAlt b+fromEither :: Either a b -> a :|: b+fromEither (Left a) = AltLeft a+fromEither (Right b) = AltRight b -instance (ToJSON a, ToJSON b) => ToJSON (Alt a b) where- toJSON (FirstAlt a) = toJSON a- toJSON (SecondAlt b) = toJSON b+instance (ToJSON a, ToJSON b) => ToJSON (a :|: b) where+ toJSON (AltLeft a) = toJSON a+ toJSON (AltRight b) = toJSON b {-# INLINE toJSON #-} -instance (FromJSON a, FromJSON b) => FromJSON (Alt a b) where- parseJSON input = (FirstAlt <$> parseJSON input) <|>- (SecondAlt <$> parseJSON input) <|>+instance (FromJSON a, FromJSON b) => FromJSON (a :|: b) where+ parseJSON input = (AltLeft <$> parseJSON input) <|>+ (AltRight <$> parseJSON input) <|> fail ("Neither alternative was found for: " ++ show input) {-# INLINE parseJSON #-}
Data/Aeson/AutoType/CodeGen.hs view
@@ -26,8 +26,11 @@ header :: Text -> Text header moduleName = Text.unlines [- "{-# LANGUAGE TemplateHaskell, ScopedTypeVariables #-}"- ,"{-# LANGUAGE RecordWildCards, OverloadedStrings #-}"+ "{-# LANGUAGE TemplateHaskell #-}"+ ,"{-# LANGUAGE ScopedTypeVariables #-}"+ ,"{-# LANGUAGE RecordWildCards #-}"+ ,"{-# LANGUAGE OverloadedStrings #-}"+ ,"{-# LANGUAGE TypeOperators #-}" ,"" ,Text.concat ["module ", capitalize moduleName, " where"] ,""
Data/Aeson/AutoType/Format.hs view
@@ -155,7 +155,7 @@ where mkUnion [] = emptyTypeRepr mkUnion nonEmpty = foldr1 mkEither nonEmpty- where mkEither a b = Text.concat ["Alt (", a, ") (", b, ")"]+ where mkEither a b = Text.concat [a, " :|: ", b] formatType (TArray a) = do inner <- formatType a return $ Text.concat ["[", inner, "]"] formatType (TObj o) = do ident <- genericIdentifier
json-autotype.cabal view
@@ -1,6 +1,6 @@ -- Build information for the package. name: json-autotype-version: 0.2.4.0+version: 0.2.5.0 synopsis: Automatic type declaration for JSON input data description: Generates datatype declarations with Aeson's "FromJSON" instances from a set of example ".json" files.