packages feed

aeson-unqualified-ast (empty) → 1

raw patch · 3 files changed

+131/−0 lines, 3 filesdep +aesondep +basedep +scientific

Dependencies added: aeson, base, scientific, text, vector

Files

+ LICENSE view
@@ -0,0 +1,22 @@+Copyright (c) 2023 Nikita Volkov++Permission is hereby granted, free of charge, to any person+obtaining a copy of this software and associated documentation+files (the "Software"), to deal in the Software without+restriction, including without limitation the rights to use,+copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the+Software is furnished to do so, subject to the following+conditions:++The above copyright notice and this permission notice shall be+included in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR+OTHER DEALINGS IN THE SOFTWARE.
+ aeson-unqualified-ast.cabal view
@@ -0,0 +1,34 @@+cabal-version: 3.0+name:          aeson-unqualified-ast+version:       1+author:        Nikita Volkov <nikita.y.volkov@mail.ru>+maintainer:    Nikita Volkov <nikita.y.volkov@mail.ru>+copyright:     (c) 2023 Nikita Volkov+license:       MIT+license-file:  LICENSE+synopsis:      Aliases to "aeson" AST making it importable unqualified+description:+  Reasonable type aliases and patterns for the AST definitions of \"aeson\",+  which are unlikely to cause any conflicts when imported unqualified.+  As such the definitions from this package are safe to reexport from custom preludes.+  .+  The package provides a "Json" type alias and pattern synonyms,+  which are both descriptive and unambiguous, unlike the ones in the \"aeson\" package.++common language-settings+  default-language:   Haskell2010+  default-extensions:+    NoImplicitPrelude+    ImportQualifiedPost+    PatternSynonyms++library+  import:          language-settings+  hs-source-dirs:  src/library+  exposed-modules: Data.Aeson.UnqualifiedAst+  build-depends:+    , aeson >=2 && <3+    , base >=4.5 && <5+    , scientific >=0.3.7.0 && <0.4+    , text >=1.2.3.0 && <1.3 || >=2.0 && <2.2+    , vector >=0.13 && <0.14
+ src/library/Data/Aeson/UnqualifiedAst.hs view
@@ -0,0 +1,75 @@+-- | Definitions of JSON AST in terms of the \"aeson\" package.+--+-- This module is intended to be imported unqualified.+-- It is obliged by the package policy to never pollute the namespace.+--+-- The naming policy that we use here:+--+-- - Constructors are to be suffixed with the type name. Read the name as answering the question of what instance of the type it is. E.g., 'ObjectJson', standing for an object kind of JSON.+-- - Subtypes are to be prefixed with the parent type. Read the name as a path. E.g., 'JsonObject' stands for @Json/Object@.+--+-- This policy is pretty universal and it has been applied successfully to disambiguate very large models.+module Data.Aeson.UnqualifiedAst where++import Data.Aeson qualified as Aeson+import Data.Aeson.KeyMap qualified as AesonKeyMap+import Data.Bool (Bool)+import Data.Scientific (Scientific)+import Data.Text (Text)+import Data.Vector (Vector)++-- * Json type++-- |+-- Alias to JSON AST representation in terms of the \"aeson\" package.+--+-- Together with the associated pattern synonym definitions that are defined in this module+-- this type provides virtually the same API as the following definition:+--+-- > data Json+-- >   = ObjectJson (KeyMap Json)+-- >   | ArrayJson (Vector Json)+-- >   | StringJson Text+-- >   | NumberJson Scientific+-- >   | BoolJson Bool+-- >   | NullJson+--+-- At the same time being just an alias it is completely interchangeable with the 'Aeson.Value' definition from \"aeson\" at zero runtime cost.+type Json = Aeson.Value++-- ** Json pattern synonyms++-- | Alias to the v'Aeson.Object' constructor and its pattern.+pattern ObjectJson :: JsonObject -> Json+pattern ObjectJson object = Aeson.Object object++-- | Alias to the v'Aeson.Array' constructor and its pattern.+pattern ArrayJson :: JsonArray -> Json+pattern ArrayJson array = Aeson.Array array++-- | Alias to the v'Aeson.String' constructor and its pattern.+pattern StringJson :: Text -> Json+pattern StringJson text = Aeson.String text++-- | Alias to the v'Aeson.Number' constructor and its pattern.+pattern NumberJson :: Scientific -> Json+pattern NumberJson scientific = Aeson.Number scientific++-- | Alias to the v'Aeson.Bool' constructor and its pattern.+pattern BoolJson :: Bool -> Json+pattern BoolJson bool = Aeson.Bool bool++-- | Alias to the v'Aeson.Null' constructor and its pattern.+pattern NullJson :: Json+pattern NullJson = Aeson.Null++-- * Other types++-- | Alias to JSON Object AST.+type JsonObject = AesonKeyMap.KeyMap Json++-- | Alias to key for 'JsonObject'.+type JsonObjectKey = AesonKeyMap.Key++-- | Alias to JSON Array AST.+type JsonArray = Vector Json