diff options
Diffstat (limited to 'autotypes/src')
-rw-r--r-- | autotypes/src/AutoTypes/Unify.hs | 19 |
1 files changed, 3 insertions, 16 deletions
diff --git a/autotypes/src/AutoTypes/Unify.hs b/autotypes/src/AutoTypes/Unify.hs index 2abde6a..bfbd05b 100644 --- a/autotypes/src/AutoTypes/Unify.hs +++ b/autotypes/src/AutoTypes/Unify.hs @@ -13,8 +13,10 @@ where import Control.Arrow import Control.Exception (Exception, throw) import qualified Data.Aeson as A +import qualified Data.Aeson.Encode.Pretty as A import qualified Data.Aeson.Key as K import qualified Data.Aeson.KeyMap as KM +import qualified Data.ByteString.Lazy.Char8 as BL import Data.Aeson.QQ import Data.List (intercalate, nub) import Data.Map (Map) @@ -63,22 +65,7 @@ instance A.ToJSON T where toJSON (Reference i) = A.object [K.fromString "$ref" A..= A.String (T.pack i)] toString :: T -> String -toString = intercalate "\n" . map (\(n, s) -> indent n s) . toString_ 0 - -toString_ :: Int -> T -> [(Int, String)] -toString_ n (Object kvs) = - concat - [ [(n, "{")], - concat . M.elems $ - M.mapWithKey (\s t -> (n + 1, s) : toString_ (n + 2) t) kvs, - [(n, "}")] - ] -toString_ n (Scalar s) = [(n, scalarTypeString s)] -toString_ n (Union ts) = concatMap (toString_ n) ts -toString_ n (Option Nothing) = [(n, "null")] -toString_ n (Option (Just t)) = map (second (++ "?")) (toString_ n t) - -indent n = (++) (replicate (4 * n) ' ') +toString = BL.unpack . A.encodePretty . A.toJSON union :: S.Set T -> T union ts |