hydra 0.1.0 → 0.1.1
raw patch · 124 files changed
+564/−438 lines, 124 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Hydra.Impl.Haskell.GraphIO: addDeepTypeAnnotations :: (Ord m, Show m) => Module m -> GraphFlow m (Module m)
- Hydra.Impl.Haskell.GraphIO: allModules :: [Module Meta]
- Hydra.Impl.Haskell.GraphIO: assignSchemas :: (Ord m, Show m) => Bool -> Module m -> GraphFlow m (Module m)
- Hydra.Impl.Haskell.GraphIO: coreModules :: [Module Meta]
- Hydra.Impl.Haskell.GraphIO: extModules :: [Module Meta]
- Hydra.Impl.Haskell.GraphIO: findType :: Context m -> Term m -> GraphFlow m (Maybe (Type m))
- Hydra.Impl.Haskell.GraphIO: generateSources :: (Module Meta -> GraphFlow Meta (Map FilePath String)) -> [Module Meta] -> FilePath -> IO ()
- Hydra.Impl.Haskell.GraphIO: hydraKernel :: Graph Meta
- Hydra.Impl.Haskell.GraphIO: kernelContext :: Context Meta
- Hydra.Impl.Haskell.GraphIO: modulesToContext :: [Module Meta] -> Context Meta
- Hydra.Impl.Haskell.GraphIO: printTrace :: Bool -> Trace -> IO ()
- Hydra.Impl.Haskell.GraphIO: runFlow :: s -> Flow s a -> IO (Maybe a)
- Hydra.Impl.Haskell.GraphIO: writeHaskell :: [Module Meta] -> FilePath -> IO ()
- Hydra.Impl.Haskell.GraphIO: writeJava :: [Module Meta] -> FilePath -> IO ()
- Hydra.Impl.Haskell.GraphIO: writePdl :: [Module Meta] -> FilePath -> IO ()
- Hydra.Impl.Haskell.GraphIO: writeScala :: [Module Meta] -> FilePath -> IO ()
- Hydra.Impl.Haskell.GraphIO: writeYaml :: [Module Meta] -> FilePath -> IO ()
- Hydra.Sorting: topologicalSort :: Eq a => [(a, [a])] -> Maybe [a]
- Hydra.Util.Context: getAttr :: String -> Flow s (Maybe (Term Meta))
- Hydra.Util.Context: getAttrWithDefault :: String -> Term Meta -> Flow s (Term Meta)
- Hydra.Util.Context: nextCount :: String -> Flow s Int
- Hydra.Util.Context: putAttr :: String -> Term Meta -> Flow s ()
+ Hydra.Impl.Haskell.Codegen: addDeepTypeAnnotations :: (Ord m, Show m) => Module m -> GraphFlow m (Module m)
+ Hydra.Impl.Haskell.Codegen: allModules :: [Module Meta]
+ Hydra.Impl.Haskell.Codegen: assignSchemas :: (Ord m, Show m) => Bool -> Module m -> GraphFlow m (Module m)
+ Hydra.Impl.Haskell.Codegen: coreModules :: [Module Meta]
+ Hydra.Impl.Haskell.Codegen: extModules :: [Module Meta]
+ Hydra.Impl.Haskell.Codegen: findType :: Context m -> Term m -> GraphFlow m (Maybe (Type m))
+ Hydra.Impl.Haskell.Codegen: generateSources :: (Module Meta -> GraphFlow Meta (Map FilePath String)) -> [Module Meta] -> FilePath -> IO ()
+ Hydra.Impl.Haskell.Codegen: hydraKernel :: Graph Meta
+ Hydra.Impl.Haskell.Codegen: kernelContext :: Context Meta
+ Hydra.Impl.Haskell.Codegen: modulesToContext :: [Module Meta] -> Context Meta
+ Hydra.Impl.Haskell.Codegen: printTrace :: Bool -> Trace -> IO ()
+ Hydra.Impl.Haskell.Codegen: runFlow :: s -> Flow s a -> IO (Maybe a)
+ Hydra.Impl.Haskell.Codegen: utilModules :: [Module Meta]
+ Hydra.Impl.Haskell.Codegen: writeHaskell :: [Module Meta] -> FilePath -> IO ()
+ Hydra.Impl.Haskell.Codegen: writeJava :: [Module Meta] -> FilePath -> IO ()
+ Hydra.Impl.Haskell.Codegen: writePdl :: [Module Meta] -> FilePath -> IO ()
+ Hydra.Impl.Haskell.Codegen: writeScala :: [Module Meta] -> FilePath -> IO ()
+ Hydra.Impl.Haskell.Codegen: writeYaml :: [Module Meta] -> FilePath -> IO ()
+ Hydra.Meta: getAttr :: String -> Flow s (Maybe (Term Meta))
+ Hydra.Meta: getAttrWithDefault :: String -> Term Meta -> Flow s (Term Meta)
+ Hydra.Meta: nextCount :: String -> Flow s Int
+ Hydra.Meta: putAttr :: String -> Term Meta -> Flow s ()
+ Hydra.Util.Sorting: topologicalSort :: Eq a => [(a, [a])] -> Maybe [a]
Files
- README.md +13/−13
- hydra.cabal +5/−6
- src/gen-main/haskell/Hydra/Compute.hs +8/−0
- src/gen-main/haskell/Hydra/Core.hs +6/−2
- src/gen-main/haskell/Hydra/Grammar.hs +14/−1
- src/gen-main/haskell/Hydra/Phantoms.hs +5/−0
- src/main/haskell/Hydra/Adapters/Coders.hs +5/−1
- src/main/haskell/Hydra/Adapters/Literal.hs +3/−1
- src/main/haskell/Hydra/Adapters/Term.hs +5/−2
- src/main/haskell/Hydra/Adapters/UtilsEtc.hs +3/−1
- src/main/haskell/Hydra/All.hs +0/−51
- src/main/haskell/Hydra/Common.hs +2/−0
- src/main/haskell/Hydra/CoreDecoding.hs +2/−0
- src/main/haskell/Hydra/CoreEncoding.hs +2/−0
- src/main/haskell/Hydra/CoreLanguage.hs +2/−0
- src/main/haskell/Hydra/Ext/Avro/Coder.hs +1/−1
- src/main/haskell/Hydra/Ext/Avro/Language.hs +1/−1
- src/main/haskell/Hydra/Ext/Avro/SchemaJson.hs +1/−1
- src/main/haskell/Hydra/Ext/Graphql/Coder.hs +1/−1
- src/main/haskell/Hydra/Ext/Graphql/Language.hs +1/−1
- src/main/haskell/Hydra/Ext/Haskell/Coder.hs +1/−1
- src/main/haskell/Hydra/Ext/Haskell/Language.hs +1/−1
- src/main/haskell/Hydra/Ext/Haskell/Utils.hs +1/−1
- src/main/haskell/Hydra/Ext/Java/Coder.hs +2/−2
- src/main/haskell/Hydra/Ext/Java/Language.hs +1/−1
- src/main/haskell/Hydra/Ext/Java/Utils.hs +1/−1
- src/main/haskell/Hydra/Ext/Json/Coder.hs +1/−1
- src/main/haskell/Hydra/Ext/Json/Eliminate.hs +1/−1
- src/main/haskell/Hydra/Ext/Json/Language.hs +1/−1
- src/main/haskell/Hydra/Ext/Pegasus/Coder.hs +1/−1
- src/main/haskell/Hydra/Ext/Pegasus/Language.hs +1/−1
- src/main/haskell/Hydra/Ext/Scala/Coder.hs +9/−18
- src/main/haskell/Hydra/Ext/Scala/Language.hs +1/−1
- src/main/haskell/Hydra/Ext/Scala/Prepare.hs +1/−1
- src/main/haskell/Hydra/Ext/Scala/Utils.hs +1/−1
- src/main/haskell/Hydra/Ext/Shacl/Coder.hs +2/−2
- src/main/haskell/Hydra/Ext/Shacl/Language.hs +1/−1
- src/main/haskell/Hydra/Ext/Tinkerpop/Language.hs +1/−1
- src/main/haskell/Hydra/Ext/Yaml/Coder.hs +1/−1
- src/main/haskell/Hydra/Ext/Yaml/Language.hs +1/−1
- src/main/haskell/Hydra/Ext/Yaml/Modules.hs +1/−1
- src/main/haskell/Hydra/Impl/Haskell/Codegen.hs +173/−0
- src/main/haskell/Hydra/Impl/Haskell/Dsl/Base.hs +3/−1
- src/main/haskell/Hydra/Impl/Haskell/Dsl/Bootstrap.hs +3/−1
- src/main/haskell/Hydra/Impl/Haskell/Dsl/Grammars.hs +3/−1
- src/main/haskell/Hydra/Impl/Haskell/Dsl/Literals.hs +3/−1
- src/main/haskell/Hydra/Impl/Haskell/Dsl/PhantomLiterals.hs +3/−1
- src/main/haskell/Hydra/Impl/Haskell/Dsl/Prims.hs +3/−1
- src/main/haskell/Hydra/Impl/Haskell/Dsl/Standard.hs +3/−1
- src/main/haskell/Hydra/Impl/Haskell/Dsl/Terms.hs +3/−1
- src/main/haskell/Hydra/Impl/Haskell/Dsl/Types.hs +3/−1
- src/main/haskell/Hydra/Impl/Haskell/Ext/Json/Serde.hs +1/−1
- src/main/haskell/Hydra/Impl/Haskell/Ext/Yaml/Serde.hs +1/−1
- src/main/haskell/Hydra/Impl/Haskell/GraphIO.hs +0/−169
- src/main/haskell/Hydra/Impl/Haskell/Sources/Adapters/Utils.hs +1/−1
- src/main/haskell/Hydra/Impl/Haskell/Sources/Basics.hs +1/−1
- src/main/haskell/Hydra/Impl/Haskell/Sources/Compute.hs +9/−2
- src/main/haskell/Hydra/Impl/Haskell/Sources/Core.hs +9/−5
- src/main/haskell/Hydra/Impl/Haskell/Sources/CoreLang.hs +1/−1
- src/main/haskell/Hydra/Impl/Haskell/Sources/Ext/Avro/Schema.hs +1/−1
- src/main/haskell/Hydra/Impl/Haskell/Sources/Ext/Graphql/Syntax.hs +1/−1
- src/main/haskell/Hydra/Impl/Haskell/Sources/Ext/Haskell/Ast.hs +1/−1
- src/main/haskell/Hydra/Impl/Haskell/Sources/Ext/Java/Syntax.hs +1/−1
- src/main/haskell/Hydra/Impl/Haskell/Sources/Ext/Json/Model.hs +1/−1
- src/main/haskell/Hydra/Impl/Haskell/Sources/Ext/Owl/Syntax.hs +1/−1
- src/main/haskell/Hydra/Impl/Haskell/Sources/Ext/Pegasus/Pdl.hs +1/−1
- src/main/haskell/Hydra/Impl/Haskell/Sources/Ext/Rdf/Syntax.hs +1/−1
- src/main/haskell/Hydra/Impl/Haskell/Sources/Ext/Scala/Meta.hs +1/−1
- src/main/haskell/Hydra/Impl/Haskell/Sources/Ext/Shacl/Model.hs +1/−1
- src/main/haskell/Hydra/Impl/Haskell/Sources/Ext/Tinkerpop/Features.hs +1/−1
- src/main/haskell/Hydra/Impl/Haskell/Sources/Ext/Tinkerpop/Typed.hs +1/−1
- src/main/haskell/Hydra/Impl/Haskell/Sources/Ext/Tinkerpop/V3.hs +1/−1
- src/main/haskell/Hydra/Impl/Haskell/Sources/Ext/Xml/Schema.hs +1/−1
- src/main/haskell/Hydra/Impl/Haskell/Sources/Ext/Yaml/Model.hs +1/−1
- src/main/haskell/Hydra/Impl/Haskell/Sources/Grammar.hs +39/−23
- src/main/haskell/Hydra/Impl/Haskell/Sources/Libraries.hs +1/−1
- src/main/haskell/Hydra/Impl/Haskell/Sources/Mantle.hs +1/−1
- src/main/haskell/Hydra/Impl/Haskell/Sources/Module.hs +1/−1
- src/main/haskell/Hydra/Impl/Haskell/Sources/Phantoms.hs +6/−1
- src/main/haskell/Hydra/Impl/Haskell/Sources/Util/Codetree/Ast.hs +1/−1
- src/main/haskell/Hydra/Kernel.hs +50/−0
- src/main/haskell/Hydra/Lexical.hs +2/−0
- src/main/haskell/Hydra/Lib/Flows.hs +3/−1
- src/main/haskell/Hydra/Lib/Io.hs +3/−1
- src/main/haskell/Hydra/Lib/Lists.hs +2/−0
- src/main/haskell/Hydra/Lib/Literals.hs +2/−0
- src/main/haskell/Hydra/Lib/Maps.hs +2/−0
- src/main/haskell/Hydra/Lib/Math.hs +2/−0
- src/main/haskell/Hydra/Lib/Optionals.hs +2/−0
- src/main/haskell/Hydra/Lib/Sets.hs +2/−0
- src/main/haskell/Hydra/Lib/Strings.hs +2/−0
- src/main/haskell/Hydra/Meta.hs +25/−4
- src/main/haskell/Hydra/Monads.hs +2/−0
- src/main/haskell/Hydra/Reduction.hs +3/−1
- src/main/haskell/Hydra/Rewriting.hs +3/−2
- src/main/haskell/Hydra/Sorting.hs +0/−17
- src/main/haskell/Hydra/Types/Inference.hs +7/−7
- src/main/haskell/Hydra/Types/Substitution.hs +3/−1
- src/main/haskell/Hydra/Types/Unification.hs +3/−1
- src/main/haskell/Hydra/Util/Codetree/Script.hs +2/−0
- src/main/haskell/Hydra/Util/Context.hs +0/−27
- src/main/haskell/Hydra/Util/Debug.hs +2/−0
- src/main/haskell/Hydra/Util/Formatting.hs +2/−0
- src/main/haskell/Hydra/Util/GrammarToModule.hs +3/−1
- src/main/haskell/Hydra/Util/Sorting.hs +20/−0
- src/test/haskell/Hydra/Adapters/LiteralSpec.hs +1/−1
- src/test/haskell/Hydra/Adapters/TermSpec.hs +1/−1
- src/test/haskell/Hydra/ArbitraryCore.hs +1/−1
- src/test/haskell/Hydra/CommonSpec.hs +1/−1
- src/test/haskell/Hydra/CoreCodersSpec.hs +1/−1
- src/test/haskell/Hydra/Ext/Json/CoderSpec.hs +1/−1
- src/test/haskell/Hydra/Ext/Yaml/CoderSpec.hs +1/−1
- src/test/haskell/Hydra/Impl/Haskell/Dsl/TypesSpec.hs +1/−1
- src/test/haskell/Hydra/Impl/Haskell/Ext/Json/SerdeSpec.hs +1/−1
- src/test/haskell/Hydra/Impl/Haskell/Ext/Yaml/SerdeSpec.hs +1/−1
- src/test/haskell/Hydra/MetaSpec.hs +1/−1
- src/test/haskell/Hydra/ReductionSpec.hs +1/−1
- src/test/haskell/Hydra/RewritingSpec.hs +1/−1
- src/test/haskell/Hydra/TestData.hs +1/−1
- src/test/haskell/Hydra/TestGraph.hs +1/−1
- src/test/haskell/Hydra/TestUtils.hs +1/−1
- src/test/haskell/Hydra/Types/InferenceSpec.hs +1/−1
- src/test/haskell/Hydra/Types/UnificationSpec.hs +1/−1
- src/test/haskell/Hydra/Util/Codetree/PrintSpec.hs +1/−1
README.md view
@@ -25,12 +25,13 @@ ## Code generation -One of the main objectives for Hydra is for the framework to generate its own source code into various languages,+It is a long-term goal for Hydra to generate its own source code into various languages, producing nearly-complete Hydra implementations in those languages.-At this time, Haskell is fully supported as a target language, while Java is supported for schemas only (i.e. Hydra type definitions map to Java classes),-and Scala is supported for data only (i.e. constants and functions are mapped, but types are not yet).+Both Haskell are fully supported as target languages,+which means that all of Hydra's type and programs currently specified in the Haskell DSL are mapped correctly to both Haskell and Java.+Scala support, on the other hand, is partial and experimental at this time. -You can generate Hydra's sources by first entering the GHCi REPL as above, then:+You can generate Hydra's Haskell sources by first entering the GHCi REPL as above, then: ```bash writeHaskell allModules "/path/to/CategoricalData/hydra/hydra-haskell/src/gen-main/haskell"@@ -38,37 +39,36 @@ The first argument to `writeHaskell` is the list of modules you want to generate (in this case, a special list containing all built-in modules), and the second is the base directory to which the generated files are to be written.-For individual modules, use Haskell list syntax, e.g.+For individual modules, use list syntax, e.g. ```bash writeHaskell [rdfSyntaxModule, shaclModelModule] "/path/to/CategoricalData/hydra/hydra-haskell/src/gen-main/haskell" ``` -The commands for Scala and Java generation are similar, e.g.+Java generation is similar, e.g. ```bash-writeScala allModules "/path/to/CategoricalData/hydra/hydra-scala/src/gen-main/scala"+writeJava allModules "/path/to/CategoricalData/hydra/hydra-java/src/gen-main/java" ``` -and+Scala generation has known bugs, but you can try it out with: ```bash-writeJava allModules "/path/to/CategoricalData/hydra/hydra-java/src/gen-main/java"+writeScala coreModules "/path/to/CategoricalData/hydra/hydra-scala/src/gen-main/scala" ``` There is also schema-only support for PDL: ```bash-writePdl allModules "/tmp/pdl"+writePdl coreModules "/tmp/pdl" ``` -For languages other than Haskell and Java, you can expect error messages from Hydra where a given coder encounters language features which are not yet fully implemented.- ## Haskell API ### Structures -The most important structural types in Hydra are `Type` and `Term` (provided in the generated [Hydra.Core](https://github.com/CategoricalData/hydra/blob/main/hydra-haskell/src/gen-main/haskell/Hydra/Core.hs) module in Haskell), and `Graph` and `Element` (provided in the generated [Hydra.Graph](https://github.com/CategoricalData/hydra/blob/main/hydra-haskell/src/gen-main/haskell/Hydra/Graph.hs) module).+The most important structural types in Hydra are `Type` and `Term` (provided in the generated [Hydra.Core](https://github.com/CategoricalData/hydra/blob/main/hydra-haskell/src/gen-main/haskell/Hydra/Core.hs) module in Haskell),+and `Graph` and `Element` (provided in the generated [Hydra.Mantle](https://github.com/CategoricalData/hydra/blob/main/hydra-haskell/src/gen-main/haskell/Hydra/Mantle.hs) module). `Type` provides a datatype, and a `Term` is an instance of a known `Type`. An `Element` is a named term together with its type, and a `Graph` is a collection of elements. A `Module` is a collection of elements in the same logical namespace, sometimes called a "model" if most of the elements represent type definitions.
hydra.cabal view
@@ -5,8 +5,8 @@ -- see: https://github.com/sol/hpack name: hydra-version: 0.1.0-synopsis: Type-aware transformations for data and functional programs+version: 0.1.1+synopsis: Type-aware transformations for data and programs description: Hydra is a transformation toolkit along the lines of Dragon (Uber), but open source, and with a more advanced type system and other new features. Hydra maps data and schemas between languages in a way which maintains type conformance. It will even map functional programs between selected languages, including parts of its own source code. category: Data homepage: https://github.com/CategoricalData/hydra#readme@@ -32,7 +32,6 @@ Hydra.Adapters.Literal Hydra.Adapters.Term Hydra.Adapters.UtilsEtc- Hydra.All Hydra.Common Hydra.CoreDecoding Hydra.CoreEncoding@@ -72,6 +71,7 @@ Hydra.Ext.Yaml.Coder Hydra.Ext.Yaml.Language Hydra.Ext.Yaml.Modules+ Hydra.Impl.Haskell.Codegen Hydra.Impl.Haskell.Dsl.Base Hydra.Impl.Haskell.Dsl.Bootstrap Hydra.Impl.Haskell.Dsl.Grammars@@ -89,7 +89,6 @@ Hydra.Impl.Haskell.Ext.Bytestrings Hydra.Impl.Haskell.Ext.Json.Serde Hydra.Impl.Haskell.Ext.Yaml.Serde- Hydra.Impl.Haskell.GraphIO Hydra.Impl.Haskell.Sources.Adapters.Utils Hydra.Impl.Haskell.Sources.Basics Hydra.Impl.Haskell.Sources.Compute@@ -117,6 +116,7 @@ Hydra.Impl.Haskell.Sources.Module Hydra.Impl.Haskell.Sources.Phantoms Hydra.Impl.Haskell.Sources.Util.Codetree.Ast+ Hydra.Kernel Hydra.Lexical Hydra.Lib.Flows Hydra.Lib.Io@@ -131,15 +131,14 @@ Hydra.Monads Hydra.Reduction Hydra.Rewriting- Hydra.Sorting Hydra.Types.Inference Hydra.Types.Substitution Hydra.Types.Unification Hydra.Util.Codetree.Script- Hydra.Util.Context Hydra.Util.Debug Hydra.Util.Formatting Hydra.Util.GrammarToModule+ Hydra.Util.Sorting Hydra.Adapters.Utils Hydra.Basics Hydra.Compute
src/gen-main/haskell/Hydra/Compute.hs view
@@ -8,6 +8,7 @@ import Data.Map import Data.Set +-- | A two-level bidirectional encoder which adapts types to types and terms to terms data Adapter s1 s2 t1 t2 v1 v2 = Adapter { adapterIsLossy :: Bool,@@ -25,6 +26,7 @@ _Adapter_coder = (Core.FieldName "coder") +-- | An evaluation context together with a source language and a target language data AdapterContext m = AdapterContext { adapterContextEvaluation :: (Context m),@@ -146,6 +148,7 @@ _Flow = (Core.Name "hydra/compute.Flow") +-- | The result of evaluating a Flow data FlowState s a = FlowState { flowStateValue :: (Maybe a),@@ -161,6 +164,7 @@ _FlowState_trace = (Core.FieldName "trace") +-- | A named language together with language-specific constraints data Language m = Language { languageName :: LanguageName,@@ -172,6 +176,7 @@ _Language_constraints = (Core.FieldName "constraints") +-- | A set of constraints on valid type and term expressions, characterizing a language data LanguageConstraints m = LanguageConstraints { languageConstraintsEliminationVariants :: (Set Mantle.EliminationVariant),@@ -201,8 +206,10 @@ _LanguageConstraints_types = (Core.FieldName "types") +-- | The unique name of a language newtype LanguageName = LanguageName {+ -- | The unique name of a language unLanguageName :: String} deriving (Eq, Ord, Read, Show) @@ -263,6 +270,7 @@ _Trace_other = (Core.FieldName "other") +-- | Specifies either a pre-order or post-order traversal data TraversalOrder = -- | Pre-order traversal TraversalOrderPre |
src/gen-main/haskell/Hydra/Core.hs view
@@ -6,6 +6,7 @@ import Data.Map import Data.Set +-- | An object, such as a type or term, together with an annotation data Annotated a m = Annotated { annotatedSubject :: a,@@ -48,6 +49,7 @@ _ApplicationType_argument = (FieldName "argument") +-- | A union elimination; a case statement data CaseStatement m = CaseStatement { caseStatementTypeName :: Name,@@ -103,10 +105,10 @@ _Field_term = (FieldName "term") --- | The name of a field+-- | The name of a field, unique within a record or union type newtype FieldName = FieldName {- -- | The name of a field+ -- | The name of a field, unique within a record or union type unFieldName :: String} deriving (Eq, Ord, Read, Show) @@ -411,6 +413,7 @@ _OptionalCases_just = (FieldName "just") +-- | A record elimination; a projection data Projection = Projection { projectionTypeName :: Name,@@ -645,6 +648,7 @@ _Union_field = (FieldName "field") +-- | An empty record type as a canonical unit type data UnitType = UnitType {} deriving (Eq, Ord, Read, Show)
src/gen-main/haskell/Hydra/Grammar.hs view
@@ -1,4 +1,4 @@--- | A common API for BNF-based grammars+-- | A common API for BNF-based grammars, specifying context-free languages module Hydra.Grammar where @@ -7,27 +7,34 @@ import Data.Map import Data.Set +-- | A constant pattern newtype Constant = Constant {+ -- | A constant pattern unConstant :: String} deriving (Eq, Ord, Read, Show) _Constant = (Core.Name "hydra/grammar.Constant") +-- | An enhanced Backus-Naur form (BNF) grammar newtype Grammar = Grammar {+ -- | An enhanced Backus-Naur form (BNF) grammar unGrammar :: [Production]} deriving (Eq, Ord, Read, Show) _Grammar = (Core.Name "hydra/grammar.Grammar") +-- | A name for a pattern newtype Label = Label {+ -- | A name for a pattern unLabel :: String} deriving (Eq, Ord, Read, Show) _Label = (Core.Name "hydra/grammar.Label") +-- | A pattern together with a name (label) data LabeledPattern = LabeledPattern { labeledPatternLabel :: Label,@@ -40,6 +47,7 @@ _LabeledPattern_pattern = (Core.FieldName "pattern") +-- | A pattern which matches valid expressions in the language data Pattern = PatternNil | PatternIgnored Pattern |@@ -78,6 +86,7 @@ _Pattern_plus = (Core.FieldName "plus") +-- | A BNF production data Production = Production { productionSymbol :: Symbol,@@ -90,15 +99,19 @@ _Production_pattern = (Core.FieldName "pattern") +-- | A regular expression newtype Regex = Regex {+ -- | A regular expression unRegex :: String} deriving (Eq, Ord, Read, Show) _Regex = (Core.Name "hydra/grammar.Regex") +-- | A nonterminal symbol newtype Symbol = Symbol {+ -- | A nonterminal symbol unSymbol :: String} deriving (Eq, Ord, Read, Show)
src/gen-main/haskell/Hydra/Phantoms.hs view
@@ -8,6 +8,7 @@ import Data.Map import Data.Set +-- | An association of a field name (as in a case statement) with a phantom type newtype Case a = Case { unCase :: Core.FieldName}@@ -15,6 +16,7 @@ _Case = (Core.Name "hydra/phantoms.Case") +-- | An association of a term with a phantom type newtype Datum a = Datum { unDatum :: (Core.Term Compute.Meta)}@@ -22,6 +24,7 @@ _Datum = (Core.Name "hydra/phantoms.Datum") +-- | An association with a named term with a phantom type data Definition a = Definition { definitionName :: Core.Name,@@ -34,6 +37,7 @@ _Definition_datum = (Core.FieldName "datum") +-- | An association with a term-level field with a phantom type newtype Fld a = Fld { unFld :: (Core.Field Compute.Meta)}@@ -41,6 +45,7 @@ _Fld = (Core.Name "hydra/phantoms.Fld") +-- | A pure association with a phantom type data Reference a = Reference {} deriving (Eq, Ord, Read, Show)
src/main/haskell/Hydra/Adapters/Coders.hs view
@@ -1,6 +1,10 @@+-- | Entry point for Hydra's adapter (type/term rewriting) framework.+-- An adapter takes a type expression which is supported in a source language, and rewrites it to a type which is supported by a target language.+-- In parallel, terms conforming to the original type are rewritten. Both levels of the transformation are bidirectional.+ module Hydra.Adapters.Coders where -import Hydra.All+import Hydra.Kernel import Hydra.CoreDecoding import Hydra.Adapters.Term import Hydra.Adapters.UtilsEtc
src/main/haskell/Hydra/Adapters/Literal.hs view
@@ -1,10 +1,12 @@+-- | Adapter framework for literal types and terms+ module Hydra.Adapters.Literal ( literalAdapter, floatAdapter, integerAdapter, ) where -import Hydra.All+import Hydra.Kernel import Hydra.Adapters.UtilsEtc import qualified Data.List as L
src/main/haskell/Hydra/Adapters/Term.hs view
@@ -1,3 +1,5 @@+-- | Adapter framework for types and terms+ module Hydra.Adapters.Term ( fieldAdapter, functionProxyName,@@ -5,7 +7,7 @@ termAdapter, ) where -import Hydra.All+import Hydra.Kernel import Hydra.CoreDecoding import Hydra.Reduction import Hydra.Adapters.Literal@@ -267,7 +269,8 @@ let lossy = or $ adapterIsLossy <$> adapters let sfields' = adapterTarget . snd <$> M.toList adapters return $ Adapter lossy t (TypeUnion $ rt {rowTypeFields = sfields'})- $ bidirectional $ \dir (TermUnion (Union _ dfield)) -> do+ $ bidirectional $ \dir term -> do+ dfield <- expectUnion term ad <- getAdapter adapters dfield TermUnion . Union nm <$> encodeDecode dir (adapterCoder ad) dfield where
src/main/haskell/Hydra/Adapters/UtilsEtc.hs view
@@ -1,3 +1,5 @@+-- | Additional adapter utilities, above and beyond the generated ones+ module Hydra.Adapters.UtilsEtc ( module Hydra.Adapters.UtilsEtc, module Hydra.Adapters.Utils,@@ -14,7 +16,7 @@ import qualified Hydra.Lib.Strings as Strings import Hydra.Util.Formatting import Hydra.Rewriting-import Hydra.Util.Context+import Hydra.Meta import qualified Hydra.Impl.Haskell.Dsl.Terms as Terms import qualified Data.List as L
− src/main/haskell/Hydra/All.hs
@@ -1,51 +0,0 @@--- | Provides in Haskell all modules which are either generated and/or are in the top-level Hydra.* namespace.--- Additionally, some Hydra.Util.* modules are included.--- Hydra.CoreDecoding and Hydra.CoreEncoding, Hydra.Meta, and Hydra.Reduction are excluded due to their dependencies on the Hydra DSLs--module Hydra.All (- module Hydra.Adapters.Utils,- module Hydra.Basics,- module Hydra.Common,- module Hydra.Compute,- module Hydra.Core,--- module Hydra.CoreDecoding,--- module Hydra.CoreEncoding,- module Hydra.CoreLanguage,- module Hydra.Grammar,- module Hydra.Lexical,- module Hydra.Mantle,--- module Hydra.Meta,- module Hydra.Module,- module Hydra.Monads,- module Hydra.Phantoms,--- module Hydra.Reduction,- module Hydra.Rewriting,- module Hydra.Sorting,- module Hydra.Util.Formatting,--- module Hydra.Util.Context,- module Hydra.Util.Debug,--- module Hydra.Util.GrammarToModule,-) where--import Hydra.Adapters.Utils-import Hydra.Basics-import Hydra.Common-import Hydra.Compute-import Hydra.Core---import Hydra.CoreDecoding---import Hydra.CoreEncoding-import Hydra.CoreLanguage-import Hydra.Grammar-import Hydra.Lexical-import Hydra.Mantle---import Hydra.Meta-import Hydra.Module-import Hydra.Monads-import Hydra.Phantoms---import Hydra.Reduction-import Hydra.Rewriting-import Hydra.Sorting-import Hydra.Util.Formatting---import Hydra.Util.Context-import Hydra.Util.Debug---import Hydra.Util.GrammarToModule
src/main/haskell/Hydra/Common.hs view
@@ -1,3 +1,5 @@+-- | Common functions for working with terms, types, and names+ module Hydra.Common where import Hydra.Core
src/main/haskell/Hydra/CoreDecoding.hs view
@@ -1,3 +1,5 @@+-- | Decoding of encoded types (as terms) back to types+ module Hydra.CoreDecoding ( decodeLiteralType, decodeFieldType,
src/main/haskell/Hydra/CoreEncoding.hs view
@@ -1,3 +1,5 @@+-- | Encoding of types as terms+ module Hydra.CoreEncoding where import Hydra.Core
src/main/haskell/Hydra/CoreLanguage.hs view
@@ -1,3 +1,5 @@+-- | Core language constraints of Hydra. These constraints are trivial; all types and all terms are supported.+ module Hydra.CoreLanguage where import Hydra.Compute
src/main/haskell/Hydra/Ext/Avro/Coder.hs view
@@ -1,6 +1,6 @@ module Hydra.Ext.Avro.Coder where -import Hydra.All+import Hydra.Kernel import Hydra.Adapters.Coders import qualified Hydra.Lib.Strings as Strings import qualified Hydra.Impl.Haskell.Dsl.Types as Types
src/main/haskell/Hydra/Ext/Avro/Language.hs view
@@ -1,6 +1,6 @@ module Hydra.Ext.Avro.Language where -import Hydra.All+import Hydra.Kernel import qualified Data.Set as S
src/main/haskell/Hydra/Ext/Avro/SchemaJson.hs view
@@ -1,6 +1,6 @@ module Hydra.Ext.Avro.SchemaJson where -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Dsl.Standard import Hydra.Impl.Haskell.Ext.Json.Serde import qualified Hydra.Ext.Avro.Schema as Avro
src/main/haskell/Hydra/Ext/Graphql/Coder.hs view
@@ -1,6 +1,6 @@ module Hydra.Ext.Graphql.Coder where -- (printGraph) where -import Hydra.All+import Hydra.Kernel --import Hydra.Adapter --import Hydra.Adapters.Term --import Hydra.CoreDecoding
src/main/haskell/Hydra/Ext/Graphql/Language.hs view
@@ -1,6 +1,6 @@ module Hydra.Ext.Graphql.Language where -import Hydra.All+import Hydra.Kernel import qualified Data.Set as S
src/main/haskell/Hydra/Ext/Haskell/Coder.hs view
@@ -1,6 +1,6 @@ module Hydra.Ext.Haskell.Coder (printModule) where -import Hydra.All+import Hydra.Kernel import Hydra.CoreDecoding import Hydra.Adapters.Coders import Hydra.Ext.Haskell.Language
src/main/haskell/Hydra/Ext/Haskell/Language.hs view
@@ -1,6 +1,6 @@ module Hydra.Ext.Haskell.Language where -import Hydra.All+import Hydra.Kernel import qualified Data.Set as S
src/main/haskell/Hydra/Ext/Haskell/Utils.hs view
@@ -1,6 +1,6 @@ module Hydra.Ext.Haskell.Utils where -import Hydra.All+import Hydra.Kernel import Hydra.Adapters.Coders import Hydra.Ext.Haskell.Language import qualified Hydra.Ext.Haskell.Ast as H
src/main/haskell/Hydra/Ext/Java/Coder.hs view
@@ -1,6 +1,6 @@ module Hydra.Ext.Java.Coder (printModule) where -import Hydra.All+import Hydra.Kernel import Hydra.CoreDecoding import Hydra.Reduction import Hydra.Ext.Java.Utils@@ -14,7 +14,7 @@ import Hydra.Ext.Java.Settings import Hydra.Adapters.UtilsEtc import Hydra.Types.Inference-import Hydra.Util.Context+import Hydra.Meta import qualified Control.Monad as CM import qualified Data.List as L
src/main/haskell/Hydra/Ext/Java/Language.hs view
@@ -1,6 +1,6 @@ module Hydra.Ext.Java.Language where -import Hydra.All+import Hydra.Kernel import qualified Data.Set as S
src/main/haskell/Hydra/Ext/Java/Utils.hs view
@@ -1,6 +1,6 @@ module Hydra.Ext.Java.Utils where -import Hydra.All+import Hydra.Kernel import qualified Hydra.Ext.Java.Syntax as Java import qualified Hydra.Lib.Strings as Strings import Hydra.Adapters.Coders
src/main/haskell/Hydra/Ext/Json/Coder.hs view
@@ -1,6 +1,6 @@ module Hydra.Ext.Json.Coder (jsonCoder) where -import Hydra.All+import Hydra.Kernel import Hydra.Adapters.Term import qualified Hydra.Impl.Haskell.Dsl.Terms as Terms import qualified Hydra.Impl.Haskell.Dsl.Types as Types
src/main/haskell/Hydra/Ext/Json/Eliminate.hs view
@@ -1,6 +1,6 @@ module Hydra.Ext.Json.Eliminate where -import Hydra.All+import Hydra.Kernel import qualified Hydra.Ext.Json.Model as Json import qualified Data.Map as M
src/main/haskell/Hydra/Ext/Json/Language.hs view
@@ -1,6 +1,6 @@ module Hydra.Ext.Json.Language where -import Hydra.All+import Hydra.Kernel import qualified Data.Set as S
src/main/haskell/Hydra/Ext/Pegasus/Coder.hs view
@@ -1,6 +1,6 @@ module Hydra.Ext.Pegasus.Coder (printModule) where -import Hydra.All+import Hydra.Kernel import Hydra.CoreDecoding import Hydra.Adapters.Term import Hydra.Adapters.Coders
src/main/haskell/Hydra/Ext/Pegasus/Language.hs view
@@ -1,6 +1,6 @@ module Hydra.Ext.Pegasus.Language where -import Hydra.All+import Hydra.Kernel import qualified Data.Set as S
src/main/haskell/Hydra/Ext/Scala/Coder.hs view
@@ -1,6 +1,6 @@ module Hydra.Ext.Scala.Coder (printModule) where -import Hydra.All+import Hydra.Kernel import Hydra.CoreDecoding import Hydra.Impl.Haskell.Dsl.Terms import qualified Hydra.Impl.Haskell.Dsl.Types as Types@@ -47,7 +47,7 @@ toPrimImport (Namespace ns) = Scala.StatImportExport $ Scala.ImportExportStatImport $ Scala.Import [ Scala.Importer (Scala.Data_RefName $ toScalaName ns) []] toScalaName name = Scala.Data_Name $ Scala.PredefString $ L.intercalate "." $ Strings.splitOn "/" name- toDef (el, TypedTerm typ term) = do+ toDef (el, TypedTerm typ term) = withTrace ("element " ++ unName (elementName el)) $ do let coder = Y.fromJust $ M.lookup typ coders rhs <- coderEncode coder term Scala.StatDefn <$> case rhs of@@ -173,18 +173,13 @@ TermOptional m -> case m of Nothing -> pure $ sname "None" Just t -> (\s -> sapply (sname "Some") [s]) <$> encodeTerm t- TermRecord (Record n fields) -> do- sn <- schemaName- case sn of- Nothing -> fail $ "unexpected anonymous record: " ++ show term- Just name -> do- let n = scalaTypeName False name- args <- CM.mapM encodeTerm (fieldTerm <$> fields)- return $ sapply (sname n) args+ TermRecord (Record name fields) -> do+ let n = scalaTypeName False name+ args <- CM.mapM encodeTerm (fieldTerm <$> fields)+ return $ sapply (sname n) args TermSet s -> sapply (sname "Set") <$> CM.mapM encodeTerm (S.toList s)- TermUnion (Union n (Field fn ft)) -> do- sn <- schemaName- let lhs = sname $ qualifyUnionFieldName "UNION." sn fn+ TermUnion (Union sn (Field fn ft)) -> do+ let lhs = sname $ qualifyUnionFieldName "UNION." (Just sn) fn args <- case stripTerm ft of TermRecord (Record _ []) -> pure [] _ -> do@@ -193,11 +188,7 @@ return $ sapply lhs args TermVariable (Variable v) -> pure $ sname v _ -> fail $ "unexpected term: " ++ show term- where- schemaName = do- cx <- getState- r <- annotationClassTermType (contextAnnotations cx) term- pure $ r >>= nameOfType cx+ encodeType :: Show m => Type m -> GraphFlow m Scala.Type encodeType t = case stripType t of
src/main/haskell/Hydra/Ext/Scala/Language.hs view
@@ -1,6 +1,6 @@ module Hydra.Ext.Scala.Language where -import Hydra.All+import Hydra.Kernel import qualified Data.Set as S
src/main/haskell/Hydra/Ext/Scala/Prepare.hs view
@@ -2,7 +2,7 @@ prepareType, ) where -import Hydra.All+import Hydra.Kernel import qualified Hydra.Impl.Haskell.Dsl.Types as Types import qualified Data.Set as S
src/main/haskell/Hydra/Ext/Scala/Utils.hs view
@@ -1,6 +1,6 @@ module Hydra.Ext.Scala.Utils where -import Hydra.All+import Hydra.Kernel import qualified Hydra.Ext.Scala.Meta as Scala import qualified Hydra.Lib.Strings as Strings import Hydra.Ext.Scala.Language
src/main/haskell/Hydra/Ext/Shacl/Coder.hs view
@@ -1,8 +1,8 @@ module Hydra.Ext.Shacl.Coder where -import Hydra.All+import Hydra.Kernel import Hydra.CoreDecoding-import Hydra.Util.Context+import Hydra.Meta import qualified Hydra.Ext.Rdf.Syntax as Rdf import qualified Hydra.Ext.Shacl.Model as Shacl import qualified Hydra.Impl.Haskell.Dsl.Literals as Literals
src/main/haskell/Hydra/Ext/Shacl/Language.hs view
@@ -1,6 +1,6 @@ module Hydra.Ext.Shacl.Language where -import Hydra.All+import Hydra.Kernel import qualified Data.Set as S
src/main/haskell/Hydra/Ext/Tinkerpop/Language.hs view
@@ -1,6 +1,6 @@ module Hydra.Ext.Tinkerpop.Language where -import Hydra.All+import Hydra.Kernel import Hydra.Ext.Tinkerpop.Features import qualified Data.Set as S
src/main/haskell/Hydra/Ext/Yaml/Coder.hs view
@@ -1,6 +1,6 @@ module Hydra.Ext.Yaml.Coder (yamlCoder) where -import Hydra.All+import Hydra.Kernel import Hydra.Adapters.Term import qualified Hydra.Impl.Haskell.Dsl.Terms as Terms import Hydra.Ext.Yaml.Language
src/main/haskell/Hydra/Ext/Yaml/Language.hs view
@@ -1,6 +1,6 @@ module Hydra.Ext.Yaml.Language where -import Hydra.All+import Hydra.Kernel import qualified Data.Set as S
src/main/haskell/Hydra/Ext/Yaml/Modules.hs view
@@ -1,6 +1,6 @@ module Hydra.Ext.Yaml.Modules (printModule) where -import Hydra.All+import Hydra.Kernel import Hydra.Adapters.Coders import Hydra.Impl.Haskell.Ext.Yaml.Serde import Hydra.Ext.Yaml.Coder
+ src/main/haskell/Hydra/Impl/Haskell/Codegen.hs view
@@ -0,0 +1,173 @@+-- | Entry point for Hydra code generation utilities++module Hydra.Impl.Haskell.Codegen where++import Hydra.Kernel+import Hydra.Impl.Haskell.Dsl.Standard+import Hydra.CoreEncoding+import Hydra.Types.Inference++import qualified Hydra.Ext.Haskell.Coder as Haskell+import qualified Hydra.Ext.Java.Coder as Java+import qualified Hydra.Ext.Pegasus.Coder as PDL+import qualified Hydra.Ext.Scala.Coder as Scala+import qualified Hydra.Ext.Yaml.Modules as Yaml++import Hydra.Impl.Haskell.Sources.Adapters.Utils+import Hydra.Impl.Haskell.Sources.Basics+import Hydra.Impl.Haskell.Sources.Core+import Hydra.Impl.Haskell.Sources.Compute+import Hydra.Impl.Haskell.Sources.Grammar+import Hydra.Impl.Haskell.Sources.Libraries+import Hydra.Impl.Haskell.Sources.Mantle+import Hydra.Impl.Haskell.Sources.Module+import Hydra.Impl.Haskell.Sources.Phantoms++import Hydra.Impl.Haskell.Sources.Util.Codetree.Ast+import Hydra.Impl.Haskell.Sources.Ext.Avro.Schema+import Hydra.Impl.Haskell.Sources.Ext.Graphql.Syntax+import Hydra.Impl.Haskell.Sources.Ext.Haskell.Ast+import Hydra.Impl.Haskell.Sources.Ext.Java.Syntax+import Hydra.Impl.Haskell.Sources.Ext.Json.Model+import Hydra.Impl.Haskell.Sources.Ext.Pegasus.Pdl+import Hydra.Impl.Haskell.Sources.Ext.Owl.Syntax+import Hydra.Impl.Haskell.Sources.Ext.Scala.Meta+import Hydra.Impl.Haskell.Sources.Ext.Tinkerpop.Features+import Hydra.Impl.Haskell.Sources.Ext.Tinkerpop.Typed+import Hydra.Impl.Haskell.Sources.Ext.Tinkerpop.V3+import Hydra.Impl.Haskell.Sources.Ext.Xml.Schema+import Hydra.Impl.Haskell.Sources.Ext.Yaml.Model+import Hydra.Impl.Haskell.Sources.Ext.Rdf.Syntax+import Hydra.Impl.Haskell.Sources.Ext.Shacl.Model+import Hydra.Impl.Haskell.Sources.Ext.Shex.Syntax++import qualified Control.Monad as CM+import qualified System.FilePath as FP+import qualified Data.List as L+import qualified Data.Map as M+import qualified System.Directory as SD+import qualified Data.Maybe as Y+++addDeepTypeAnnotations :: (Ord m, Show m) => Module m -> GraphFlow m (Module m)+addDeepTypeAnnotations mod = do+ els <- CM.mapM annotateElementWithTypes $ moduleElements mod+ return $ mod {moduleElements = els}++allModules :: [Module Meta]+allModules = coreModules ++ utilModules ++ extModules++assignSchemas :: (Ord m, Show m) => Bool -> Module m -> GraphFlow m (Module m)+assignSchemas doInfer mod = do+ cx <- getState+ els <- CM.mapM (annotate cx) $ moduleElements mod+ return $ mod {moduleElements = els}+ where+ annotate cx el = do+ typ <- findType cx (elementData el)+ case typ of+ Nothing -> if doInfer+ then do+ t <- typeSchemeType . snd <$> inferType (elementData el)+ return el {elementSchema = encodeType t}+ else return el+ Just typ -> return el {elementSchema = encodeType typ}++coreModules :: [Module Meta]+coreModules = [+ codetreeAstModule,+ haskellAstModule,+ hydraCoreModule,+ hydraComputeModule,+ hydraMantleModule,+ hydraModuleModule,+ hydraGrammarModule,+-- hydraMonadsModule,+ hydraPhantomsModule,+ jsonModelModule]++utilModules = [+ adapterUtilsModule,+ hydraBasicsModule]++extModules :: [Module Meta]+extModules = [+ avroSchemaModule,+ graphqlSyntaxModule,+ javaSyntaxModule,+ pegasusPdlModule,+ owlSyntaxModule,+ rdfSyntaxModule,+ scalaMetaModule,+ shaclModelModule,+ shexSyntaxModule,+ tinkerpopFeaturesModule,+ tinkerpopTypedModule,+ tinkerpopV3Module,+ xmlSchemaModule,+ yamlModelModule]++findType :: Context m -> Term m -> GraphFlow m (Maybe (Type m))+findType cx term = annotationClassTermType (contextAnnotations cx) term++generateSources :: (Module Meta -> GraphFlow Meta (M.Map FilePath String)) -> [Module Meta] -> FilePath -> IO ()+generateSources printModule mods0 basePath = do+ mfiles <- runFlow kernelContext generateFiles+ case mfiles of+ Nothing -> fail "Transformation failed"+ Just files -> mapM_ writePair files+ where+ generateFiles = do+ withTrace "generate files" $ do+ mods1 <- CM.mapM (assignSchemas False) mods0+ withState (modulesToContext mods1) $ do+ mods2 <- CM.mapM addDeepTypeAnnotations mods1+ maps <- CM.mapM printModule mods2+ return $ L.concat (M.toList <$> maps)++ writePair (path, s) = do+ let fullPath = FP.combine basePath path+ SD.createDirectoryIfMissing True $ FP.takeDirectory fullPath+ writeFile fullPath s++hydraKernel :: Graph Meta+hydraKernel = elementsToGraph Nothing $ L.concat (moduleElements <$> [hydraCoreModule, hydraMantleModule, hydraModuleModule])++kernelContext = graphContext hydraKernel++modulesToContext :: [Module Meta] -> Context Meta+modulesToContext mods = kernelContext {contextGraph = elementsToGraph (Just hydraKernel) elements}+ where+ elements = L.concat (moduleElements <$> allModules)+ allModules = L.concat (close <$> mods)+ where+ close mod = mod:(L.concat (close <$> moduleDependencies mod))++printTrace :: Bool -> Trace -> IO ()+printTrace isError t = do+ if not (L.null $ traceMessages t)+ then do+ putStrLn $ if isError then "Flow failed. Messages:" else "Messages:"+ putStrLn $ indentLines $ traceSummary t+ else pure ()++runFlow :: s -> Flow s a -> IO (Maybe a)+runFlow cx f = do+ let FlowState v _ t = unFlow f cx emptyTrace+ printTrace (Y.isNothing v) t+ return v++writeHaskell :: [Module Meta] -> FilePath -> IO ()+writeHaskell = generateSources Haskell.printModule++writeJava :: [Module Meta] -> FP.FilePath -> IO ()+writeJava = generateSources Java.printModule++writePdl :: [Module Meta] -> FP.FilePath -> IO ()+writePdl = generateSources PDL.printModule++writeScala :: [Module Meta] -> FP.FilePath -> IO ()+writeScala = generateSources Scala.printModule++writeYaml :: [Module Meta] -> FP.FilePath -> IO ()+writeYaml = generateSources Yaml.printModule
src/main/haskell/Hydra/Impl/Haskell/Dsl/Base.hs view
@@ -1,10 +1,12 @@+-- | Base DSL which makes use of phantom types. Use this DSL for defining programs as opposed to data type definitions.+ module Hydra.Impl.Haskell.Dsl.Base ( module Hydra.Impl.Haskell.Dsl.Base, module Hydra.Impl.Haskell.Dsl.PhantomLiterals, Standard.coreContext, ) where -import Hydra.All+import Hydra.Kernel import Hydra.Meta import Hydra.CoreEncoding import Hydra.Impl.Haskell.Dsl.PhantomLiterals
src/main/haskell/Hydra/Impl/Haskell/Dsl/Bootstrap.hs view
@@ -1,6 +1,8 @@+-- | A bootstrapping DSL, used for Hydra's inner core models+ module Hydra.Impl.Haskell.Dsl.Bootstrap where -import Hydra.All+import Hydra.Kernel import Hydra.Meta import Hydra.CoreEncoding import qualified Hydra.Impl.Haskell.Dsl.Types as Types
src/main/haskell/Hydra/Impl/Haskell/Dsl/Grammars.hs view
@@ -1,6 +1,8 @@+-- | A DSL for building BNF grammars+ module Hydra.Impl.Haskell.Dsl.Grammars where -import Hydra.All+import Hydra.Kernel import Data.String(IsString(..))
src/main/haskell/Hydra/Impl/Haskell/Dsl/Literals.hs view
@@ -1,6 +1,8 @@+-- | A DSL for constructing literal types and terms+ module Hydra.Impl.Haskell.Dsl.Literals where -import Hydra.All+import Hydra.Kernel import Data.Int
src/main/haskell/Hydra/Impl/Haskell/Dsl/PhantomLiterals.hs view
@@ -1,6 +1,8 @@+-- | A DSL for constructing literal terms using Haskell's built-in datatypes+ module Hydra.Impl.Haskell.Dsl.PhantomLiterals where -import Hydra.All+import Hydra.Kernel import qualified Hydra.Impl.Haskell.Dsl.Terms as Terms import Data.Int
src/main/haskell/Hydra/Impl/Haskell/Dsl/Prims.hs view
@@ -1,6 +1,8 @@+-- | A DSL for constructing primitive function definitions+ module Hydra.Impl.Haskell.Dsl.Prims where -import Hydra.All+import Hydra.Kernel import qualified Hydra.Impl.Haskell.Dsl.Terms as Terms import qualified Hydra.Impl.Haskell.Dsl.Types as Types
src/main/haskell/Hydra/Impl/Haskell/Dsl/Standard.hs view
@@ -1,9 +1,11 @@+-- | A DSL which is used as a basis for some of the other DSLs+ module Hydra.Impl.Haskell.Dsl.Standard ( module Hydra.Impl.Haskell.Dsl.Standard, module Hydra.Impl.Haskell.Dsl.Bootstrap ) where -import Hydra.All+import Hydra.Kernel import Hydra.Meta import Hydra.Impl.Haskell.Dsl.Terms as Terms import qualified Hydra.Impl.Haskell.Dsl.Types as Types
src/main/haskell/Hydra/Impl/Haskell/Dsl/Terms.hs view
@@ -1,6 +1,8 @@+-- | A DSL for constructing Hydra terms+ module Hydra.Impl.Haskell.Dsl.Terms where -import Hydra.All+import Hydra.Kernel import qualified Hydra.Impl.Haskell.Dsl.Literals as Literals import Prelude hiding (map)
src/main/haskell/Hydra/Impl/Haskell/Dsl/Types.hs view
@@ -1,6 +1,8 @@+-- | A DSL for constructing Hydra types+ module Hydra.Impl.Haskell.Dsl.Types where -import Hydra.All+import Hydra.Kernel import qualified Data.List as L import qualified Data.Map as M
src/main/haskell/Hydra/Impl/Haskell/Ext/Json/Serde.hs view
@@ -1,6 +1,6 @@ module Hydra.Impl.Haskell.Ext.Json.Serde where -import Hydra.All+import Hydra.Kernel import Hydra.Ext.Json.Coder import qualified Hydra.Ext.Json.Model as Json import Hydra.Impl.Haskell.Ext.Bytestrings
src/main/haskell/Hydra/Impl/Haskell/Ext/Yaml/Serde.hs view
@@ -1,6 +1,6 @@ module Hydra.Impl.Haskell.Ext.Yaml.Serde where -import Hydra.All+import Hydra.Kernel import Hydra.Ext.Yaml.Coder import qualified Hydra.Ext.Yaml.Model as YM import Hydra.Impl.Haskell.Ext.Bytestrings
− src/main/haskell/Hydra/Impl/Haskell/GraphIO.hs
@@ -1,169 +0,0 @@-module Hydra.Impl.Haskell.GraphIO where--import Hydra.All-import Hydra.Impl.Haskell.Dsl.Standard-import Hydra.CoreEncoding-import Hydra.Types.Inference--import qualified Hydra.Ext.Haskell.Coder as Haskell-import qualified Hydra.Ext.Java.Coder as Java-import qualified Hydra.Ext.Pegasus.Coder as PDL-import qualified Hydra.Ext.Scala.Coder as Scala-import qualified Hydra.Ext.Yaml.Modules as Yaml--import Hydra.Impl.Haskell.Sources.Adapters.Utils-import Hydra.Impl.Haskell.Sources.Basics-import Hydra.Impl.Haskell.Sources.Core-import Hydra.Impl.Haskell.Sources.Compute-import Hydra.Impl.Haskell.Sources.Grammar-import Hydra.Impl.Haskell.Sources.Libraries-import Hydra.Impl.Haskell.Sources.Mantle-import Hydra.Impl.Haskell.Sources.Module-import Hydra.Impl.Haskell.Sources.Phantoms--import Hydra.Impl.Haskell.Sources.Util.Codetree.Ast-import Hydra.Impl.Haskell.Sources.Ext.Avro.Schema-import Hydra.Impl.Haskell.Sources.Ext.Graphql.Syntax-import Hydra.Impl.Haskell.Sources.Ext.Haskell.Ast-import Hydra.Impl.Haskell.Sources.Ext.Java.Syntax-import Hydra.Impl.Haskell.Sources.Ext.Json.Model-import Hydra.Impl.Haskell.Sources.Ext.Pegasus.Pdl-import Hydra.Impl.Haskell.Sources.Ext.Owl.Syntax-import Hydra.Impl.Haskell.Sources.Ext.Scala.Meta-import Hydra.Impl.Haskell.Sources.Ext.Tinkerpop.Features-import Hydra.Impl.Haskell.Sources.Ext.Tinkerpop.Typed-import Hydra.Impl.Haskell.Sources.Ext.Tinkerpop.V3-import Hydra.Impl.Haskell.Sources.Ext.Xml.Schema-import Hydra.Impl.Haskell.Sources.Ext.Yaml.Model-import Hydra.Impl.Haskell.Sources.Ext.Rdf.Syntax-import Hydra.Impl.Haskell.Sources.Ext.Shacl.Model-import Hydra.Impl.Haskell.Sources.Ext.Shex.Syntax--import qualified Control.Monad as CM-import qualified System.FilePath as FP-import qualified Data.List as L-import qualified Data.Map as M-import qualified System.Directory as SD-import qualified Data.Maybe as Y---addDeepTypeAnnotations :: (Ord m, Show m) => Module m -> GraphFlow m (Module m)-addDeepTypeAnnotations mod = do- els <- CM.mapM annotateElementWithTypes $ moduleElements mod- return $ mod {moduleElements = els}--allModules :: [Module Meta]-allModules = coreModules ++ extModules--assignSchemas :: (Ord m, Show m) => Bool -> Module m -> GraphFlow m (Module m)-assignSchemas doInfer mod = do- cx <- getState- els <- CM.mapM (annotate cx) $ moduleElements mod- return $ mod {moduleElements = els}- where- annotate cx el = do- typ <- findType cx (elementData el)- case typ of- Nothing -> if doInfer- then do- t <- typeSchemeType . snd <$> inferType (elementData el)- return el {elementSchema = encodeType t}- else return el- Just typ -> return el {elementSchema = encodeType typ}--coreModules :: [Module Meta]-coreModules = [- adapterUtilsModule,- codetreeAstModule,- haskellAstModule,- hydraBasicsModule,- hydraCoreModule,- hydraComputeModule,- hydraMantleModule,- hydraModuleModule,- hydraGrammarModule,--- hydraMonadsModule,- hydraPhantomsModule,- jsonModelModule]--extModules :: [Module Meta]-extModules = [- avroSchemaModule,- graphqlSyntaxModule,- javaSyntaxModule,- pegasusPdlModule,- owlSyntaxModule,- rdfSyntaxModule,- scalaMetaModule,- shaclModelModule,- shexSyntaxModule,- tinkerpopFeaturesModule,- tinkerpopTypedModule,- tinkerpopV3Module,- xmlSchemaModule,- yamlModelModule]--findType :: Context m -> Term m -> GraphFlow m (Maybe (Type m))-findType cx term = annotationClassTermType (contextAnnotations cx) term--generateSources :: (Module Meta -> GraphFlow Meta (M.Map FilePath String)) -> [Module Meta] -> FilePath -> IO ()-generateSources printModule mods0 basePath = do- mfiles <- runFlow kernelContext generateFiles- case mfiles of- Nothing -> fail "Transformation failed"- Just files -> mapM_ writePair files- where- generateFiles = do- withTrace "generate files" $ do- mods1 <- CM.mapM (assignSchemas False) mods0- withState (modulesToContext mods1) $ do- mods2 <- CM.mapM addDeepTypeAnnotations mods1- maps <- CM.mapM printModule mods2- return $ L.concat (M.toList <$> maps)-- writePair (path, s) = do- let fullPath = FP.combine basePath path- SD.createDirectoryIfMissing True $ FP.takeDirectory fullPath- writeFile fullPath s--hydraKernel :: Graph Meta-hydraKernel = elementsToGraph Nothing $ L.concat (moduleElements <$> [hydraCoreModule, hydraMantleModule, hydraModuleModule])--kernelContext = graphContext hydraKernel--modulesToContext :: [Module Meta] -> Context Meta-modulesToContext mods = kernelContext {contextGraph = elementsToGraph (Just hydraKernel) elements}- where- elements = L.concat (moduleElements <$> allModules)- allModules = L.concat (close <$> mods)- where- close mod = mod:(L.concat (close <$> moduleDependencies mod))--printTrace :: Bool -> Trace -> IO ()-printTrace isError t = do- if not (L.null $ traceMessages t)- then do- putStrLn $ if isError then "Flow failed. Messages:" else "Messages:"- putStrLn $ indentLines $ traceSummary t- else pure ()--runFlow :: s -> Flow s a -> IO (Maybe a)-runFlow cx f = do- let FlowState v _ t = unFlow f cx emptyTrace- printTrace (Y.isNothing v) t- return v--writeHaskell :: [Module Meta] -> FilePath -> IO ()-writeHaskell = generateSources Haskell.printModule--writeJava :: [Module Meta] -> FP.FilePath -> IO ()-writeJava = generateSources Java.printModule--writePdl :: [Module Meta] -> FP.FilePath -> IO ()-writePdl = generateSources PDL.printModule--writeScala :: [Module Meta] -> FP.FilePath -> IO ()-writeScala = generateSources Scala.printModule--writeYaml :: [Module Meta] -> FP.FilePath -> IO ()-writeYaml = generateSources Yaml.printModule
src/main/haskell/Hydra/Impl/Haskell/Sources/Adapters/Utils.hs view
@@ -1,6 +1,6 @@ module Hydra.Impl.Haskell.Sources.Adapters.Utils where -import Hydra.All+import Hydra.Kernel import qualified Hydra.Impl.Haskell.Dsl.Types as Types import Hydra.Impl.Haskell.Sources.Basics import qualified Hydra.Impl.Haskell.Dsl.Standard as Standard
src/main/haskell/Hydra/Impl/Haskell/Sources/Basics.hs view
@@ -1,6 +1,6 @@ module Hydra.Impl.Haskell.Sources.Basics where -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Dsl.Base as Base import Hydra.Impl.Haskell.Sources.Module import Hydra.Impl.Haskell.Sources.Mantle
src/main/haskell/Hydra/Impl/Haskell/Sources/Compute.hs view
@@ -2,7 +2,7 @@ module Hydra.Impl.Haskell.Sources.Compute where -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Dsl.Types as Types import Hydra.Impl.Haskell.Dsl.Standard import Hydra.Impl.Haskell.Sources.Core@@ -22,6 +22,7 @@ elements = [ def "Adapter" $+ doc "A two-level bidirectional encoder which adapts types to types and terms to terms" $ lambda "s1" $ lambda "s2" $ lambda "t1" $ lambda "t2" $ lambda "v1" $ lambda "v2" $ record [ "isLossy">: boolean, "source">: variable "t1",@@ -29,6 +30,7 @@ "coder">: compute "Coder" @@ "s1" @@ "s2" @@ "v1" @@ "v2"], def "AdapterContext" $+ doc "An evaluation context together with a source language and a target language" $ lambda "m" $ record [ "evaluation">: apply (compute "Context") (variable "m"), "source">: apply (compute "Language") (variable "m"),@@ -94,17 +96,20 @@ function "s" (compute "Trace" --> compute "FlowState" @@ "s" @@ "a"), def "FlowState" $+ doc "The result of evaluating a Flow" $ lambda "s" $ lambda "a" $ record [ "value">: optional "a", "state">: "s", "trace">: compute "Trace"], def "Language" $+ doc "A named language together with language-specific constraints" $ lambda "m" $ record [ "name">: compute "LanguageName", "constraints">: apply (compute "LanguageConstraints") (variable "m")], def "LanguageConstraints" $+ doc "A set of constraints on valid type and term expressions, characterizing a language" $ lambda "m" $ record [ "eliminationVariants">: Types.set $ mantle "EliminationVariant", "literalVariants">: Types.set $ mantle "LiteralVariant",@@ -115,7 +120,8 @@ "typeVariants">: Types.set $ mantle "TypeVariant", "types">: core "Type" @@ "m" --> boolean], - def "LanguageName" string,+ def "LanguageName" $+ doc "The unique name of a language" string, def "Meta" $ doc "A built-in metadata container for terms" $@@ -148,6 +154,7 @@ Types.map string (core "Term" @@ compute "Meta")], def "TraversalOrder" $+ doc "Specifies either a pre-order or post-order traversal" $ union [ "pre">: doc "Pre-order traversal" unit, "post">: doc "Post-order traversal" unit]]
src/main/haskell/Hydra/Impl/Haskell/Sources/Core.hs view
@@ -2,7 +2,7 @@ module Hydra.Impl.Haskell.Sources.Core where -import Hydra.All+import Hydra.Kernel import Hydra.Meta import Hydra.Impl.Haskell.Dsl.Types as Types import Hydra.Impl.Haskell.Dsl.Bootstrap@@ -23,8 +23,8 @@ elements = [ def "Annotated" $- lambda "a" $- lambda "m" $ record [+ doc "An object, such as a type or term, together with an annotation" $+ lambda "a" $ lambda "m" $ record [ "subject">: "a", "annotation">: "m"], @@ -49,6 +49,7 @@ core "Type" @@ "m"], def "CaseStatement" $+ doc "A union elimination; a case statement" $ lambda "m" $ record [ "typeName">: core "Name", "cases">: list $ core "Field" @@ "m"],@@ -82,7 +83,7 @@ "term">: core "Term" @@ "m"], def "FieldName" $- doc "The name of a field"+ doc "The name of a field, unique within a record or union type" string, def "FieldType" $@@ -243,6 +244,7 @@ core "Term" @@ "m"], def "Projection" $+ doc "A record elimination; a projection" $ record [ "typeName">: core "Name", "field">: core "FieldName"],@@ -371,4 +373,6 @@ "typeName">: core "Name", "field">: core "Field" @@ "m"], - def "UnitType" $ record []]+ def "UnitType" $+ doc "An empty record type as a canonical unit type" $+ record []]
src/main/haskell/Hydra/Impl/Haskell/Sources/CoreLang.hs view
@@ -2,7 +2,7 @@ module Hydra.Impl.Haskell.Sources.CoreLang where -import Hydra.All+import Hydra.Kernel import Hydra.Compute import Hydra.Impl.Haskell.Dsl.Base as Base import qualified Hydra.Impl.Haskell.Dsl.Terms as Terms
src/main/haskell/Hydra/Impl/Haskell/Sources/Ext/Avro/Schema.hs view
@@ -2,7 +2,7 @@ module Hydra.Impl.Haskell.Sources.Ext.Avro.Schema where -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Dsl.Types as Types import Hydra.Impl.Haskell.Dsl.Standard import Hydra.Impl.Haskell.Sources.Core
src/main/haskell/Hydra/Impl/Haskell/Sources/Ext/Graphql/Syntax.hs view
@@ -2,7 +2,7 @@ module Hydra.Impl.Haskell.Sources.Ext.Graphql.Syntax where -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Dsl.Grammars import Hydra.Util.GrammarToModule import qualified Hydra.Impl.Haskell.Dsl.Standard as Standard
src/main/haskell/Hydra/Impl/Haskell/Sources/Ext/Haskell/Ast.hs view
@@ -2,7 +2,7 @@ import Hydra.Impl.Haskell.Sources.Core -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Dsl.Types as Types import Hydra.Impl.Haskell.Dsl.Standard
src/main/haskell/Hydra/Impl/Haskell/Sources/Ext/Java/Syntax.hs view
@@ -2,7 +2,7 @@ import Hydra.Impl.Haskell.Sources.Core -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Dsl.Types as Types import Hydra.Impl.Haskell.Dsl.Standard
src/main/haskell/Hydra/Impl/Haskell/Sources/Ext/Json/Model.hs view
@@ -2,7 +2,7 @@ import Hydra.Impl.Haskell.Sources.Core -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Dsl.Types as Types import Hydra.Impl.Haskell.Dsl.Standard
src/main/haskell/Hydra/Impl/Haskell/Sources/Ext/Owl/Syntax.hs view
@@ -2,7 +2,7 @@ import Hydra.Impl.Haskell.Sources.Core -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Dsl.Types as Types import qualified Hydra.Impl.Haskell.Dsl.Terms as Terms import Hydra.Impl.Haskell.Dsl.Standard
src/main/haskell/Hydra/Impl/Haskell/Sources/Ext/Pegasus/Pdl.hs view
@@ -3,7 +3,7 @@ import Hydra.Impl.Haskell.Sources.Core import Hydra.Impl.Haskell.Sources.Ext.Json.Model -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Dsl.Types as Types import Hydra.Impl.Haskell.Dsl.Standard
src/main/haskell/Hydra/Impl/Haskell/Sources/Ext/Rdf/Syntax.hs view
@@ -2,7 +2,7 @@ import Hydra.Impl.Haskell.Sources.Core -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Dsl.Types as Types import Hydra.Impl.Haskell.Dsl.Standard
src/main/haskell/Hydra/Impl/Haskell/Sources/Ext/Scala/Meta.hs view
@@ -2,7 +2,7 @@ import Hydra.Impl.Haskell.Sources.Core -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Dsl.Types as Types import Hydra.Impl.Haskell.Dsl.Standard
src/main/haskell/Hydra/Impl/Haskell/Sources/Ext/Shacl/Model.hs view
@@ -4,7 +4,7 @@ import Hydra.Impl.Haskell.Sources.Core -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Dsl.Types as Types import Hydra.Impl.Haskell.Dsl.Standard import Hydra.Impl.Haskell.Sources.Ext.Rdf.Syntax
src/main/haskell/Hydra/Impl/Haskell/Sources/Ext/Tinkerpop/Features.hs view
@@ -4,7 +4,7 @@ import Hydra.Impl.Haskell.Sources.Core -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Dsl.Types as Types import Hydra.Impl.Haskell.Dsl.Standard
src/main/haskell/Hydra/Impl/Haskell/Sources/Ext/Tinkerpop/Typed.hs view
@@ -2,7 +2,7 @@ import Hydra.Impl.Haskell.Sources.Core -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Dsl.Types as Types import Hydra.Impl.Haskell.Dsl.Standard
src/main/haskell/Hydra/Impl/Haskell/Sources/Ext/Tinkerpop/V3.hs view
@@ -4,7 +4,7 @@ import Hydra.Impl.Haskell.Sources.Core -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Dsl.Types as Types import Hydra.Impl.Haskell.Dsl.Standard
src/main/haskell/Hydra/Impl/Haskell/Sources/Ext/Xml/Schema.hs view
@@ -2,7 +2,7 @@ import Hydra.Impl.Haskell.Sources.Core -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Dsl.Types as Types import Hydra.Impl.Haskell.Dsl.Standard
src/main/haskell/Hydra/Impl/Haskell/Sources/Ext/Yaml/Model.hs view
@@ -2,7 +2,7 @@ import Hydra.Impl.Haskell.Sources.Core -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Dsl.Types as Types import Hydra.Impl.Haskell.Dsl.Standard
src/main/haskell/Hydra/Impl/Haskell/Sources/Grammar.hs view
@@ -2,7 +2,7 @@ module Hydra.Impl.Haskell.Sources.Grammar where -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Dsl.Types as Types import Hydra.Impl.Haskell.Dsl.Standard import Hydra.Impl.Haskell.Sources.Core@@ -10,7 +10,7 @@ hydraGrammarModule :: Module Meta hydraGrammarModule = Module ns elements [] $- Just "A common API for BNF-based grammars"+ Just "A common API for BNF-based grammars, specifying context-free languages" where ns = Namespace "hydra/grammar" grammar = nsref ns@@ -18,33 +18,49 @@ elements = [ - def "Constant" string,+ def "Constant" $+ doc "A constant pattern"+ string, - def "Grammar" $ list $ grammar "Production",+ def "Grammar" $+ doc "An enhanced Backus-Naur form (BNF) grammar" $+ list $ grammar "Production", - def "Label" string,+ def "Label" $+ doc "A name for a pattern"+ string, - def "LabeledPattern" $ record [+ def "LabeledPattern" $+ doc "A pattern together with a name (label)" $+ record [ "label">: grammar "Label", "pattern">: grammar "Pattern"], - def "Pattern" $ union [- "nil">: unit,- "ignored">: grammar "Pattern",- "labeled">: grammar "LabeledPattern",- "constant">: grammar "Constant",- "regex">: grammar "Regex",- "nonterminal">: grammar "Symbol",- "sequence">: list $ grammar "Pattern",- "alternatives">: list $ grammar "Pattern",- "option">: grammar "Pattern",- "star">: grammar "Pattern",- "plus">: grammar "Pattern"],+ def "Pattern" $+ doc "A pattern which matches valid expressions in the language" $+ union [+ "nil">: unit,+ "ignored">: grammar "Pattern",+ "labeled">: grammar "LabeledPattern",+ "constant">: grammar "Constant",+ "regex">: grammar "Regex",+ "nonterminal">: grammar "Symbol",+ "sequence">: list $ grammar "Pattern",+ "alternatives">: list $ grammar "Pattern",+ "option">: grammar "Pattern",+ "star">: grammar "Pattern",+ "plus">: grammar "Pattern"], - def "Production" $ record [- "symbol">: grammar "Symbol",- "pattern">: grammar "Pattern"],+ def "Production" $+ doc "A BNF production" $+ record [+ "symbol">: grammar "Symbol",+ "pattern">: grammar "Pattern"], - def "Regex" string,+ def "Regex" $+ doc "A regular expression"+ string, - def "Symbol" string]+ def "Symbol" $+ doc "A nonterminal symbol"+ string]
src/main/haskell/Hydra/Impl/Haskell/Sources/Libraries.hs view
@@ -1,6 +1,6 @@ module Hydra.Impl.Haskell.Sources.Libraries where -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Dsl.Prims as Prims import qualified Hydra.Impl.Haskell.Dsl.Terms as Terms import qualified Hydra.Impl.Haskell.Dsl.Types as Types
src/main/haskell/Hydra/Impl/Haskell/Sources/Mantle.hs view
@@ -2,7 +2,7 @@ module Hydra.Impl.Haskell.Sources.Mantle where -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Dsl.Types as Types import Hydra.Impl.Haskell.Dsl.Standard import Hydra.Impl.Haskell.Sources.Core
src/main/haskell/Hydra/Impl/Haskell/Sources/Module.hs view
@@ -2,7 +2,7 @@ module Hydra.Impl.Haskell.Sources.Module where -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Dsl.Types as Types import Hydra.Impl.Haskell.Dsl.Standard import Hydra.Impl.Haskell.Sources.Mantle
src/main/haskell/Hydra/Impl/Haskell/Sources/Phantoms.hs view
@@ -2,7 +2,7 @@ module Hydra.Impl.Haskell.Sources.Phantoms where -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Dsl.Types as Types import Hydra.Impl.Haskell.Dsl.Standard import Hydra.Impl.Haskell.Sources.Core@@ -21,18 +21,23 @@ elements = [ def "Case" $+ doc "An association of a field name (as in a case statement) with a phantom type" $ lambda "a" $ core "FieldName", def "Datum" $+ doc "An association of a term with a phantom type" $ lambda "a" $ (core "Term") @@ (evaluation "Meta"), def "Definition" $+ doc "An association with a named term with a phantom type" $ lambda "a" $ record [ "name">: core "Name", "datum">: phantoms "Datum" @@ "a"], def "Fld" $+ doc "An association with a term-level field with a phantom type" $ lambda "a" $ (core "Field") @@ (evaluation "Meta"), def "Reference" $+ doc "A pure association with a phantom type" $ lambda "a" $ unit]
src/main/haskell/Hydra/Impl/Haskell/Sources/Util/Codetree/Ast.hs view
@@ -1,6 +1,6 @@ module Hydra.Impl.Haskell.Sources.Util.Codetree.Ast where -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Dsl.Types as Types import Hydra.Impl.Haskell.Dsl.Standard import Hydra.Impl.Haskell.Sources.Core
+ src/main/haskell/Hydra/Kernel.hs view
@@ -0,0 +1,50 @@+-- | A proxy for the Hydra kernel, i.e. the code which must be present in every Hydra implementation.+-- This currently includes most modules in the top-level Hydra.* namespace, as well as some Hydra.Util.* modules.+-- The adapter and inference frameworks, as well as Hydra.CoreDecoding, Hydra.CoreEncoding, Hydra.Meta, and Hydra.Reduction are logically part of the kernel,+-- but are excluded for now due to circular dependencies.++module Hydra.Kernel (+ module Hydra.Adapters.Utils,+ module Hydra.Basics,+ module Hydra.Common,+ module Hydra.Compute,+ module Hydra.Core,+-- module Hydra.CoreDecoding,+-- module Hydra.CoreEncoding,+ module Hydra.CoreLanguage,+ module Hydra.Grammar,+ module Hydra.Lexical,+ module Hydra.Mantle,+-- module Hydra.Meta,+ module Hydra.Module,+ module Hydra.Monads,+ module Hydra.Phantoms,+-- module Hydra.Reduction,+ module Hydra.Rewriting,+ module Hydra.Util.Debug,+ module Hydra.Util.Formatting,+-- module Hydra.Util.GrammarToModule,+ module Hydra.Util.Sorting,+) where++import Hydra.Adapters.Utils+import Hydra.Basics+import Hydra.Common+import Hydra.Compute+import Hydra.Core+--import Hydra.CoreDecoding+--import Hydra.CoreEncoding+import Hydra.CoreLanguage+import Hydra.Grammar+import Hydra.Lexical+import Hydra.Mantle+--import Hydra.Meta+import Hydra.Module+import Hydra.Monads+import Hydra.Phantoms+--import Hydra.Reduction+import Hydra.Rewriting+import Hydra.Util.Debug+import Hydra.Util.Formatting+--import Hydra.Util.GrammarToModule+import Hydra.Util.Sorting
src/main/haskell/Hydra/Lexical.hs view
@@ -1,3 +1,5 @@+-- | Functions for retrieving elements and primitive functions from a graph context+ module Hydra.Lexical ( module Hydra.Lexical, module Hydra.Common,
src/main/haskell/Hydra/Lib/Flows.hs view
@@ -1,6 +1,8 @@+-- | Haskell implementations of hydra/lib/flows primitives+ module Hydra.Lib.Flows where -import Hydra.All+import Hydra.Kernel apply :: Flow s (a -> b) -> Flow s a -> Flow s b
src/main/haskell/Hydra/Lib/Io.hs view
@@ -1,10 +1,12 @@+-- | Haskell implementations of hydra/lib/io primitives+ module Hydra.Lib.Io ( showTerm, showType, coreContext, ) where -import Hydra.All+import Hydra.Kernel import Hydra.Ext.Json.Coder import qualified Hydra.Ext.Json.Model as Json import Hydra.Impl.Haskell.Dsl.Standard
src/main/haskell/Hydra/Lib/Lists.hs view
@@ -1,3 +1,5 @@+-- | Haskell implementations of hydra/lib/lists primitives+ module Hydra.Lib.Lists where import qualified Data.List as L
src/main/haskell/Hydra/Lib/Literals.hs view
@@ -1,3 +1,5 @@+-- | Haskell implementations of hydra/lib/literals primitives+ module Hydra.Lib.Literals where
src/main/haskell/Hydra/Lib/Maps.hs view
@@ -1,3 +1,5 @@+-- | Haskell implementations of hydra/lib/maps primitives+ module Hydra.Lib.Maps where import qualified Data.Map as M
src/main/haskell/Hydra/Lib/Math.hs view
@@ -1,3 +1,5 @@+-- | Haskell implementations of hydra/lib/math primitives+ module Hydra.Lib.Math where
src/main/haskell/Hydra/Lib/Optionals.hs view
@@ -1,3 +1,5 @@+-- | Haskell implementations of hydra/lib/optionals primitives+ module Hydra.Lib.Optionals where import qualified Data.Maybe as Y
src/main/haskell/Hydra/Lib/Sets.hs view
@@ -1,3 +1,5 @@+-- | Haskell implementations of hydra/lib/sets primitives+ module Hydra.Lib.Sets where import qualified Data.Set as S
src/main/haskell/Hydra/Lib/Strings.hs view
@@ -1,3 +1,5 @@+-- | Haskell implementations of hydra/lib/strings primitives+ module Hydra.Lib.Strings where import qualified Data.Char as C
src/main/haskell/Hydra/Meta.hs view
@@ -1,3 +1,5 @@+-- | Functions for working with Meta, the default annotation type in Hydra+ module Hydra.Meta where import Hydra.Core@@ -7,7 +9,7 @@ import Hydra.Common import Hydra.Monads import Hydra.Mantle-import Hydra.Impl.Haskell.Dsl.Terms+import qualified Hydra.Impl.Haskell.Dsl.Terms as Terms import qualified Data.Map as M import qualified Data.Maybe as Y@@ -23,6 +25,14 @@ getAnnotation :: String -> Meta -> Maybe (Term Meta) getAnnotation key (Meta m) = M.lookup key m +getAttr :: String -> Flow s (Maybe (Term Meta))+getAttr key = Flow q+ where+ q s0 t0 = FlowState (Just $ M.lookup key $ traceOther t0) s0 t0++getAttrWithDefault :: String -> Term Meta -> Flow s (Term Meta)+getAttrWithDefault key def = Y.fromMaybe def <$> getAttr key+ getDescription :: Meta -> GraphFlow Meta (Y.Maybe String) getDescription meta = case getAnnotation metaDescription meta of Nothing -> pure Nothing@@ -74,11 +84,22 @@ metaType :: String metaType = "type" +nextCount :: String -> Flow s Int+nextCount attrName = do+ count <- getAttrWithDefault attrName (Terms.int32 0) >>= Terms.expectInt32+ putAttr attrName (Terms.int32 $ count + 1)+ return count++putAttr :: String -> Term Meta -> Flow s ()+putAttr key val = Flow q+ where+ q s0 t0 = FlowState (Just ()) s0 (t0 {traceOther = M.insert key val $ traceOther t0})+ setAnnotation :: String -> Y.Maybe (Term Meta) -> Meta -> Meta setAnnotation key val (Meta m) = Meta $ M.alter (const val) key m setDescription :: Y.Maybe String -> Meta -> Meta-setDescription d = setAnnotation metaDescription (string <$> d)+setDescription d = setAnnotation metaDescription (Terms.string <$> d) setTermAnnotation :: Context Meta -> String -> Y.Maybe (Term Meta) -> Term Meta -> Term Meta setTermAnnotation cx key val term = if meta == annotationClassDefault (contextAnnotations cx)@@ -89,7 +110,7 @@ meta = setAnnotation key val $ termMetaInternal term setTermDescription :: Context Meta -> Y.Maybe String -> Term Meta -> Term Meta-setTermDescription cx d = setTermAnnotation cx metaDescription (string <$> d)+setTermDescription cx d = setTermAnnotation cx metaDescription (Terms.string <$> d) setTermType :: Context Meta -> Y.Maybe (Type Meta) -> Term Meta -> Term Meta setTermType cx d = setTermAnnotation cx metaType (encodeType <$> d)@@ -106,7 +127,7 @@ meta = setAnnotation key val $ typeMetaInternal typ setTypeDescription :: Context Meta -> Y.Maybe String -> Type Meta -> Type Meta-setTypeDescription cx d = setTypeAnnotation cx metaDescription (string <$> d)+setTypeDescription cx d = setTypeAnnotation cx metaDescription (Terms.string <$> d) termMetaInternal :: Term Meta -> Meta termMetaInternal = aggregateAnnotations $ \t -> case t of
src/main/haskell/Hydra/Monads.hs view
@@ -1,3 +1,5 @@+-- | Functions and type class implementations for working with Hydra's built-in Flow monad+ module Hydra.Monads ( module Hydra.Common, module Hydra.Core,
src/main/haskell/Hydra/Reduction.hs view
@@ -1,3 +1,5 @@+-- | Functions for reducing terms and types, i.e. performing computations+ module Hydra.Reduction where import Hydra.Core@@ -8,7 +10,7 @@ import Hydra.Lexical import Hydra.Lexical import Hydra.CoreDecoding-import Hydra.Util.Context+import Hydra.Meta import qualified Control.Monad as CM import qualified Data.List as L
src/main/haskell/Hydra/Rewriting.hs view
@@ -1,3 +1,5 @@+-- | Functions for type and term rewriting+ module Hydra.Rewriting where import Hydra.Core@@ -5,9 +7,8 @@ import Hydra.Module import Hydra.Lexical import Hydra.Compute---import Hydra.CoreDecoding import Hydra.Mantle-import Hydra.Sorting+import Hydra.Util.Sorting import qualified Control.Monad as CM import qualified Data.List as L
− src/main/haskell/Hydra/Sorting.hs
@@ -1,17 +0,0 @@-module Hydra.Sorting where--import qualified Data.List as L-import qualified Data.Bifunctor as BF----- Note: requires a DAG (the ordering is incomplete in the presence of cycles).-topologicalSort :: Eq a => [(a, [a])] -> Maybe [a]-topologicalSort pairs = if L.length result < L.length pairs- then Nothing- else Just result- where- result = foldl makePrecede [] pairs- makePrecede ts (x, xs) = L.nub $- case L.elemIndex x ts of- Just i -> uncurry (++) $ BF.first (++ xs) $ splitAt i ts- _ -> ts ++ xs ++ [x]
src/main/haskell/Hydra/Types/Inference.hs view
@@ -1,3 +1,5 @@+-- | Entry point for Hydra's variation on Hindley-Milner type inference+ module Hydra.Types.Inference ( annotateElementWithTypes, annotateTermWithTypes,@@ -5,7 +7,7 @@ Constraint, ) where -import Hydra.All+import Hydra.Kernel import Hydra.CoreDecoding import Hydra.CoreEncoding import qualified Hydra.Impl.Haskell.Dsl.Types as Types@@ -282,18 +284,16 @@ inferFieldType :: (Ord m, Show m) => Field m -> Flow (InferenceContext m) (Field (m, Type m, [Constraint m])) inferFieldType (Field fname term) = Field fname <$> infer term --- | Solve for the toplevel type of an expression in a given environment+-- | Solve for the top-level type of an expression in a given environment inferType :: (Ord m, Show m) => Term m -> GraphFlow m (Term (m, Type m, [Constraint m]), TypeScheme m) inferType term = do withTrace ("infer type") $ do--- withTrace ("infer type of " ++ show term) $ do cx <- getState withState (startContext cx) $ do term1 <- infer term- withTrace ("original term (without annotations): " ++ show (removeTermAnnotations term) ++ " ### inferred term: " ++ show term1) $ do- subst <- withGraphContext $ withSchemaContext $ solveConstraints (termConstraints term1)- let term2 = rewriteDataType (substituteInType subst) term1- return (term2, closeOver $ termType term2)+ subst <- withGraphContext $ withSchemaContext $ solveConstraints (termConstraints term1)+ let term2 = rewriteDataType (substituteInType subst) term1+ return (term2, closeOver $ termType term2) where -- | Canonicalize and return the polymorphic toplevel type. closeOver = normalizeScheme . generalize M.empty . reduceType
src/main/haskell/Hydra/Types/Substitution.hs view
@@ -1,6 +1,8 @@+-- | Variable substitution and normalization of type expressions+ module Hydra.Types.Substitution where -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Dsl.Types as Types import qualified Data.List as L
src/main/haskell/Hydra/Types/Unification.hs view
@@ -1,9 +1,11 @@+-- | Hindley-Milner style type unification+ module Hydra.Types.Unification ( Constraint, solveConstraints, ) where -import Hydra.All+import Hydra.Kernel import Hydra.Types.Substitution import Hydra.Impl.Haskell.Dsl.Types as Types
src/main/haskell/Hydra/Util/Codetree/Script.hs view
@@ -1,3 +1,5 @@+-- | Utilities for constructing Hydra code trees+ module Hydra.Util.Codetree.Script where import Hydra.Util.Codetree.Ast
− src/main/haskell/Hydra/Util/Context.hs
@@ -1,27 +0,0 @@-module Hydra.Util.Context where--import Hydra.All-import qualified Hydra.Impl.Haskell.Dsl.Terms as Terms--import qualified Data.Map as M-import qualified Data.Maybe as Y---getAttr :: String -> Flow s (Maybe (Term Meta))-getAttr key = Flow q- where- q s0 t0 = FlowState (Just $ M.lookup key $ traceOther t0) s0 t0--getAttrWithDefault :: String -> Term Meta -> Flow s (Term Meta)-getAttrWithDefault key def = Y.fromMaybe def <$> getAttr key--nextCount :: String -> Flow s Int-nextCount attrName = do- count <- getAttrWithDefault attrName (Terms.int32 0) >>= Terms.expectInt32- putAttr attrName (Terms.int32 $ count + 1)- return count--putAttr :: String -> Term Meta -> Flow s ()-putAttr key val = Flow q- where- q s0 t0 = FlowState (Just ()) s0 (t0 {traceOther = M.insert key val $ traceOther t0})
src/main/haskell/Hydra/Util/Debug.hs view
@@ -1,3 +1,5 @@+-- | Debugging utilities+ module Hydra.Util.Debug where import Control.Exception
src/main/haskell/Hydra/Util/Formatting.hs view
@@ -1,3 +1,5 @@+-- | String formatting utilities+ module Hydra.Util.Formatting where import qualified Hydra.Lib.Strings as Strings
src/main/haskell/Hydra/Util/GrammarToModule.hs view
@@ -1,6 +1,8 @@+-- | A utility for converting a BNF grammar to a Hydra module+ module Hydra.Util.GrammarToModule where -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Dsl.Types as Types import Hydra.Impl.Haskell.Dsl.Terms as Terms import Hydra.Impl.Haskell.Dsl.Standard
+ src/main/haskell/Hydra/Util/Sorting.hs view
@@ -0,0 +1,20 @@+-- | Utilities for sorting++module Hydra.Util.Sorting where++import qualified Data.List as L+import qualified Data.Bifunctor as BF+++-- | Sort a directed acyclic graph (DAG) based on an adjacency list+-- Note: assumes that the input is in fact a DAG; the ordering is incomplete in the presence of cycles.+topologicalSort :: Eq a => [(a, [a])] -> Maybe [a]+topologicalSort pairs = if L.length result < L.length pairs+ then Nothing+ else Just result+ where+ result = foldl makePrecede [] pairs+ makePrecede ts (x, xs) = L.nub $+ case L.elemIndex x ts of+ Just i -> uncurry (++) $ BF.first (++ xs) $ splitAt i ts+ _ -> ts ++ xs ++ [x]
src/test/haskell/Hydra/Adapters/LiteralSpec.hs view
@@ -1,6 +1,6 @@ module Hydra.Adapters.LiteralSpec where -import Hydra.All+import Hydra.Kernel import Hydra.TestUtils
src/test/haskell/Hydra/Adapters/TermSpec.hs view
@@ -1,6 +1,6 @@ module Hydra.Adapters.TermSpec where -import Hydra.All+import Hydra.Kernel import Hydra.Adapters.Term import Hydra.Adapters.UtilsEtc import Hydra.Impl.Haskell.Dsl.Terms as Terms
src/test/haskell/Hydra/ArbitraryCore.hs view
@@ -1,6 +1,6 @@ module Hydra.ArbitraryCore where -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Dsl.Terms import qualified Hydra.Impl.Haskell.Dsl.Types as Types
src/test/haskell/Hydra/CommonSpec.hs view
@@ -1,6 +1,6 @@ module Hydra.CommonSpec where -import Hydra.All+import Hydra.Kernel import Hydra.TestUtils import qualified Hydra.Impl.Haskell.Dsl.Terms as Terms
src/test/haskell/Hydra/CoreCodersSpec.hs view
@@ -1,6 +1,6 @@ module Hydra.CoreCodersSpec where -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Dsl.Terms as Terms import Hydra.CoreDecoding import Hydra.CoreEncoding
src/test/haskell/Hydra/Ext/Json/CoderSpec.hs view
@@ -1,6 +1,6 @@ module Hydra.Ext.Json.CoderSpec where -import Hydra.All+import Hydra.Kernel import Hydra.Lib.Literals import qualified Hydra.Impl.Haskell.Dsl.Terms as Terms import Hydra.Ext.Json.Coder
src/test/haskell/Hydra/Ext/Yaml/CoderSpec.hs view
@@ -1,6 +1,6 @@ module Hydra.Ext.Yaml.CoderSpec where -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Dsl.Terms import Hydra.Ext.Yaml.Coder import qualified Hydra.Ext.Yaml.Model as YM
src/test/haskell/Hydra/Impl/Haskell/Dsl/TypesSpec.hs view
@@ -2,7 +2,7 @@ module Hydra.Impl.Haskell.Dsl.TypesSpec where -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Dsl.Types import qualified Test.Hspec as H
src/test/haskell/Hydra/Impl/Haskell/Ext/Json/SerdeSpec.hs view
@@ -3,7 +3,7 @@ module Hydra.Impl.Haskell.Ext.Json.SerdeSpec where -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Dsl.Terms import Hydra.Impl.Haskell.Ext.Json.Serde import qualified Hydra.Impl.Haskell.Dsl.Types as Types
src/test/haskell/Hydra/Impl/Haskell/Ext/Yaml/SerdeSpec.hs view
@@ -3,7 +3,7 @@ module Hydra.Impl.Haskell.Ext.Yaml.SerdeSpec where -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Dsl.Terms import Hydra.Impl.Haskell.Ext.Yaml.Serde import qualified Hydra.Impl.Haskell.Dsl.Types as Types
src/test/haskell/Hydra/MetaSpec.hs view
@@ -1,6 +1,6 @@ module Hydra.MetaSpec where -import Hydra.All+import Hydra.Kernel import qualified Hydra.Impl.Haskell.Dsl.Terms as Terms import Hydra.Meta import Hydra.TestUtils
src/test/haskell/Hydra/ReductionSpec.hs view
@@ -1,6 +1,6 @@ module Hydra.ReductionSpec where -import Hydra.All+import Hydra.Kernel import Hydra.Reduction import Hydra.Impl.Haskell.Dsl.Terms import qualified Hydra.Impl.Haskell.Dsl.Types as Types
src/test/haskell/Hydra/RewritingSpec.hs view
@@ -2,7 +2,7 @@ module Hydra.RewritingSpec where -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Dsl.Terms import Hydra.TestUtils
src/test/haskell/Hydra/TestData.hs view
@@ -1,6 +1,6 @@ module Hydra.TestData where -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Dsl.Terms import Hydra.TestGraph import qualified Hydra.Impl.Haskell.Dsl.Terms as Terms
src/test/haskell/Hydra/TestGraph.hs view
@@ -3,7 +3,7 @@ module Hydra.Impl.Haskell.Sources.Libraries, ) where -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Dsl.Standard as Standard import Hydra.Impl.Haskell.Sources.Core import Hydra.Impl.Haskell.Sources.Libraries
src/test/haskell/Hydra/TestUtils.hs view
@@ -15,7 +15,7 @@ import Hydra.ArbitraryCore() -import Hydra.All+import Hydra.Kernel import Hydra.TestGraph import Hydra.Adapters.Literal import Hydra.Adapters.Term
src/test/haskell/Hydra/Types/InferenceSpec.hs view
@@ -1,6 +1,6 @@ module Hydra.Types.InferenceSpec where -import Hydra.All+import Hydra.Kernel import Hydra.Impl.Haskell.Sources.Libraries import Hydra.Types.Inference import Hydra.TestUtils
src/test/haskell/Hydra/Types/UnificationSpec.hs view
@@ -1,6 +1,6 @@ module Hydra.Types.UnificationSpec where -import Hydra.All+import Hydra.Kernel import Hydra.Types.Unification import Hydra.TestUtils import qualified Hydra.Impl.Haskell.Dsl.Types as Types
src/test/haskell/Hydra/Util/Codetree/PrintSpec.hs view
@@ -86,7 +86,7 @@ checkPrecedence :: H.SpecWith () checkPrecedence = do- H.describe "Unit tests for verify that operator precedence is respected" $ do+ H.describe "Unit tests to verify that operator precedence is respected" $ do H.it "Check expressions with operators of different precedence" $ do check