on master help sign in
shuffle pretty printer around to use it exclusively from the tutd console
f5e3e65AgentM
project-m36.cabal+32−27
@@ -34,7 +34,7 @@ Flag haskell-scripting
34 Default: True
34 Default: True
35
35
36Library
36Library
37− Build-Depends: base>=4.8 && < 4.15, ghc-paths, mtl, containers, unordered-containers, hashable, haskeline, directory, MonadRandom, random-shuffle, uuid >= 1.3.12, cassava >= 0.4.5.1 && < 0.6, text, bytestring, deepseq, deepseq-generics, vector, parallel, monad-parallel, exceptions, transformers, gnuplot, binary, filepath, zlib, directory, vector-binary-instances, temporary, stm, time, hashable-time, old-locale, rset, attoparsec, either, base64-bytestring, data-interval, extended-reals, network-transport, aeson >= 1.1, path-pieces, conduit, resourcet, http-api-data, semigroups, QuickCheck, quickcheck-instances, distributed-process-client-server >= 0.2.3, distributed-process >= 0.7.4, distributed-process-extras >= 0.3.2, distributed-process-async >= 0.2.4.1, network-transport-tcp >= 0.6.0, network-transport, list-t, stm-containers >= 0.2.15, foldl, optparse-applicative, Glob, cryptohash-sha256, text-manipulate >= 0.2.0.1 && < 0.3, prettyprinter
37+ Build-Depends: base>=4.8 && < 4.15, ghc-paths, mtl, containers, unordered-containers, hashable, haskeline, directory, MonadRandom, random-shuffle, uuid >= 1.3.12, cassava >= 0.4.5.1 && < 0.6, text, bytestring, deepseq, deepseq-generics, vector, parallel, monad-parallel, exceptions, transformers, gnuplot, binary, filepath, zlib, directory, vector-binary-instances, temporary, stm, time, hashable-time, old-locale, rset, attoparsec, either, base64-bytestring, data-interval, extended-reals, network-transport, aeson >= 1.1, path-pieces, conduit, resourcet, http-api-data, semigroups, QuickCheck, quickcheck-instances, distributed-process-client-server >= 0.2.3, distributed-process >= 0.7.4, distributed-process-extras >= 0.3.2, distributed-process-async >= 0.2.4.1, network-transport-tcp >= 0.6.0, network-transport, list-t, stm-containers >= 0.2.15, foldl, optparse-applicative, Glob, cryptohash-sha256, text-manipulate >= 0.2.0.1 && < 0.3, vector-instances
38 if flag(haskell-scripting)
38 if flag(haskell-scripting)
39 Build-Depends: ghc >= 8.2 && < 8.11
39 Build-Depends: ghc >= 8.2 && < 8.11
40 CPP-Options: -DPM36_HASKELL_SCRIPTING
40 CPP-Options: -DPM36_HASKELL_SCRIPTING
@@ -121,8 +121,7 @@ Library
121 ProjectM36.GraphRefRelationalExpr,
121 ProjectM36.GraphRefRelationalExpr,
122 ProjectM36.NormalizeExpr,
122 ProjectM36.NormalizeExpr,
123 ProjectM36.TransactionInfo,
123 ProjectM36.TransactionInfo,
124− ProjectM36.WithNameExpr,
124+ ProjectM36.WithNameExpr
125− ProjectM36.PrettyPrinter
126 GHC-Options: -Wall -rdynamic
125 GHC-Options: -Wall -rdynamic
127 if os(windows)
126 if os(windows)
128 Build-Depends: Win32 >= 2.5.4.1
127 Build-Depends: Win32 >= 2.5.4.1
@@ -178,7 +177,8 @@ Executable tutd
178 attoparsec,
177 attoparsec,
179 stm-containers >= 1.0.0,
178 stm-containers >= 1.0.0,
180 list-t,
179 list-t,
181− parser-combinators
180+ parser-combinators,
181+ prettyprinter
182 Other-Modules: TutorialD.Interpreter,
182 Other-Modules: TutorialD.Interpreter,
183 TutorialD.Interpreter.Base,
183 TutorialD.Interpreter.Base,
184 TutorialD.Interpreter.DatabaseContextExpr,
184 TutorialD.Interpreter.DatabaseContextExpr,
@@ -197,6 +197,7 @@ Executable tutd
197 TutorialD.Interpreter.SchemaOperator,
197 TutorialD.Interpreter.SchemaOperator,
198 TutorialD.Interpreter.TransGraphRelationalOperator,
198 TutorialD.Interpreter.TransGraphRelationalOperator,
199 TutorialD.Interpreter.SchemaOperator
199 TutorialD.Interpreter.SchemaOperator
200+ TutorialD.Printer
200 main-is: TutorialD/tutd.hs
201 main-is: TutorialD/tutd.hs
201 CC-Options: -fPIC
202 CC-Options: -fPIC
202 GHC-Options: -Wall -threaded
203 GHC-Options: -Wall -threaded
@@ -273,8 +274,8 @@ Test-Suite test-tutoriald
273 Default-Extensions: OverloadedStrings
274 Default-Extensions: OverloadedStrings
274 type: exitcode-stdio-1.0
275 type: exitcode-stdio-1.0
275 main-is: test/TutorialD/Interpreter.hs
276 main-is: test/TutorialD/Interpreter.hs
276− Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, uuid, stm, deepseq, deepseq-generics, binary, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, megaparsec, text, base64-bytestring, data-interval, filepath, stm-containers, list-t, project-m36, random, MonadRandom, semigroups, parser-combinators
277+ Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, uuid, stm, deepseq, deepseq-generics, binary, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, megaparsec, text, base64-bytestring, data-interval, filepath, stm-containers, list-t, project-m36, random, MonadRandom, semigroups, parser-combinators, prettyprinter
277− Other-Modules: TutorialD.Interpreter, TutorialD.Interpreter.Base, TutorialD.Interpreter.Export.Base, TutorialD.Interpreter.Export.CSV, TutorialD.Interpreter.Import.Base, TutorialD.Interpreter.Import.CSV, TutorialD.Interpreter.Import.TutorialD, TutorialD.Interpreter.RODatabaseContextOperator, TutorialD.Interpreter.RelationalExpr, TutorialD.Interpreter.TransactionGraphOperator, TutorialD.Interpreter.Types, TutorialD.Interpreter.DatabaseContextExpr, TutorialD.Interpreter.InformationOperator, TutorialD.Interpreter.Import.BasicExamples, TutorialD.Interpreter.DatabaseContextIOOperator, TutorialD.Interpreter.TestBase, TutorialD.Interpreter.TransGraphRelationalOperator, TutorialD.Interpreter.SchemaOperator
278+ Other-Modules: TutorialD.Interpreter, TutorialD.Interpreter.Base, TutorialD.Interpreter.Export.Base, TutorialD.Interpreter.Export.CSV, TutorialD.Interpreter.Import.Base, TutorialD.Interpreter.Import.CSV, TutorialD.Interpreter.Import.TutorialD, TutorialD.Interpreter.RODatabaseContextOperator, TutorialD.Interpreter.RelationalExpr, TutorialD.Interpreter.TransactionGraphOperator, TutorialD.Interpreter.Types, TutorialD.Interpreter.DatabaseContextExpr, TutorialD.Interpreter.InformationOperator, TutorialD.Interpreter.Import.BasicExamples, TutorialD.Interpreter.DatabaseContextIOOperator, TutorialD.Interpreter.TestBase, TutorialD.Interpreter.TransGraphRelationalOperator, TutorialD.Interpreter.SchemaOperator, TutorialD.Printer
278 GHC-Options: -Wall -threaded
279 GHC-Options: -Wall -threaded
279 Hs-Source-Dirs: ./src/bin, ., test
280 Hs-Source-Dirs: ./src/bin, ., test
280
281
@@ -282,9 +283,9 @@ Test-Suite test-tutoriald-atomfunctionscript
282 Default-Language: Haskell2010
283 Default-Language: Haskell2010
283 Default-Extensions: OverloadedStrings
284 Default-Extensions: OverloadedStrings
284 type: exitcode-stdio-1.0
285 type: exitcode-stdio-1.0
285− Other-Modules: TutorialD.Interpreter, TutorialD.Interpreter.Base, TutorialD.Interpreter.DatabaseContextExpr, TutorialD.Interpreter.DatabaseContextIOOperator, TutorialD.Interpreter.Export.Base, TutorialD.Interpreter.Export.CSV, TutorialD.Interpreter.Import.Base, TutorialD.Interpreter.Import.BasicExamples, TutorialD.Interpreter.Import.CSV, TutorialD.Interpreter.Import.TutorialD, TutorialD.Interpreter.InformationOperator, TutorialD.Interpreter.RODatabaseContextOperator, TutorialD.Interpreter.RelationalExpr, TutorialD.Interpreter.TestBase, TutorialD.Interpreter.TransGraphRelationalOperator, TutorialD.Interpreter.TransactionGraphOperator, TutorialD.Interpreter.Types, TutorialD.Interpreter.SchemaOperator
286+ Other-Modules: TutorialD.Interpreter, TutorialD.Interpreter.Base, TutorialD.Interpreter.DatabaseContextExpr, TutorialD.Interpreter.DatabaseContextIOOperator, TutorialD.Interpreter.Export.Base, TutorialD.Interpreter.Export.CSV, TutorialD.Interpreter.Import.Base, TutorialD.Interpreter.Import.BasicExamples, TutorialD.Interpreter.Import.CSV, TutorialD.Interpreter.Import.TutorialD, TutorialD.Interpreter.InformationOperator, TutorialD.Interpreter.RODatabaseContextOperator, TutorialD.Interpreter.RelationalExpr, TutorialD.Interpreter.TestBase, TutorialD.Interpreter.TransGraphRelationalOperator, TutorialD.Interpreter.TransactionGraphOperator, TutorialD.Interpreter.Types, TutorialD.Interpreter.SchemaOperator, TutorialD.Printer
286 main-is: test/TutorialD/Interpreter/AtomFunctionScript.hs
287 main-is: test/TutorialD/Interpreter/AtomFunctionScript.hs
287− Build-Depends: base, HUnit, project-m36, uuid, containers, megaparsec, text, vector, directory, bytestring, mtl, haskeline, random, MonadRandom, semigroups, time, parser-combinators
288+ Build-Depends: base, HUnit, project-m36, uuid, containers, megaparsec, text, vector, directory, bytestring, mtl, haskeline, random, MonadRandom, semigroups, time, parser-combinators, prettyprinter, base64-bytestring
288 GHC-Options: -Wall -threaded
289 GHC-Options: -Wall -threaded
289 Hs-Source-Dirs: ./src/bin, ./test, .
290 Hs-Source-Dirs: ./src/bin, ./test, .
290
291
@@ -292,9 +293,9 @@ Test-Suite test-tutoriald-databasecontextfunctionscript
292 Default-Language: Haskell2010
293 Default-Language: Haskell2010
293 Default-Extensions: OverloadedStrings
294 Default-Extensions: OverloadedStrings
294 type: exitcode-stdio-1.0
295 type: exitcode-stdio-1.0
295− Other-Modules: TutorialD.Interpreter, TutorialD.Interpreter.Base, TutorialD.Interpreter.DatabaseContextExpr, TutorialD.Interpreter.DatabaseContextIOOperator, TutorialD.Interpreter.Export.Base, TutorialD.Interpreter.Export.CSV, TutorialD.Interpreter.Import.Base, TutorialD.Interpreter.Import.BasicExamples, TutorialD.Interpreter.Import.CSV, TutorialD.Interpreter.Import.TutorialD, TutorialD.Interpreter.InformationOperator, TutorialD.Interpreter.RODatabaseContextOperator, TutorialD.Interpreter.RelationalExpr, TutorialD.Interpreter.TestBase, TutorialD.Interpreter.TransGraphRelationalOperator, TutorialD.Interpreter.TransactionGraphOperator, TutorialD.Interpreter.Types, TutorialD.Interpreter.SchemaOperator
296+ Other-Modules: TutorialD.Interpreter, TutorialD.Interpreter.Base, TutorialD.Interpreter.DatabaseContextExpr, TutorialD.Interpreter.DatabaseContextIOOperator, TutorialD.Interpreter.Export.Base, TutorialD.Interpreter.Export.CSV, TutorialD.Interpreter.Import.Base, TutorialD.Interpreter.Import.BasicExamples, TutorialD.Interpreter.Import.CSV, TutorialD.Interpreter.Import.TutorialD, TutorialD.Interpreter.InformationOperator, TutorialD.Interpreter.RODatabaseContextOperator, TutorialD.Interpreter.RelationalExpr, TutorialD.Interpreter.TestBase, TutorialD.Interpreter.TransGraphRelationalOperator, TutorialD.Interpreter.TransactionGraphOperator, TutorialD.Interpreter.Types, TutorialD.Interpreter.SchemaOperator, TutorialD.Printer
296 main-is: test/TutorialD/Interpreter/DatabaseContextFunctionScript.hs
297 main-is: test/TutorialD/Interpreter/DatabaseContextFunctionScript.hs
297− Build-Depends: base, HUnit, project-m36, uuid, containers, megaparsec, text, vector, directory, bytestring, mtl, haskeline, random, MonadRandom, semigroups, time, parser-combinators
298+ Build-Depends: base, HUnit, project-m36, uuid, containers, megaparsec, text, vector, directory, bytestring, mtl, haskeline, random, MonadRandom, semigroups, time, parser-combinators, prettyprinter, base64-bytestring
298 GHC-Options: -Wall -threaded
299 GHC-Options: -Wall -threaded
299 Hs-Source-Dirs: ./src/bin, ./test, .
300 Hs-Source-Dirs: ./src/bin, ./test, .
300
301
@@ -319,8 +320,8 @@ Test-Suite test-transactiongraph-persist
319 Default-Extensions: OverloadedStrings
320 Default-Extensions: OverloadedStrings
320 type: exitcode-stdio-1.0
321 type: exitcode-stdio-1.0
321 main-is: test/TransactionGraph/Persist.hs
322 main-is: test/TransactionGraph/Persist.hs
322− Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, uuid, stm, deepseq, deepseq-generics, binary, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, megaparsec, text, base64-bytestring, data-interval, filepath, stm-containers, project-m36, random, MonadRandom, semigroups, parser-combinators
323+ Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, uuid, stm, deepseq, deepseq-generics, binary, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, megaparsec, text, base64-bytestring, data-interval, filepath, stm-containers, project-m36, random, MonadRandom, semigroups, parser-combinators, prettyprinter
323− Other-Modules: TutorialD.Interpreter.Base, TutorialD.Interpreter.RelationalExpr, TutorialD.Interpreter.Types, TutorialD.Interpreter.DatabaseContextExpr, TutorialD.Interpreter.Import.BasicExamples
324+ Other-Modules: TutorialD.Interpreter.Base, TutorialD.Interpreter.RelationalExpr, TutorialD.Interpreter.Types, TutorialD.Interpreter.DatabaseContextExpr, TutorialD.Interpreter.Import.BasicExamples, TutorialD.Printer
324 Hs-Source-Dirs: ., ./src/bin
325 Hs-Source-Dirs: ., ./src/bin
325 GHC-Options: -Wall -threaded
326 GHC-Options: -Wall -threaded
326
327
@@ -329,7 +330,7 @@ Test-Suite test-relation-import-csv
329 Default-Extensions: OverloadedStrings
330 Default-Extensions: OverloadedStrings
330 type: exitcode-stdio-1.0
331 type: exitcode-stdio-1.0
331 main-is: test/Relation/Import/CSV.hs
332 main-is: test/Relation/Import/CSV.hs
332− Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, uuid, stm, deepseq, deepseq-generics, binary, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, megaparsec, text, base64-bytestring, data-interval, filepath, stm-containers, project-m36
333+ Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, uuid, stm, deepseq, deepseq-generics, binary, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, megaparsec, text, base64-bytestring, data-interval, filepath, stm-containers, project-m36, prettyprinter
333 GHC-Options: -Wall -threaded
334 GHC-Options: -Wall -threaded
334
335
335Test-Suite test-tutoriald-import-tutoriald
336Test-Suite test-tutoriald-import-tutoriald
@@ -337,8 +338,8 @@ Test-Suite test-tutoriald-import-tutoriald
337 Default-Extensions: OverloadedStrings
338 Default-Extensions: OverloadedStrings
338 type: exitcode-stdio-1.0
339 type: exitcode-stdio-1.0
339 main-is: test/TutorialD/Interpreter/Import/TutorialD.hs
340 main-is: test/TutorialD/Interpreter/Import/TutorialD.hs
340− Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, uuid, stm, deepseq, deepseq-generics, binary, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, megaparsec, text, base64-bytestring, data-interval, filepath, stm-containers, project-m36, random, MonadRandom, semigroups, parser-combinators
341+ Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, uuid, stm, deepseq, deepseq-generics, binary, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, megaparsec, text, base64-bytestring, data-interval, filepath, stm-containers, project-m36, random, MonadRandom, semigroups, parser-combinators, prettyprinter
341− Other-Modules: TutorialD.Interpreter.Base, TutorialD.Interpreter.Import.Base, TutorialD.Interpreter.Import.TutorialD, TutorialD.Interpreter.RelationalExpr, TutorialD.Interpreter.Types, TutorialD.Interpreter.DatabaseContextExpr, TutorialD.Interpreter.Import.BasicExamples
342+ Other-Modules: TutorialD.Interpreter.Base, TutorialD.Interpreter.Import.Base, TutorialD.Interpreter.Import.TutorialD, TutorialD.Interpreter.RelationalExpr, TutorialD.Interpreter.Types, TutorialD.Interpreter.DatabaseContextExpr, TutorialD.Interpreter.Import.BasicExamples, TutorialD.Printer
342 GHC-Options: -Wall -threaded
343 GHC-Options: -Wall -threaded
343 Hs-Source-Dirs: ., ./src/bin
344 Hs-Source-Dirs: ., ./src/bin
344
345
@@ -347,7 +348,7 @@ Test-Suite test-relation-export-csv
347 Default-Extensions: OverloadedStrings
348 Default-Extensions: OverloadedStrings
348 type: exitcode-stdio-1.0
349 type: exitcode-stdio-1.0
349 main-is: test/Relation/Export/CSV.hs
350 main-is: test/Relation/Export/CSV.hs
350− Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, uuid, stm, deepseq, deepseq-generics, binary, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, megaparsec, text, base64-bytestring, data-interval, filepath, stm-containers, project-m36
351+ Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, uuid, stm, deepseq, deepseq-generics, binary, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, megaparsec, text, base64-bytestring, data-interval, filepath, stm-containers, project-m36, prettyprinter
351 GHC-Options: -Wall -threaded
352 GHC-Options: -Wall -threaded
352
353
353Test-Suite test-transactiongraph-merge
354Test-Suite test-transactiongraph-merge
@@ -362,9 +363,11 @@ Test-Suite test-prettyprinter
362 Default-Language: Haskell2010
363 Default-Language: Haskell2010
363 Default-Extensions: OverloadedStrings
364 Default-Extensions: OverloadedStrings
364 type: exitcode-stdio-1.0
365 type: exitcode-stdio-1.0
365− main-is: test/PrettyPrinter.hs
366+ main-is: test/TutorialD/Printer.hs
366− Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, uuid, stm, deepseq, deepseq-generics, binary, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, megaparsec, text, base64-bytestring, data-interval, filepath, template-haskell, transformers, aeson, conduit, either, path-pieces, http-api-data, stm-containers, list-t, project-m36
367+ Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, uuid, stm, deepseq, deepseq-generics, binary, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, megaparsec, text, base64-bytestring, data-interval, filepath, template-haskell, transformers, aeson, conduit, either, path-pieces, http-api-data, stm-containers, list-t, project-m36, prettyprinter, random, MonadRandom, parser-combinators, base64-bytestring
367 GHC-Options: -Wall -threaded
368 GHC-Options: -Wall -threaded
369+ Other-Modules: TutorialD.Printer, TutorialD.Interpreter.Base, TutorialD.Interpreter.RelationalExpr, TutorialD.Interpreter.Types
370+ Hs-Source-Dirs: ., ./src/bin
368
371
369benchmark bench
372benchmark bench
370 Default-Language: Haskell2010
373 Default-Language: Haskell2010
@@ -453,7 +456,7 @@ Test-Suite test-websocket-server
453 Default-Language: Haskell2010
456 Default-Language: Haskell2010
454 type: exitcode-stdio-1.0
457 type: exitcode-stdio-1.0
455 main-is: test/Server/WebSocket.hs
458 main-is: test/Server/WebSocket.hs
456− Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, uuid, stm, deepseq, deepseq-generics, binary, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, megaparsec, text, base64-bytestring, data-interval, filepath, transformers, stm-containers, list-t, websockets, optparse-applicative, network, aeson, project-m36, random, MonadRandom, network-transport-tcp, semigroups, parser-combinators
459+ Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, uuid, stm, deepseq, deepseq-generics, binary, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, megaparsec, text, base64-bytestring, data-interval, filepath, transformers, stm-containers, list-t, websockets, optparse-applicative, network, aeson, project-m36, random, MonadRandom, network-transport-tcp, semigroups, parser-combinators, prettyprinter
457 Other-Modules: TutorialD.Interpreter.Export.Base, TutorialD.Interpreter.Export.CSV, TutorialD.Interpreter.Import.BasicExamples, TutorialD.Interpreter.Import.CSV, TutorialD.Interpreter.InformationOperator, TutorialD.Interpreter.RODatabaseContextOperator, TutorialD.Interpreter.TransactionGraphOperator, ProjectM36.Client.Json, ProjectM36.Server.RemoteCallTypes.Json, ProjectM36.Server.WebSocket, TutorialD.Interpreter, TutorialD.Interpreter.Base, TutorialD.Interpreter.DatabaseContextExpr, TutorialD.Interpreter.Import.Base, TutorialD.Interpreter.Import.TutorialD, TutorialD.Interpreter.RelationalExpr, TutorialD.Interpreter.Types, TutorialD.Interpreter.DatabaseContextIOOperator, TutorialD.Interpreter.TransGraphRelationalOperator, TutorialD.Interpreter.SchemaOperator
460 Other-Modules: TutorialD.Interpreter.Export.Base, TutorialD.Interpreter.Export.CSV, TutorialD.Interpreter.Import.BasicExamples, TutorialD.Interpreter.Import.CSV, TutorialD.Interpreter.InformationOperator, TutorialD.Interpreter.RODatabaseContextOperator, TutorialD.Interpreter.TransactionGraphOperator, ProjectM36.Client.Json, ProjectM36.Server.RemoteCallTypes.Json, ProjectM36.Server.WebSocket, TutorialD.Interpreter, TutorialD.Interpreter.Base, TutorialD.Interpreter.DatabaseContextExpr, TutorialD.Interpreter.Import.Base, TutorialD.Interpreter.Import.TutorialD, TutorialD.Interpreter.RelationalExpr, TutorialD.Interpreter.Types, TutorialD.Interpreter.DatabaseContextIOOperator, TutorialD.Interpreter.TransGraphRelationalOperator, TutorialD.Interpreter.SchemaOperator
458 Default-Extensions: OverloadedStrings
461 Default-Extensions: OverloadedStrings
459 GHC-Options: -Wall -threaded
462 GHC-Options: -Wall -threaded
@@ -463,17 +466,18 @@ Test-Suite test-isomorphic-schemas
463 Default-Language: Haskell2010
466 Default-Language: Haskell2010
464 type: exitcode-stdio-1.0
467 type: exitcode-stdio-1.0
465 main-is: test/IsomorphicSchema.hs
468 main-is: test/IsomorphicSchema.hs
466− Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, uuid, stm, deepseq, deepseq-generics, binary, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, megaparsec, text, base64-bytestring, data-interval, filepath, transformers, stm-containers, list-t, websockets, optparse-applicative, network, aeson, project-m36
469+ Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, uuid, stm, deepseq, deepseq-generics, binary, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, megaparsec, text, base64-bytestring, data-interval, filepath, transformers, stm-containers, list-t, websockets, optparse-applicative, network, aeson, project-m36, prettyprinter
467 Default-Extensions: OverloadedStrings
470 Default-Extensions: OverloadedStrings
468 GHC-Options: -Wall -threaded
471 GHC-Options: -Wall -threaded
469 Hs-Source-Dirs: ./src/bin, .
472 Hs-Source-Dirs: ./src/bin, .
473+ Other-Modules: TutorialD.Printer
470
474
471Test-Suite test-atomable
475Test-Suite test-atomable
472 Default-Language: Haskell2010
476 Default-Language: Haskell2010
473 type: exitcode-stdio-1.0
477 type: exitcode-stdio-1.0
474 main-is: test/Relation/Atomable.hs
478 main-is: test/Relation/Atomable.hs
475− Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, uuid, stm, deepseq, deepseq-generics, binary, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, megaparsec, text, base64-bytestring, data-interval, filepath, transformers, stm-containers, list-t, websockets, optparse-applicative, network, aeson, project-m36, random, MonadRandom, semigroups, parser-combinators
479+ Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, uuid, stm, deepseq, deepseq-generics, binary, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, megaparsec, text, base64-bytestring, data-interval, filepath, transformers, stm-containers, list-t, websockets, optparse-applicative, network, aeson, project-m36, random, MonadRandom, semigroups, parser-combinators, prettyprinter
476− Other-Modules: TutorialD.Interpreter, TutorialD.Interpreter.Base, TutorialD.Interpreter.DatabaseContextExpr, TutorialD.Interpreter.DatabaseContextIOOperator, TutorialD.Interpreter.Export.Base, TutorialD.Interpreter.Export.CSV, TutorialD.Interpreter.Import.Base, TutorialD.Interpreter.Import.BasicExamples, TutorialD.Interpreter.Import.CSV, TutorialD.Interpreter.Import.TutorialD, TutorialD.Interpreter.InformationOperator, TutorialD.Interpreter.RODatabaseContextOperator, TutorialD.Interpreter.RelationalExpr, TutorialD.Interpreter.SchemaOperator, TutorialD.Interpreter.TestBase, TutorialD.Interpreter.TransGraphRelationalOperator, TutorialD.Interpreter.TransactionGraphOperator, TutorialD.Interpreter.Types
480+ Other-Modules: TutorialD.Interpreter, TutorialD.Interpreter.Base, TutorialD.Interpreter.DatabaseContextExpr, TutorialD.Interpreter.DatabaseContextIOOperator, TutorialD.Interpreter.Export.Base, TutorialD.Interpreter.Export.CSV, TutorialD.Interpreter.Import.Base, TutorialD.Interpreter.Import.BasicExamples, TutorialD.Interpreter.Import.CSV, TutorialD.Interpreter.Import.TutorialD, TutorialD.Interpreter.InformationOperator, TutorialD.Interpreter.RODatabaseContextOperator, TutorialD.Interpreter.RelationalExpr, TutorialD.Interpreter.SchemaOperator, TutorialD.Interpreter.TestBase, TutorialD.Interpreter.TransGraphRelationalOperator, TutorialD.Interpreter.TransactionGraphOperator, TutorialD.Interpreter.Types, TutorialD.Printer
477 Default-Extensions: OverloadedStrings
481 Default-Extensions: OverloadedStrings
478 GHC-Options: -Wall -threaded
482 GHC-Options: -Wall -threaded
479 Hs-Source-Dirs: ./src/bin, ., test/
483 Hs-Source-Dirs: ./src/bin, ., test/
@@ -491,7 +495,7 @@ Test-Suite test-transactiongraph-automerge
491 Default-Language: Haskell2010
495 Default-Language: Haskell2010
492 type: exitcode-stdio-1.0
496 type: exitcode-stdio-1.0
493 main-is: test/TransactionGraph/Automerge.hs
497 main-is: test/TransactionGraph/Automerge.hs
494− Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, uuid, stm, deepseq, deepseq-generics, binary, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, megaparsec, text, base64-bytestring, data-interval, filepath, transformers, stm-containers, list-t, websockets, optparse-applicative, network, aeson, project-m36, random, MonadRandom, semigroups, parser-combinators
498+ Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, uuid, stm, deepseq, deepseq-generics, binary, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, megaparsec, text, base64-bytestring, data-interval, filepath, transformers, stm-containers, list-t, websockets, optparse-applicative, network, aeson, project-m36, random, MonadRandom, semigroups, parser-combinators, prettyprinter
495 Other-Modules: TutorialD.Interpreter, TutorialD.Interpreter.Base, TutorialD.Interpreter.DatabaseContextExpr, TutorialD.Interpreter.DatabaseContextIOOperator, TutorialD.Interpreter.Export.Base, TutorialD.Interpreter.Export.CSV, TutorialD.Interpreter.Import.Base, TutorialD.Interpreter.Import.BasicExamples, TutorialD.Interpreter.Import.CSV, TutorialD.Interpreter.Import.TutorialD, TutorialD.Interpreter.InformationOperator, TutorialD.Interpreter.RODatabaseContextOperator, TutorialD.Interpreter.RelationalExpr, TutorialD.Interpreter.SchemaOperator, TutorialD.Interpreter.TestBase, TutorialD.Interpreter.TransGraphRelationalOperator, TutorialD.Interpreter.TransactionGraphOperator, TutorialD.Interpreter.Types
499 Other-Modules: TutorialD.Interpreter, TutorialD.Interpreter.Base, TutorialD.Interpreter.DatabaseContextExpr, TutorialD.Interpreter.DatabaseContextIOOperator, TutorialD.Interpreter.Export.Base, TutorialD.Interpreter.Export.CSV, TutorialD.Interpreter.Import.Base, TutorialD.Interpreter.Import.BasicExamples, TutorialD.Interpreter.Import.CSV, TutorialD.Interpreter.Import.TutorialD, TutorialD.Interpreter.InformationOperator, TutorialD.Interpreter.RODatabaseContextOperator, TutorialD.Interpreter.RelationalExpr, TutorialD.Interpreter.SchemaOperator, TutorialD.Interpreter.TestBase, TutorialD.Interpreter.TransGraphRelationalOperator, TutorialD.Interpreter.TransactionGraphOperator, TutorialD.Interpreter.Types
496 Default-Extensions: OverloadedStrings
500 Default-Extensions: OverloadedStrings
497 GHC-Options: -Wall -threaded
501 GHC-Options: -Wall -threaded
@@ -501,7 +505,7 @@ Test-Suite test-tupleable
501 Default-Language: Haskell2010
505 Default-Language: Haskell2010
502 type: exitcode-stdio-1.0
506 type: exitcode-stdio-1.0
503 main-is: test/Relation/Tupleable.hs
507 main-is: test/Relation/Tupleable.hs
504− Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, uuid, stm, deepseq, deepseq-generics, binary, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, megaparsec, text, base64-bytestring, data-interval, filepath, transformers, stm-containers, list-t, websockets, optparse-applicative, network, aeson, project-m36, random, MonadRandom, semigroups
508+ Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, uuid, stm, deepseq, deepseq-generics, binary, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, megaparsec, text, base64-bytestring, data-interval, filepath, transformers, stm-containers, list-t, websockets, optparse-applicative, network, aeson, project-m36, random, MonadRandom, semigroups, prettyprinter
505 Default-Extensions: OverloadedStrings
509 Default-Extensions: OverloadedStrings
506 GHC-Options: -Wall -threaded
510 GHC-Options: -Wall -threaded
507 Hs-Source-Dirs: ./src/bin, ., test/
511 Hs-Source-Dirs: ./src/bin, ., test/
@@ -510,10 +514,11 @@ Test-Suite test-client-simple
510 Default-Language: Haskell2010
514 Default-Language: Haskell2010
511 Main-Is: test/Client/Simple.hs
515 Main-Is: test/Client/Simple.hs
512 type: exitcode-stdio-1.0
516 type: exitcode-stdio-1.0
513− Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, uuid, stm, deepseq, deepseq-generics, binary, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, megaparsec, text, base64-bytestring, data-interval, filepath, transformers, stm-containers, list-t, websockets, optparse-applicative, network, aeson, project-m36, random, MonadRandom, semigroups
517+ Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, uuid, stm, deepseq, deepseq-generics, binary, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, megaparsec, text, base64-bytestring, data-interval, filepath, transformers, stm-containers, list-t, websockets, optparse-applicative, network, aeson, project-m36, random, MonadRandom, semigroups, prettyprinter
514 Default-Extensions: OverloadedStrings
518 Default-Extensions: OverloadedStrings
515 GHC-Options: -Wall -threaded
519 GHC-Options: -Wall -threaded
516 Hs-Source-Dirs: ./src/bin, ., test/
520 Hs-Source-Dirs: ./src/bin, ., test/
521+ Other-Modules: TutorialD.Printer
517
522
518-- test for file handle leaks
523-- test for file handle leaks
519Executable handles
524Executable handles
@@ -547,8 +552,8 @@ Test-Suite test-dataframe
547 Default-Language: Haskell2010
552 Default-Language: Haskell2010
548 Main-Is: test/DataFrame.hs
553 Main-Is: test/DataFrame.hs
549 type: exitcode-stdio-1.0
554 type: exitcode-stdio-1.0
550− Other-Modules: TutorialD.Interpreter, TutorialD.Interpreter.Base, TutorialD.Interpreter.DatabaseContextExpr, TutorialD.Interpreter.DatabaseContextIOOperator, TutorialD.Interpreter.Export.Base, TutorialD.Interpreter.Export.CSV, TutorialD.Interpreter.Import.Base, TutorialD.Interpreter.Import.BasicExamples, TutorialD.Interpreter.Import.CSV, TutorialD.Interpreter.Import.TutorialD, TutorialD.Interpreter.InformationOperator, TutorialD.Interpreter.RODatabaseContextOperator, TutorialD.Interpreter.RelationalExpr, TutorialD.Interpreter.SchemaOperator, TutorialD.Interpreter.TestBase, TutorialD.Interpreter.TransGraphRelationalOperator, TutorialD.Interpreter.TransactionGraphOperator, TutorialD.Interpreter.Types
555+ Other-Modules: TutorialD.Interpreter, TutorialD.Interpreter.Base, TutorialD.Interpreter.DatabaseContextExpr, TutorialD.Interpreter.DatabaseContextIOOperator, TutorialD.Interpreter.Export.Base, TutorialD.Interpreter.Export.CSV, TutorialD.Interpreter.Import.Base, TutorialD.Interpreter.Import.BasicExamples, TutorialD.Interpreter.Import.CSV, TutorialD.Interpreter.Import.TutorialD, TutorialD.Interpreter.InformationOperator, TutorialD.Interpreter.RODatabaseContextOperator, TutorialD.Interpreter.RelationalExpr, TutorialD.Interpreter.SchemaOperator, TutorialD.Interpreter.TestBase, TutorialD.Interpreter.TransGraphRelationalOperator, TutorialD.Interpreter.TransactionGraphOperator, TutorialD.Interpreter.Types, TutorialD.Printer
551− Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, uuid, stm, deepseq, deepseq-generics, binary, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, megaparsec, text, base64-bytestring, data-interval, filepath, transformers, stm-containers, list-t, websockets, optparse-applicative, network, aeson, project-m36, random, MonadRandom, semigroups, parser-combinators
556+ Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, uuid, stm, deepseq, deepseq-generics, binary, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, megaparsec, text, base64-bytestring, data-interval, filepath, transformers, stm-containers, list-t, websockets, optparse-applicative, network, aeson, project-m36, random, MonadRandom, semigroups, parser-combinators, prettyprinter
552 Default-Extensions: OverloadedStrings
557 Default-Extensions: OverloadedStrings
553 GHC-Options: -Wall -threaded
558 GHC-Options: -Wall -threaded
554 Hs-Source-Dirs: ./src/bin, ., test/
559 Hs-Source-Dirs: ./src/bin, ., test/
src/bin/TutorialD/Interpreter/Base.hs+1−1
@@ -226,5 +226,5 @@ utcTimeP = do
226
226
227colonOp :: Text -> Parser ()
227colonOp :: Text -> Parser ()
228colonOp opStr = do
228colonOp opStr = do
229− _ <- string opStr <* spaceChar <* spaceConsumer
229+ _ <- string opStr <* (void spaceChar <|> eof) <* spaceConsumer
230 pure ()
230 pure ()
src/bin/TutorialD/Interpreter/RODatabaseContextOperator.hs+22−5
@@ -1,13 +1,16 @@
1{-# LANGUAGE GADTs #-}
1{-# LANGUAGE GADTs #-}
2module TutorialD.Interpreter.RODatabaseContextOperator where
2module TutorialD.Interpreter.RODatabaseContextOperator where
3import ProjectM36.Base
3import ProjectM36.Base
4+import ProjectM36.Relation
4import qualified ProjectM36.DataFrame as DF
5import qualified ProjectM36.DataFrame as DF
5import ProjectM36.Error
6import ProjectM36.Error
7+import ProjectM36.Tuple
6import ProjectM36.InclusionDependency
8import ProjectM36.InclusionDependency
7import qualified ProjectM36.Client as C
9import qualified ProjectM36.Client as C
8import TutorialD.Interpreter.Base
10import TutorialD.Interpreter.Base
9import TutorialD.Interpreter.RelationalExpr
11import TutorialD.Interpreter.RelationalExpr
10import TutorialD.Interpreter.DatabaseContextExpr
12import TutorialD.Interpreter.DatabaseContextExpr
13+import TutorialD.Printer
11import Control.Monad.State
14import Control.Monad.State
12import qualified Data.Text as T
15import qualified Data.Text as T
13import ProjectM36.Relation.Show.Gnuplot
16import ProjectM36.Relation.Show.Gnuplot
@@ -19,7 +22,7 @@ data RODatabaseContextOperator where
19 ShowRelation :: RelationalExpr -> RODatabaseContextOperator
22 ShowRelation :: RelationalExpr -> RODatabaseContextOperator
20 PlotRelation :: RelationalExpr -> RODatabaseContextOperator
23 PlotRelation :: RelationalExpr -> RODatabaseContextOperator
21 ShowRelationType :: RelationalExpr -> RODatabaseContextOperator
24 ShowRelationType :: RelationalExpr -> RODatabaseContextOperator
22− ShowConstraint :: StringType -> RODatabaseContextOperator
25+ ShowConstraints :: StringType -> RODatabaseContextOperator
23 ShowPlan :: DatabaseContextExpr -> RODatabaseContextOperator
26 ShowPlan :: DatabaseContextExpr -> RODatabaseContextOperator
24 ShowTypes :: RODatabaseContextOperator
27 ShowTypes :: RODatabaseContextOperator
25 ShowRelationVariables :: RODatabaseContextOperator
28 ShowRelationVariables :: RODatabaseContextOperator
@@ -64,7 +67,7 @@ quitP = do
64showConstraintsP :: Parser RODatabaseContextOperator
67showConstraintsP :: Parser RODatabaseContextOperator
65showConstraintsP = do
68showConstraintsP = do
66 colonOp ":constraints"
69 colonOp ":constraints"
67− ShowConstraint <$> option "" identifier
70+ ShowConstraints <$> option "" identifier
68
71
69plotRelExprP :: Parser RODatabaseContextOperator
72plotRelExprP :: Parser RODatabaseContextOperator
70plotRelExprP = do
73plotRelExprP = do
@@ -106,15 +109,16 @@ evalRODatabaseContextOp sessionId conn (PlotRelation expr) = do
106 err <- plotRelation rel
109 err <- plotRelation rel
107 when (isJust err) $ print err
110 when (isJust err) $ print err
108
111
109−evalRODatabaseContextOp sessionId conn (ShowConstraint name) = do
112+evalRODatabaseContextOp sessionId conn (ShowConstraints name) = do
110 eIncDeps <- C.inclusionDependencies sessionId conn
113 eIncDeps <- C.inclusionDependencies sessionId conn
111 let val = case eIncDeps of
114 let val = case eIncDeps of
112 Left err -> Left err
115 Left err -> Left err
113 Right incDeps -> case name of
116 Right incDeps -> case name of
114− "" -> inclusionDependenciesAsRelation incDeps
117+ "" -> inclusionDependenciesAsRelation incDeps >>= renderRelExprsInIncDeps
115 depName -> case M.lookup depName incDeps of
118 depName -> case M.lookup depName incDeps of
116 Nothing -> Left (InclusionDependencyNameNotInUseError depName)
119 Nothing -> Left (InclusionDependencyNameNotInUseError depName)
120+ Just dep ->
117− Just dep -> inclusionDependenciesAsRelation (M.singleton depName dep)
121+ inclusionDependenciesAsRelation (M.singleton depName dep) >>= renderRelExprsInIncDeps
118 pure $ case val of
122 pure $ case val of
119 Left err -> DisplayErrorResult (T.pack (show err))
123 Left err -> DisplayErrorResult (T.pack (show err))
120 Right rel -> DisplayRelationResult rel
124 Right rel -> DisplayRelationResult rel
@@ -191,3 +195,16 @@ attrOrderExprP = DF.AttributeOrderExpr <$> identifier <*> orderP
191
195
192orderP :: Parser DF.Order
196orderP :: Parser DF.Order
193orderP = try (reservedOp "ascending" >> pure DF.AscendingOrder) <|> try (reservedOp "descending" >> pure DF.DescendingOrder) <|> pure DF.AscendingOrder
197orderP = try (reservedOp "ascending" >> pure DF.AscendingOrder) <|> try (reservedOp "descending" >> pure DF.DescendingOrder) <|> pure DF.AscendingOrder
198+
199+-- render RelationalExprAtoms as TutorialD
200+renderRelExprsInIncDeps :: Relation -> Either RelationalError Relation
201+renderRelExprsInIncDeps = relMogrify tupMapper attrs
202+ where
203+ tupMapper tup = pure $ mkRelationTupleFromMap (M.map mapper (tupleToMap tup))
204+ mapper (RelationalExprAtom expr) = TextAtom (T.pack (show (prettyRelationalExpr expr)))
205+ mapper atom = atom
206+ attrs = C.attributesFromList [Attribute "name" TextAtomType,
207+ Attribute "sub" TextAtomType,
208+ Attribute "super" TextAtomType
209+ ]
210+
src/lib/ProjectM36/PrettyPrinter.hs → src/bin/TutorialD/Printer.hsrenamed+72−32
@@ -1,52 +1,67 @@
1−{-# LANGUAGE TypeSynonymInstances #-}
1+{-# OPTIONS_GHC -fno-warn-orphans #-}
2{-# LANGUAGE FlexibleInstances #-}
2{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE OverloadedStrings #-}
4{-# LANGUAGE ScopedTypeVariables #-}
4{-# LANGUAGE ScopedTypeVariables #-}
5−module ProjectM36.PrettyPrinter where
5+{-# LANGUAGE TypeApplications #-}
6+module TutorialD.Printer where
6import ProjectM36.Base
7import ProjectM36.Base
7−import ProjectM36.Atomable
8+import ProjectM36.Attribute hiding (null)
8−import ProjectM36.Attribute
9import Data.Text.Prettyprint.Doc
9import Data.Text.Prettyprint.Doc
10import qualified Data.Set as S hiding (fromList)
10import qualified Data.Set as S hiding (fromList)
11−import qualified Data.Text as T
12import qualified Data.Vector as V
11import qualified Data.Vector as V
13import qualified Data.Map.Strict as M
12import qualified Data.Map.Strict as M
14−import Data.Foldable as F
13+import Data.Time.Calendar
14+import Data.Time.Clock.POSIX
15+import qualified Data.ByteString.Base64 as B64
16+import qualified Data.Text.Encoding as TE
15
17
16instance Pretty Atom where
18instance Pretty Atom where
17 pretty (IntegerAtom x) = pretty x
19 pretty (IntegerAtom x) = pretty x
18− pretty (IntAtom x) = pretty x
20+ pretty (IntAtom x) = "int" <> parensList [pretty x]
19 pretty (DoubleAtom x) = pretty x
21 pretty (DoubleAtom x) = pretty x
20− pretty (TextAtom x) = pretty x
22+ pretty (TextAtom x) = dquotes (pretty x)
21− pretty (DayAtom x) = pretty $ show x
23+ pretty (DayAtom x) = "fromGregorian" <> parensList [pretty a, pretty b, pretty c]
22− pretty (DateTimeAtom x) = pretty $ show x
24+ where
25+ (a,b,c) = toGregorian x
26+ pretty (DateTimeAtom time) = "dateTimeFromEpochSeconds" <> parensList [pretty @Integer (round (utcTimeToPOSIXSeconds time))]
23− pretty (ByteStringAtom x) = pretty $ show x
27+ pretty (ByteStringAtom bs) = "bytestring" <> parensList [dquotes (pretty (TE.decodeUtf8 (B64.encode bs)))]
24− pretty (BoolAtom x) = pretty x
28+ pretty (BoolAtom x) = if x then "t" else "f"
25 pretty (RelationAtom x) = pretty x
29 pretty (RelationAtom x) = pretty x
30+ pretty (RelationalExprAtom re) = pretty re
26− pretty (ConstructedAtom n ty as) = pretty n <+> prettyList as
31+ pretty (ConstructedAtom n _ as) = pretty n <+> prettyList as
27
32
28instance Pretty AtomExpr where
33instance Pretty AtomExpr where
29 pretty (AttributeAtomExpr attrName) = pretty attrName
34 pretty (AttributeAtomExpr attrName) = pretty attrName
30 pretty (NakedAtomExpr atom) = pretty atom
35 pretty (NakedAtomExpr atom) = pretty atom
31− pretty (FunctionAtomExpr atomFuncName atomExprs _) = pretty atomFuncName <> prettyAtomExprsAsArguments atomExprs
36+ pretty (FunctionAtomExpr atomFuncName' atomExprs _) = pretty atomFuncName' <> prettyAtomExprsAsArguments atomExprs
32− pretty (RelationAtomExpr relExpr) = pretty relExpr
37+ pretty (RelationAtomExpr relExpr) = pretty relExpr
38+ pretty (ConstructedAtomExpr dName [] _) = pretty dName
33− pretty (ConstructedAtomExpr dName atomExprs _) = pretty dName <+> prettyList atomExprs
39+ pretty (ConstructedAtomExpr dName atomExprs _) = pretty dName <+> hsep (map prettyAtomExpr atomExprs)
34−
40+
41+prettyAtomExpr :: AtomExpr -> Doc ann
42+prettyAtomExpr atomExpr =
43+ case atomExpr of
44+ AttributeAtomExpr attrName -> "@" <> pretty attrName
45+ ConstructedAtomExpr dConsName [] () -> pretty dConsName
46+ ConstructedAtomExpr dConsName atomExprs () -> parens (pretty dConsName <+> hsep (map prettyAtomExpr atomExprs))
47+ _ -> pretty atomExpr
48+
35prettyAtomExprsAsArguments :: [AtomExpr] -> Doc ann
49prettyAtomExprsAsArguments :: [AtomExpr] -> Doc ann
36prettyAtomExprsAsArguments = align . parensList . map addAt
50prettyAtomExprsAsArguments = align . parensList . map addAt
37− where addAt (atomExpr :: AtomExpr) = case atomExpr of
51+ where addAt (atomExpr :: AtomExpr) =
52+ case atomExpr of
38− AttributeAtomExpr attrName -> "@" <> pretty attrName
53+ AttributeAtomExpr attrName -> "@" <> pretty attrName
39− otherwise -> pretty atomExpr
54+ _ -> pretty atomExpr
40
55
41instance Pretty TupleExpr where
56instance Pretty TupleExpr where
42− pretty (TupleExpr map) = "tuple" <> bracesList (Prelude.map (\(attrName,atom)-> pretty attrName <+> pretty atom) (M.toList map))
57+ pretty (TupleExpr map') = "tuple" <> bracesList (Prelude.map (\(attrName,atom)-> pretty attrName <+> pretty atom) (M.toList map'))
43
58
44instance Pretty RelationTuple where
59instance Pretty RelationTuple where
45 pretty (RelationTuple attrs atoms) = "tuple" <> bracesList (zipWith (\x y-> pretty x <+> pretty y) (V.toList (attributeNames attrs)) (V.toList atoms))
60 pretty (RelationTuple attrs atoms) = "tuple" <> bracesList (zipWith (\x y-> pretty x <+> pretty y) (V.toList (attributeNames attrs)) (V.toList atoms))
46
61
47instance Pretty Relation where
62instance Pretty Relation where
48− pretty (Relation attrs tupSet) | attrs == V.empty && (asList tupSet) == [] = "false"
63+ pretty (Relation attrs tupSet) | attrs == V.empty && null (asList tupSet) = "false"
49− pretty (Relation attrs tupSet) | attrs == V.empty && (asList tupSet) == [RelationTuple V.empty (V.empty)] = "true"
64+ pretty (Relation attrs tupSet) | attrs == V.empty && asList tupSet == [RelationTuple V.empty V.empty] = "true"
50 pretty (Relation attrs tupSet) = "relation" <> prettyBracesList (V.toList attrs) <> prettyBracesList (asList tupSet)
65 pretty (Relation attrs tupSet) = "relation" <> prettyBracesList (V.toList attrs) <> prettyBracesList (asList tupSet)
51
66
52instance Pretty Attribute where
67instance Pretty Attribute where
@@ -59,34 +74,38 @@ instance Pretty RelationalExpr where
59 pretty (Equals a b) = pretty' a <+> "==" <+> pretty' b
74 pretty (Equals a b) = pretty' a <+> "==" <+> pretty' b
60 pretty (Project ns r) = pretty' (ignoreProjects r) <> pretty ns
75 pretty (Project ns r) = pretty' (ignoreProjects r) <> pretty ns
61 pretty (Extend ext r) = collectExtends r <> pretty ext <> "}"
76 pretty (Extend ext r) = collectExtends r <> pretty ext <> "}"
77+ pretty (MakeRelationFromExprs Nothing (TupleExprs () tupExprs)) = "relation" <> prettyBracesList tupExprs
62− pretty (MakeRelationFromExprs (Just attrExprs) tupExprs) = "relation" <> (prettyBracesList attrExprs) <> prettyBracesList (F.toList tupExprs)
78+ pretty (MakeRelationFromExprs (Just attrExprs) (TupleExprs () tupExprs)) = "relation" <> prettyBracesList attrExprs <> prettyBracesList tupExprs
63 pretty (MakeStaticRelation attrs tupSet) = "relation" <> prettyBracesList (V.toList attrs) <> prettyBracesList (asList tupSet)
79 pretty (MakeStaticRelation attrs tupSet) = "relation" <> prettyBracesList (V.toList attrs) <> prettyBracesList (asList tupSet)
64 pretty (Union a b) = parens $ pretty' a <+> "union" <+> pretty' b
80 pretty (Union a b) = parens $ pretty' a <+> "union" <+> pretty' b
65 pretty (Join a b) = parens $ pretty' a <+> "join" <+> pretty' b
81 pretty (Join a b) = parens $ pretty' a <+> "join" <+> pretty' b
66 pretty (Rename n1 n2 relExpr) = parens $ pretty relExpr <+> "rename" <+> braces (pretty n1 <+> "as" <+> pretty n2)
82 pretty (Rename n1 n2 relExpr) = parens $ pretty relExpr <+> "rename" <+> braces (pretty n1 <+> "as" <+> pretty n2)
67 pretty (Difference a b) = parens $ pretty' a <+> "minus" <+> pretty' b
83 pretty (Difference a b) = parens $ pretty' a <+> "minus" <+> pretty' b
68− pretty (Group attrNames attrName relExpr) = parens $ pretty relExpr <+> "group" <+> parens ((pretty attrNames) <+> "as" <+> pretty attrName)
84+ pretty (Group attrNames attrName relExpr) = parens $ pretty relExpr <+> "group" <+> parens (pretty attrNames <+> "as" <+> pretty attrName)
69 pretty (Ungroup attrName relExpr) = parens $ pretty' relExpr <+> "ungroup" <+> pretty attrName
85 pretty (Ungroup attrName relExpr) = parens $ pretty' relExpr <+> "ungroup" <+> pretty attrName
70 pretty (Restrict resPreExpr relExpr) = parens $ pretty' relExpr <+> "where" <+> pretty resPreExpr
86 pretty (Restrict resPreExpr relExpr) = parens $ pretty' relExpr <+> "where" <+> pretty resPreExpr
71 pretty (With pairs a) = "with" <+> parensList (map (\(name,expr)-> pretty name <+> "as" <+> pretty expr) pairs) <+> pretty' a
87 pretty (With pairs a) = "with" <+> parensList (map (\(name,expr)-> pretty name <+> "as" <+> pretty expr) pairs) <+> pretty' a
72
88
73-- relvar:{a:=?}:{b:=?}:... in ADTs => relvar:{a:=?, b:=?, ...} in Doc ann
89-- relvar:{a:=?}:{b:=?}:... in ADTs => relvar:{a:=?, b:=?, ...} in Doc ann
74collectExtends :: RelationalExpr -> Doc ann
90collectExtends :: RelationalExpr -> Doc ann
75−collectExtends (Extend ext r) = (collectExtends r) <> (pretty ext) <> ", "
91+collectExtends (Extend ext r) = collectExtends r <> pretty ext <> ", "
76collectExtends r = pretty r <> ":{"
92collectExtends r = pretty r <> ":{"
77
93
78--relvar{a,b,c,...}{a,b,...}..{a} => relvar{a}
94--relvar{a,b,c,...}{a,b,...}..{a} => relvar{a}
79ignoreProjects :: RelationalExpr -> RelationalExpr
95ignoreProjects :: RelationalExpr -> RelationalExpr
80−ignoreProjects (Project ns r) = ignoreProjects r
96+ignoreProjects (Project _ r) = ignoreProjects r
81ignoreProjects r = r
97ignoreProjects r = r
82
98
99+prettyRelationalExpr :: RelationalExpr -> Doc n
100+prettyRelationalExpr (RelationVariable n _) = pretty n
101+prettyRelationalExpr r = parens (pretty r)
102+
83pretty' :: RelationalExpr -> Doc n
103pretty' :: RelationalExpr -> Doc n
84−pretty' (RelationVariable n _) = pretty n
104+pretty' = prettyRelationalExpr
85−pretty' r = parens (pretty r)
86
105
87instance Pretty AttributeNames where
106instance Pretty AttributeNames where
88 pretty (AttributeNames attrNames) = prettyBracesList (S.toList attrNames)
107 pretty (AttributeNames attrNames) = prettyBracesList (S.toList attrNames)
89− pretty (InvertedAttributeNames attrNames) = braces $ "all but" <+> (concatWith (surround ", ") (map pretty (S.toList attrNames)))
108+ pretty (InvertedAttributeNames attrNames) = braces $ "all but" <+> concatWith (surround ", ") (map pretty (S.toList attrNames))
90 pretty (RelationalExprAttributeNames relExpr) = braces $ "all from" <+> pretty relExpr
109 pretty (RelationalExprAttributeNames relExpr) = braces $ "all from" <+> pretty relExpr
91 pretty a = error $ show a ++ " is not implemented yet."
110 pretty a = error $ show a ++ " is not implemented yet."
92-- YuMing L.: I guess these two are used in evaluating relational expressions. So we won't be using them in pretty printer.
111-- YuMing L.: I guess these two are used in evaluating relational expressions. So we won't be using them in pretty printer.
@@ -95,8 +114,29 @@ instance Pretty AttributeNames where
95
114
96instance Pretty AttributeExpr where
115instance Pretty AttributeExpr where
97 pretty (NakedAttributeExpr attr) = pretty attr
116 pretty (NakedAttributeExpr attr) = pretty attr
98− pretty (AttributeAndTypeNameExpr name typeCons _) = pretty name <+> pretty (show typeCons) -- workaround
117+ pretty (AttributeAndTypeNameExpr name typeCons _) = pretty name <+> pretty typeCons
99−
118+
119+instance Pretty TypeConstructor where
120+ pretty (ADTypeConstructor tcName []) = pretty tcName
121+ pretty (ADTypeConstructor tcName tConsArgs) = pretty tcName <+> hsep (map pretty tConsArgs)
122+ pretty (PrimitiveTypeConstructor tcName atomType') = pretty tcName <+> pretty atomType'
123+ pretty (RelationAtomTypeConstructor attrExprs) = "relation" <> prettyBracesList attrExprs
124+ pretty (TypeVariable x) = pretty x
125+
126+instance Pretty AtomType where
127+ pretty IntAtomType = "Int"
128+ pretty IntegerAtomType = "Integer"
129+ pretty DoubleAtomType = "Double"
130+ pretty TextAtomType = "Text"
131+ pretty DayAtomType = "Day"
132+ pretty DateTimeAtomType = "DateTime"
133+ pretty ByteStringAtomType = "ByteString"
134+ pretty BoolAtomType = "Bool"
135+ pretty (RelationAtomType attrs) = "relation " <+> prettyBracesList (V.toList attrs)
136+ pretty (ConstructedAtomType tcName tvMap) = pretty tcName <+> hsep (map pretty (M.toList tvMap)) --order matters
137+ pretty RelationalExprAtomType = "RelationalExpr"
138+ pretty (TypeVariableType x) = pretty x
139+
100instance Pretty ExtendTupleExpr where
140instance Pretty ExtendTupleExpr where
101 pretty (AttributeExtendTupleExpr attrName atomExpr) = pretty attrName <> ":=" <> pretty atomExpr
141 pretty (AttributeExtendTupleExpr attrName atomExpr) = pretty attrName <> ":=" <> pretty atomExpr
102
142
src/lib/ProjectM36/Arbitrary.hs+5
@@ -9,6 +9,7 @@ import ProjectM36.AtomType
9import ProjectM36.Attribute (atomType)
9import ProjectM36.Attribute (atomType)
10import ProjectM36.DataConstructorDef as DCD
10import ProjectM36.DataConstructorDef as DCD
11import ProjectM36.DataTypes.Interval
11import ProjectM36.DataTypes.Interval
12+import ProjectM36.Relation
12import qualified Data.Vector as V
13import qualified Data.Vector as V
13import Data.Text (Text)
14import Data.Text (Text)
14import Test.QuickCheck
15import Test.QuickCheck
@@ -48,6 +49,10 @@ arbitrary' ByteStringAtomType =
48
49
49arbitrary' BoolAtomType =
50arbitrary' BoolAtomType =
50 Right . BoolAtom <$> lift (arbitrary :: Gen Bool)
51 Right . BoolAtom <$> lift (arbitrary :: Gen Bool)
52+
53+arbitrary' RelationalExprAtomType =
54+ pure (Right (RelationalExprAtom (ExistingRelation relationTrue))) -- don't bother with arbitrary relational expressions
55+
51arbitrary' constructedAtomType@(ConstructedAtomType tcName tvMap)
56arbitrary' constructedAtomType@(ConstructedAtomType tcName tvMap)
52 --special-casing for Interval type
57 --special-casing for Interval type
53 | isIntervalAtomType constructedAtomType = createArbitraryInterval (intervalSubType constructedAtomType)
58 | isIntervalAtomType constructedAtomType = createArbitraryInterval (intervalSubType constructedAtomType)
src/lib/ProjectM36/Atom.hs+1
@@ -20,6 +20,7 @@ atomToText (DayAtom i) = (T.pack . show) i
20atomToText (DateTimeAtom i) = (T.pack . show) i
20atomToText (DateTimeAtom i) = (T.pack . show) i
21atomToText (ByteStringAtom i) = (T.pack . show) i
21atomToText (ByteStringAtom i) = (T.pack . show) i
22atomToText (BoolAtom i) = (T.pack . show) i
22atomToText (BoolAtom i) = (T.pack . show) i
23+atomToText (RelationalExprAtom re) = (T.pack . show) re
23
24
24atomToText (RelationAtom i) = (T.pack . show) i
25atomToText (RelationAtom i) = (T.pack . show) i
25atomToText (ConstructedAtom dConsName typ atoms)
26atomToText (ConstructedAtom dConsName typ atoms)
src/lib/ProjectM36/AtomType.hs+1
@@ -442,6 +442,7 @@ isResolvedType typ =
442 DateTimeAtomType -> True
442 DateTimeAtomType -> True
443 ByteStringAtomType -> True
443 ByteStringAtomType -> True
444 BoolAtomType -> True
444 BoolAtomType -> True
445+ RelationalExprAtomType -> True
445 RelationAtomType attrs -> isResolvedAttributes attrs
446 RelationAtomType attrs -> isResolvedAttributes attrs
446 ConstructedAtomType _ tvMap -> all isResolvedType (M.elems tvMap)
447 ConstructedAtomType _ tvMap -> all isResolvedType (M.elems tvMap)
447 TypeVariableType _ -> False
448 TypeVariableType _ -> False
src/lib/ProjectM36/Atomable.hs+1
@@ -252,6 +252,7 @@ typeToTypeConstructor x@DayAtomType = PrimitiveTypeConstructor "Day" x
252typeToTypeConstructor x@DateTimeAtomType = PrimitiveTypeConstructor "DateTime" x
252typeToTypeConstructor x@DateTimeAtomType = PrimitiveTypeConstructor "DateTime" x
253typeToTypeConstructor x@ByteStringAtomType = PrimitiveTypeConstructor "ByteString" x
253typeToTypeConstructor x@ByteStringAtomType = PrimitiveTypeConstructor "ByteString" x
254typeToTypeConstructor x@BoolAtomType = PrimitiveTypeConstructor "Bool" x
254typeToTypeConstructor x@BoolAtomType = PrimitiveTypeConstructor "Bool" x
255+typeToTypeConstructor x@RelationalExprAtomType = PrimitiveTypeConstructor "RelationalExpr" x
255typeToTypeConstructor (RelationAtomType attrs)
256typeToTypeConstructor (RelationAtomType attrs)
256 = RelationAtomTypeConstructor $ map attrToAttrExpr $ V.toList attrs
257 = RelationAtomTypeConstructor $ map attrToAttrExpr $ V.toList attrs
257 where
258 where
src/lib/ProjectM36/Base.hs+61−26
@@ -27,6 +27,9 @@ import Data.Hashable.Time ()
27import Data.Typeable
27import Data.Typeable
28import Data.ByteString (ByteString)
28import Data.ByteString (ByteString)
29import qualified Data.List.NonEmpty as NE
29import qualified Data.List.NonEmpty as NE
30+import Data.Vector.Instances ()
31+import Data.Hashable.Generic
32+
30type StringType = Text
33type StringType = Text
31
34
32-- | Database atoms are the smallest, undecomposable units of a tuple. Common examples are integers, text, or unique identity keys.
35-- | Database atoms are the smallest, undecomposable units of a tuple. Common examples are integers, text, or unique identity keys.
@@ -39,8 +42,9 @@ data Atom = IntegerAtom Integer |
39 ByteStringAtom ByteString |
42 ByteStringAtom ByteString |
40 BoolAtom Bool |
43 BoolAtom Bool |
41 RelationAtom Relation |
44 RelationAtom Relation |
45+ RelationalExprAtom RelationalExpr | --used for returning inc deps
42 ConstructedAtom DataConstructorName AtomType [Atom]
46 ConstructedAtom DataConstructorName AtomType [Atom]
43− deriving (Eq, Show, Binary, Typeable, NFData, Generic)
47+ deriving (Eq, Show, Binary, Typeable, NFData, Generic, Read)
44
48
45instance Hashable Atom where
49instance Hashable Atom where
46 hashWithSalt salt (ConstructedAtom dConsName _ atoms) = salt `hashWithSalt` atoms
50 hashWithSalt salt (ConstructedAtom dConsName _ atoms) = salt `hashWithSalt` atoms
@@ -54,6 +58,7 @@ instance Hashable Atom where
54 hashWithSalt salt (ByteStringAtom bs) = salt `hashWithSalt` bs
58 hashWithSalt salt (ByteStringAtom bs) = salt `hashWithSalt` bs
55 hashWithSalt salt (BoolAtom b) = salt `hashWithSalt` b
59 hashWithSalt salt (BoolAtom b) = salt `hashWithSalt` b
56 hashWithSalt salt (RelationAtom r) = salt `hashWithSalt` r
60 hashWithSalt salt (RelationAtom r) = salt `hashWithSalt` r
61+ hashWithSalt salt (RelationalExprAtom re) = salt `hashWithSalt` re
57
62
58instance Binary UTCTime where
63instance Binary UTCTime where
59 put utc = put $ toRational (utcTimeToPOSIXSeconds utc)
64 put utc = put $ toRational (utcTimeToPOSIXSeconds utc)
@@ -77,13 +82,15 @@ data AtomType = IntAtomType |
77 BoolAtomType |
82 BoolAtomType |
78 RelationAtomType Attributes |
83 RelationAtomType Attributes |
79 ConstructedAtomType TypeConstructorName TypeVarMap |
84 ConstructedAtomType TypeConstructorName TypeVarMap |
85+ RelationalExprAtomType |
80 TypeVariableType TypeVarName
86 TypeVariableType TypeVarName
81 --wildcard used in Atom Functions and tuples for data constructors which don't provide all arguments to the type constructor
87 --wildcard used in Atom Functions and tuples for data constructors which don't provide all arguments to the type constructor
82− deriving (Eq, NFData, Generic, Binary, Show)
88+ deriving (Eq, NFData, Generic, Binary, Show, Read, Hashable)
83
89
84instance Ord AtomType where
90instance Ord AtomType where
85 compare = undefined
91 compare = undefined
86−
92+
93+-- this should probably be an ordered dictionary in order to be able to round-trip these arguments
87type TypeVarMap = M.Map TypeVarName AtomType
94type TypeVarMap = M.Map TypeVarName AtomType
88
95
89instance Hashable TypeVarMap where
96instance Hashable TypeVarMap where
@@ -98,7 +105,7 @@ isRelationAtomType _ = False
98type AttributeName = StringType
105type AttributeName = StringType
99
106
100-- | A relation's type is composed of attribute names and types.
107-- | A relation's type is composed of attribute names and types.
101−data Attribute = Attribute AttributeName AtomType deriving (Eq, Show, Generic, NFData, Binary)
108+data Attribute = Attribute AttributeName AtomType deriving (Eq, Show, Read, Generic, NFData, Binary)
102
109
103instance Hashable Attribute where
110instance Hashable Attribute where
104 hashWithSalt salt (Attribute attrName _) = hashWithSalt salt attrName
111 hashWithSalt salt (Attribute attrName _) = hashWithSalt salt attrName
@@ -116,7 +123,7 @@ sortedAttributesIndices :: Attributes -> [(Int, Attribute)]
116sortedAttributesIndices attrs = L.sortBy (\(_, Attribute name1 _) (_,Attribute name2 _) -> compare name1 name2) $ V.toList (V.indexed attrs)
123sortedAttributesIndices attrs = L.sortBy (\(_, Attribute name1 _) (_,Attribute name2 _) -> compare name1 name2) $ V.toList (V.indexed attrs)
117
124
118-- | The relation's tuple set is the body of the relation.
125-- | The relation's tuple set is the body of the relation.
119−newtype RelationTupleSet = RelationTupleSet { asList :: [RelationTuple] } deriving (Hashable, Show, Generic, Binary)
126+newtype RelationTupleSet = RelationTupleSet { asList :: [RelationTuple] } deriving (Hashable, Show, Generic, Binary, Read)
120
127
121instance Read Relation where
128instance Read Relation where
122 readsPrec = error "relation read not supported"
129 readsPrec = error "relation read not supported"
@@ -144,7 +151,7 @@ instance Hashable RelationTuple where
144 sortedTupVec = V.map (\(index, _) -> tupVec V.! index) $ V.fromList sortedAttrsIndices
151 sortedTupVec = V.map (\(index, _) -> tupVec V.! index) $ V.fromList sortedAttrsIndices
145
152
146-- | A tuple is a set of attributes mapped to their 'Atom' values.
153-- | A tuple is a set of attributes mapped to their 'Atom' values.
147−data RelationTuple = RelationTuple Attributes (V.Vector Atom) deriving (Show, Generic)
154+data RelationTuple = RelationTuple Attributes (V.Vector Atom) deriving (Show, Read, Generic)
148
155
149instance Binary RelationTuple
156instance Binary RelationTuple
150
157
@@ -219,12 +226,15 @@ data RelationalExprBase a =
219 --Summarize :: AtomExpr -> AttributeName -> RelationalExpr -> RelationalExpr -> RelationalExpr -- a special case of Extend
226 --Summarize :: AtomExpr -> AttributeName -> RelationalExpr -> RelationalExpr -> RelationalExpr -- a special case of Extend
220 --Evaluate relationalExpr with scoped views
227 --Evaluate relationalExpr with scoped views
221 With [(WithNameExprBase a, RelationalExprBase a)] (RelationalExprBase a)
228 With [(WithNameExprBase a, RelationalExprBase a)] (RelationalExprBase a)
222− deriving (Show, Eq, Generic, NFData, Foldable, Functor, Traversable)
229+ deriving (Show, Read, Eq, Generic, NFData, Foldable, Functor, Traversable)
223−
230+
231+instance Hashable RelationalExpr where
232+ hashWithSalt = genericHashWithSalt
233+
224instance Binary RelationalExpr
234instance Binary RelationalExpr
225
235
226data WithNameExprBase a = WithNameExpr RelVarName a
236data WithNameExprBase a = WithNameExpr RelVarName a
227− deriving (Show, Eq, Generic, NFData, Foldable, Functor, Traversable)
237+ deriving (Show, Read, Eq, Generic, NFData, Foldable, Functor, Traversable, Hashable)
228
238
229type WithNameExpr = WithNameExprBase ()
239type WithNameExpr = WithNameExprBase ()
230
240
@@ -248,15 +258,15 @@ type TypeVarName = StringType
248-- | Metadata definition for type constructors such as @data Either a b@.
258-- | Metadata definition for type constructors such as @data Either a b@.
249data TypeConstructorDef = ADTypeConstructorDef TypeConstructorName [TypeVarName] |
259data TypeConstructorDef = ADTypeConstructorDef TypeConstructorName [TypeVarName] |
250 PrimitiveTypeConstructorDef TypeConstructorName AtomType
260 PrimitiveTypeConstructorDef TypeConstructorName AtomType
251− deriving (Show, Generic, Binary, Eq, NFData)
261+ deriving (Show, Generic, Binary, Eq, NFData, Hashable, Read)
252
262
253-- | Found in data constructors and type declarations: Left (Either Int Text) | Right Int
263-- | Found in data constructors and type declarations: Left (Either Int Text) | Right Int
254type TypeConstructor = TypeConstructorBase ()
264type TypeConstructor = TypeConstructorBase ()
255data TypeConstructorBase a = ADTypeConstructor TypeConstructorName [TypeConstructor] |
265data TypeConstructorBase a = ADTypeConstructor TypeConstructorName [TypeConstructor] |
256− PrimitiveTypeConstructor TypeConstructorName AtomType |
266+ PrimitiveTypeConstructor TypeConstructorName AtomType |
257− RelationAtomTypeConstructor [AttributeExprBase a] |
267+ RelationAtomTypeConstructor [AttributeExprBase a] |
258− TypeVariable TypeVarName
268+ TypeVariable TypeVarName
259− deriving (Show, Generic, Binary, Eq, NFData)
269+ deriving (Show, Generic, Binary, Eq, NFData, Hashable, Read)
260
270
261type TypeConstructorMapping = [(TypeConstructorDef, DataConstructorDefs)]
271type TypeConstructorMapping = [(TypeConstructorDef, DataConstructorDefs)]
262
272
@@ -266,13 +276,13 @@ type DataConstructorName = StringType
266type AtomTypeName = StringType
276type AtomTypeName = StringType
267
277
268-- | Used to define a data constructor in a type constructor context such as @Left a | Right b@
278-- | Used to define a data constructor in a type constructor context such as @Left a | Right b@
269−data DataConstructorDef = DataConstructorDef DataConstructorName [DataConstructorDefArg] deriving (Eq, Show, Binary, Generic, NFData)
279+data DataConstructorDef = DataConstructorDef DataConstructorName [DataConstructorDefArg] deriving (Eq, Show, Binary, Generic, NFData, Hashable, Read)
270
280
271type DataConstructorDefs = [DataConstructorDef]
281type DataConstructorDefs = [DataConstructorDef]
272
282
273data DataConstructorDefArg = DataConstructorDefTypeConstructorArg TypeConstructor |
283data DataConstructorDefArg = DataConstructorDefTypeConstructorArg TypeConstructor |
274 DataConstructorDefTypeVarNameArg TypeVarName
284 DataConstructorDefTypeVarNameArg TypeVarName
275− deriving (Show, Generic, Binary, Eq, NFData)
285+ deriving (Show, Generic, Binary, Eq, NFData, Hashable, Read)
276
286
277type InclusionDependencies = M.Map IncDepName InclusionDependency
287type InclusionDependencies = M.Map IncDepName InclusionDependency
278type RelationVariables = M.Map RelVarName GraphRefRelationalExpr
288type RelationVariables = M.Map RelVarName GraphRefRelationalExpr
@@ -316,7 +326,7 @@ data DatabaseContext = DatabaseContext {
316type IncDepName = StringType
326type IncDepName = StringType
317
327
318-- | Inclusion dependencies represent every possible database constraint. Constraints enforce specific, arbitrarily-complex rules to which the database context's relation variables must adhere unconditionally.
328-- | Inclusion dependencies represent every possible database constraint. Constraints enforce specific, arbitrarily-complex rules to which the database context's relation variables must adhere unconditionally.
319−data InclusionDependency = InclusionDependency RelationalExpr RelationalExpr deriving (Show, Eq, Generic, NFData)
329+data InclusionDependency = InclusionDependency RelationalExpr RelationalExpr deriving (Show, Eq, Generic, NFData, Hashable, Read)
320
330
321instance Binary InclusionDependency
331instance Binary InclusionDependency
322
332
@@ -327,6 +337,9 @@ type DatabaseContextExprName = StringType
327
337
328type DatabaseContextExpr = DatabaseContextExprBase ()
338type DatabaseContextExpr = DatabaseContextExprBase ()
329
339
340+instance Hashable DatabaseContextExpr where
341+ hashWithSalt = genericHashWithSalt
342+
330type GraphRefDatabaseContextExpr = DatabaseContextExprBase GraphRefTransactionMarker
343type GraphRefDatabaseContextExpr = DatabaseContextExprBase GraphRefTransactionMarker
331
344
332instance Binary GraphRefDatabaseContextExpr
345instance Binary GraphRefDatabaseContextExpr
@@ -358,7 +371,10 @@ data DatabaseContextExprBase a =
358 ExecuteDatabaseContextFunction DatabaseContextFunctionName [AtomExprBase a] |
371 ExecuteDatabaseContextFunction DatabaseContextFunctionName [AtomExprBase a] |
359
372
360 MultipleExpr [DatabaseContextExprBase a]
373 MultipleExpr [DatabaseContextExprBase a]
361− deriving (Show, Eq, Generic)
374+ deriving (Show, Read, Eq, Generic, NFData)
375+
376+instance Hashable (M.Map AttributeName AtomExpr) where
377+ hashWithSalt salt m = salt `hashWithSalt` M.toList m
362
378
363instance Binary DatabaseContextExpr
379instance Binary DatabaseContextExpr
364
380
@@ -380,6 +396,8 @@ type DatabaseContextIOExpr = DatabaseContextIOExprBase ()
380
396
381type RestrictionPredicateExpr = RestrictionPredicateExprBase ()
397type RestrictionPredicateExpr = RestrictionPredicateExprBase ()
382
398
399+instance Hashable RestrictionPredicateExpr
400+
383type GraphRefRestrictionPredicateExpr = RestrictionPredicateExprBase GraphRefTransactionMarker
401type GraphRefRestrictionPredicateExpr = RestrictionPredicateExprBase GraphRefTransactionMarker
384
402
385-- | Restriction predicates are boolean algebra components which, when composed, indicate whether or not a tuple should be retained during a restriction (filtering) operation.
403-- | Restriction predicates are boolean algebra components which, when composed, indicate whether or not a tuple should be retained during a restriction (filtering) operation.
@@ -391,7 +409,7 @@ data RestrictionPredicateExprBase a =
391 RelationalExprPredicate (RelationalExprBase a) | --type must be same as true and false relations (no attributes)
409 RelationalExprPredicate (RelationalExprBase a) | --type must be same as true and false relations (no attributes)
392 AtomExprPredicate (AtomExprBase a) | --atom must evaluate to boolean
410 AtomExprPredicate (AtomExprBase a) | --atom must evaluate to boolean
393 AttributeEqualityPredicate AttributeName (AtomExprBase a) -- relationalexpr must result in relation with single tuple
411 AttributeEqualityPredicate AttributeName (AtomExprBase a) -- relationalexpr must result in relation with single tuple
394− deriving (Show, Eq, Generic, NFData, Foldable, Functor, Traversable)
412+ deriving (Show, Read, Eq, Generic, NFData, Foldable, Functor, Traversable)
395
413
396instance Binary RestrictionPredicateExpr
414instance Binary RestrictionPredicateExpr
397
415
@@ -454,6 +472,8 @@ instance Ord Transaction where
454
472
455type AtomExpr = AtomExprBase ()
473type AtomExpr = AtomExprBase ()
456
474
475+instance Hashable AtomExpr
476+
457type GraphRefAtomExpr = AtomExprBase GraphRefTransactionMarker
477type GraphRefAtomExpr = AtomExprBase GraphRefTransactionMarker
458
478
459-- | An atom expression represents an action to take when extending a relation or when statically defining a relation or a new tuple.
479-- | An atom expression represents an action to take when extending a relation or when statically defining a relation or a new tuple.
@@ -462,15 +482,18 @@ data AtomExprBase a = AttributeAtomExpr AttributeName |
462 FunctionAtomExpr AtomFunctionName [AtomExprBase a] a |
482 FunctionAtomExpr AtomFunctionName [AtomExprBase a] a |
463 RelationAtomExpr (RelationalExprBase a) |
483 RelationAtomExpr (RelationalExprBase a) |
464 ConstructedAtomExpr DataConstructorName [AtomExprBase a] a
484 ConstructedAtomExpr DataConstructorName [AtomExprBase a] a
465− deriving (Eq,Show,Generic, NFData, Foldable, Functor, Traversable)
485+ deriving (Eq, Show, Read, Generic, NFData, Foldable, Functor, Traversable)
466
486
467instance Binary AtomExpr
487instance Binary AtomExpr
468
488
469-- | Used in tuple creation when creating a relation.
489-- | Used in tuple creation when creating a relation.
470data ExtendTupleExprBase a = AttributeExtendTupleExpr AttributeName (AtomExprBase a)
490data ExtendTupleExprBase a = AttributeExtendTupleExpr AttributeName (AtomExprBase a)
471− deriving (Show, Eq, Generic, NFData, Foldable, Functor, Traversable)
491+ deriving (Show, Read, Eq, Generic, NFData, Foldable, Functor, Traversable)
472
492
473type ExtendTupleExpr = ExtendTupleExprBase ()
493type ExtendTupleExpr = ExtendTupleExprBase ()
494+
495+instance Hashable ExtendTupleExpr
496+
474type GraphRefExtendTupleExpr = ExtendTupleExprBase GraphRefTransactionMarker
497type GraphRefExtendTupleExpr = ExtendTupleExprBase GraphRefTransactionMarker
475
498
476instance Binary ExtendTupleExpr
499instance Binary ExtendTupleExpr
@@ -519,7 +542,12 @@ data AttributeNamesBase a = AttributeNames (S.Set AttributeName) |
519 UnionAttributeNames (AttributeNamesBase a) (AttributeNamesBase a) |
542 UnionAttributeNames (AttributeNamesBase a) (AttributeNamesBase a) |
520 IntersectAttributeNames (AttributeNamesBase a) (AttributeNamesBase a) |
543 IntersectAttributeNames (AttributeNamesBase a) (AttributeNamesBase a) |
521 RelationalExprAttributeNames (RelationalExprBase a) -- use attribute names from the relational expression's type
544 RelationalExprAttributeNames (RelationalExprBase a) -- use attribute names from the relational expression's type
522− deriving (Eq, Show, Generic, NFData, Foldable, Functor, Traversable)
545+ deriving (Eq, Show, Read, Generic, NFData, Foldable, Functor, Traversable)
546+
547+instance Hashable AttributeNames
548+
549+instance Hashable (S.Set AttributeName) where
550+ hashWithSalt salt s = salt `hashWithSalt` S.toList s
523
551
524type AttributeNames = AttributeNamesBase ()
552type AttributeNames = AttributeNamesBase ()
525
553
@@ -539,12 +567,14 @@ type GraphRefAttributeExpr = AttributeExprBase GraphRefTransactionMarker
539-- | Create attributes dynamically.
567-- | Create attributes dynamically.
540data AttributeExprBase a = AttributeAndTypeNameExpr AttributeName TypeConstructor a |
568data AttributeExprBase a = AttributeAndTypeNameExpr AttributeName TypeConstructor a |
541 NakedAttributeExpr Attribute
569 NakedAttributeExpr Attribute
542− deriving (Eq, Show, Generic, Binary, NFData, Foldable, Functor, Traversable)
570+ deriving (Eq, Show, Read, Generic, Binary, NFData, Foldable, Functor, Traversable, Hashable)
543
571
544-- | Dynamically create a tuple from attribute names and 'AtomExpr's.
572-- | Dynamically create a tuple from attribute names and 'AtomExpr's.
545newtype TupleExprBase a = TupleExpr (M.Map AttributeName (AtomExprBase a))
573newtype TupleExprBase a = TupleExpr (M.Map AttributeName (AtomExprBase a))
546− deriving (Eq, Show, Generic, NFData, Foldable, Functor, Traversable)
574+ deriving (Eq, Show, Read, Generic, NFData, Foldable, Functor, Traversable)
547−
575+
576+instance Hashable TupleExpr
577+
548instance Binary TupleExpr
578instance Binary TupleExpr
549
579
550type TupleExpr = TupleExprBase ()
580type TupleExpr = TupleExprBase ()
@@ -552,7 +582,10 @@ type TupleExpr = TupleExprBase ()
552type GraphRefTupleExpr = TupleExprBase GraphRefTransactionMarker
582type GraphRefTupleExpr = TupleExprBase GraphRefTransactionMarker
553
583
554data TupleExprsBase a = TupleExprs a [TupleExprBase a]
584data TupleExprsBase a = TupleExprs a [TupleExprBase a]
555− deriving (Eq, Show, Generic, NFData, Foldable, Functor, Traversable)
585+ deriving (Eq, Show, Read, Generic, NFData, Foldable, Functor, Traversable)
586+
587+instance Hashable TupleExprs where
588+ hashWithSalt = genericHashWithSalt
556
589
557type GraphRefTupleExprs = TupleExprsBase GraphRefTransactionMarker
590type GraphRefTupleExprs = TupleExprsBase GraphRefTransactionMarker
558
591
@@ -604,6 +637,7 @@ attrTypeVars (Attribute _ aType) = case aType of
604 DateTimeAtomType -> S.empty
637 DateTimeAtomType -> S.empty
605 ByteStringAtomType -> S.empty
638 ByteStringAtomType -> S.empty
606 BoolAtomType -> S.empty
639 BoolAtomType -> S.empty
640+ RelationalExprAtomType -> S.empty
607 (RelationAtomType attrs) -> S.unions (map attrTypeVars (V.toList attrs))
641 (RelationAtomType attrs) -> S.unions (map attrTypeVars (V.toList attrs))
608 (ConstructedAtomType _ tvMap) -> M.keysSet tvMap
642 (ConstructedAtomType _ tvMap) -> M.keysSet tvMap
609 (TypeVariableType nam) -> S.singleton nam
643 (TypeVariableType nam) -> S.singleton nam
@@ -627,6 +661,7 @@ atomTypeVars DayAtomType = S.empty
627atomTypeVars DateTimeAtomType = S.empty
661atomTypeVars DateTimeAtomType = S.empty
628atomTypeVars ByteStringAtomType = S.empty
662atomTypeVars ByteStringAtomType = S.empty
629atomTypeVars BoolAtomType = S.empty
663atomTypeVars BoolAtomType = S.empty
664+atomTypeVars RelationalExprAtomType = S.empty
630atomTypeVars (RelationAtomType attrs) = S.unions (map attrTypeVars (V.toList attrs))
665atomTypeVars (RelationAtomType attrs) = S.unions (map attrTypeVars (V.toList attrs))
631atomTypeVars (ConstructedAtomType _ tvMap) = M.keysSet tvMap
666atomTypeVars (ConstructedAtomType _ tvMap) = M.keysSet tvMap
632atomTypeVars (TypeVariableType nam) = S.singleton nam
667atomTypeVars (TypeVariableType nam) = S.singleton nam
src/lib/ProjectM36/DataTypes/Interval.hs+2
@@ -37,6 +37,7 @@ supportsInterval typ = case typ of
37 BoolAtomType -> False
37 BoolAtomType -> False
38 RelationAtomType _ -> False
38 RelationAtomType _ -> False
39 ConstructedAtomType _ _ -> False --once we support an interval-style typeclass, we might enable this
39 ConstructedAtomType _ _ -> False --once we support an interval-style typeclass, we might enable this
40+ RelationalExprAtomType -> False
40 TypeVariableType _ -> False
41 TypeVariableType _ -> False
41
42
42supportsOrdering :: AtomType -> Bool
43supportsOrdering :: AtomType -> Bool
@@ -50,6 +51,7 @@ supportsOrdering typ = case typ of
50 ByteStringAtomType -> False
51 ByteStringAtomType -> False
51 BoolAtomType -> False
52 BoolAtomType -> False
52 RelationAtomType _ -> False
53 RelationAtomType _ -> False
54+ RelationalExprAtomType -> False
53 ConstructedAtomType _ _ -> False --once we support an interval-style typeclass, we might enable this
55 ConstructedAtomType _ _ -> False --once we support an interval-style typeclass, we might enable this
54 TypeVariableType _ -> False
56 TypeVariableType _ -> False
55
57
src/lib/ProjectM36/DataTypes/Primitive.hs+1
@@ -42,3 +42,4 @@ atomTypeForAtom (ByteStringAtom _) = ByteStringAtomType
42atomTypeForAtom (BoolAtom _) = BoolAtomType
42atomTypeForAtom (BoolAtom _) = BoolAtomType
43atomTypeForAtom (RelationAtom (Relation attrs _)) = RelationAtomType attrs
43atomTypeForAtom (RelationAtom (Relation attrs _)) = RelationAtomType attrs
44atomTypeForAtom (ConstructedAtom _ aType _) = aType
44atomTypeForAtom (ConstructedAtom _ aType _) = aType
45+atomTypeForAtom (RelationalExprAtom _) = RelationalExprAtomType
src/lib/ProjectM36/DataTypes/Sorting.hs+1
@@ -24,6 +24,7 @@ isSortableAtomType typ = case typ of
24 DateTimeAtomType -> True
24 DateTimeAtomType -> True
25 ByteStringAtomType -> False
25 ByteStringAtomType -> False
26 BoolAtomType -> True
26 BoolAtomType -> True
27+ RelationalExprAtomType -> False
27 RelationAtomType _ -> False
28 RelationAtomType _ -> False
28 ConstructedAtomType _ _ -> False
29 ConstructedAtomType _ _ -> False
29 TypeVariableType _ -> False
30 TypeVariableType _ -> False
src/lib/ProjectM36/InclusionDependency.hs+4−7
@@ -4,19 +4,16 @@ import ProjectM36.Attribute
4import ProjectM36.Error
4import ProjectM36.Error
5import ProjectM36.Relation
5import ProjectM36.Relation
6import qualified Data.Map as M
6import qualified Data.Map as M
7−import qualified Data.Text as T
8−import ProjectM36.PrettyPrinter
9−import Data.Text.Prettyprint.Doc
10
7
11inclusionDependenciesAsRelation :: InclusionDependencies -> Either RelationalError Relation
8inclusionDependenciesAsRelation :: InclusionDependencies -> Either RelationalError Relation
12inclusionDependenciesAsRelation incDeps =
9inclusionDependenciesAsRelation incDeps =
13 mkRelationFromList attrs (map incDepAsAtoms (M.toList incDeps))
10 mkRelationFromList attrs (map incDepAsAtoms (M.toList incDeps))
14 where
11 where
15 attrs = attributesFromList [Attribute "name" TextAtomType,
12 attrs = attributesFromList [Attribute "name" TextAtomType,
16− Attribute "sub" TextAtomType,
13+ Attribute "sub" RelationalExprAtomType,
17− Attribute "super" TextAtomType
14+ Attribute "super" RelationalExprAtomType
18 ]
15 ]
19 incDepAsAtoms (name, InclusionDependency exprA exprB) = [TextAtom name,
16 incDepAsAtoms (name, InclusionDependency exprA exprB) = [TextAtom name,
20− TextAtom (T.pack (show (pretty exprA))),
17+ RelationalExprAtom exprA,
21− TextAtom (T.pack (show (pretty exprB)))]
18+ RelationalExprAtom exprB]
22
19
src/lib/ProjectM36/Relation/Parse/CSV.hs+5
@@ -83,6 +83,11 @@ parseCSVAtomP _ _ BoolAtomType = do
83 case readMaybe bString of
83 case readMaybe bString of
84 Nothing -> fail ("invalid BoolAtom string: " ++ bString)
84 Nothing -> fail ("invalid BoolAtom string: " ++ bString)
85 Just b -> pure (Right (BoolAtom b))
85 Just b -> pure (Right (BoolAtom b))
86+parseCSVAtomP _ _ RelationalExprAtomType = do
87+ reString <- T.unpack <$> takeToEndOfData
88+ case readMaybe reString of
89+ Nothing -> fail ("invalid RelationalExprAtom string: " ++ reString)
90+ Just b -> pure (Right (RelationalExprAtom b))
86parseCSVAtomP attrName tConsMap typ@(ConstructedAtomType _ tvmap)
91parseCSVAtomP attrName tConsMap typ@(ConstructedAtomType _ tvmap)
87 | isIntervalAtomType typ = do
92 | isIntervalAtomType typ = do
88 begin <- (APT.char '[' >> pure False) <|> (APT.char '(' >> pure True)
93 begin <- (APT.char '[' >> pure False) <|> (APT.char '(' >> pure True)
test/PrettyPrinter.hsdeleted−22
@@ -1,22 +0,0 @@
1−{-# LANGUAGE OverloadedStrings #-}
2−import Test.HUnit
3−import ProjectM36.Base
4−import ProjectM36.PrettyPrinter
5−import qualified Data.Vector as V
6−import System.Exit
7−import Data.Text
8−import ProjectM36.Relation
9−import Data.Text.Prettyprint.Doc
10−testList :: Test
11−testList = TestList [
12− testPretty "true" (ExistingRelation (Relation V.empty (RelationTupleSet [RelationTuple V.empty V.empty]))),
13− testPretty "false" (ExistingRelation (Relation V.empty (RelationTupleSet []))),
14− testPretty "true:{a:=1, b:=1}" (Extend (AttributeExtendTupleExpr "b" (NakedAtomExpr (IntAtom 1))) (Extend (AttributeExtendTupleExpr "a" (NakedAtomExpr (IntAtom 1))) (ExistingRelation relationTrue)))]
15−
16−main :: IO ()
17−main = do
18− tcounts <- runTestTT testList
19− if errors tcounts + failures tcounts > 0 then exitFailure else exitSuccess
20−
21−testPretty :: String -> RelationalExpr -> Test
22−testPretty relExprText relExprADT = TestCase $ assertEqual relExprText (show (pretty relExprADT)) (show (pretty relExprText))
test/TutorialD/Printer.hsnew file+47
@@ -0,0 +1,47 @@
1+{-# LANGUAGE OverloadedStrings #-}
2+import Test.HUnit
3+import ProjectM36.Base
4+import System.Exit
5+import Data.Text.Prettyprint.Doc
6+import Data.Map (fromList)
7+import TutorialD.Printer ()
8+import TutorialD.Interpreter.RelationalExpr
9+import Text.Megaparsec
10+import Data.Text (pack)
11+
12+testList :: Test
13+testList = TestList [
14+ testPretty "true" (RelationVariable "true" ()),
15+ testPretty "relation{tuple{a 3, b \"x\"}, tuple{a 4, b \"y\"}}" (MakeRelationFromExprs Nothing (TupleExprs () [TupleExpr (fromList [("a",NakedAtomExpr (IntegerAtom 3)),("b",NakedAtomExpr (TextAtom "x"))]),TupleExpr (fromList [("a",NakedAtomExpr (IntegerAtom 4)),("b",NakedAtomExpr (TextAtom "y"))])])),
16+ testPretty "true:{a:=1, b:=1}" (Extend (AttributeExtendTupleExpr "b" (NakedAtomExpr (IntegerAtom 1))) (Extend (AttributeExtendTupleExpr "a" (NakedAtomExpr (IntegerAtom 1))) (RelationVariable "true" ()))),
17+ testPretty "relation{tuple{a fromGregorian(2014, 2, 4)}}" (MakeRelationFromExprs Nothing (TupleExprs () [TupleExpr (fromList [("a",FunctionAtomExpr "fromGregorian" [NakedAtomExpr (IntegerAtom 2014),NakedAtomExpr (IntegerAtom 2),NakedAtomExpr (IntegerAtom 4)] ())])])),
18+ testPretty "relation{tuple{a bytestring(\"dGVzdGRhdGE=\")}}" (MakeRelationFromExprs Nothing (TupleExprs () [TupleExpr (fromList [("a",FunctionAtomExpr "bytestring" [NakedAtomExpr (TextAtom "dGVzdGRhdGE=")] ())])])),
19+ testPretty "relation{tuple{a t}}" (MakeRelationFromExprs Nothing (TupleExprs () [TupleExpr (fromList [("a",NakedAtomExpr (BoolAtom True))])])),
20+ testPretty "relation{tuple{a Cons 4 (Cons 5 Empty)}}" (MakeRelationFromExprs Nothing (TupleExprs () [TupleExpr (fromList [("a",ConstructedAtomExpr "Cons" [NakedAtomExpr (IntegerAtom 4),ConstructedAtomExpr "Cons" [NakedAtomExpr (IntegerAtom 5),ConstructedAtomExpr "Empty" [] ()] ()] ())])])),
21+ testPretty "relation{a Int, b Text, c Bool}{}" (MakeRelationFromExprs (Just [AttributeAndTypeNameExpr "a" (ADTypeConstructor "Int" []) (),AttributeAndTypeNameExpr "b" (ADTypeConstructor "Text" []) (),AttributeAndTypeNameExpr "c" (ADTypeConstructor "Bool" []) ()]) (TupleExprs () [])),
22+ testPretty "relation{a relation{b Int}}{}" (MakeRelationFromExprs (Just [AttributeAndTypeNameExpr "a" (RelationAtomTypeConstructor [AttributeAndTypeNameExpr "b" (ADTypeConstructor "Int" []) ()]) ()]) (TupleExprs () []))
23+ ]
24+
25+main :: IO ()
26+main = do
27+ tcounts <- runTestTT testList
28+ if errors tcounts + failures tcounts > 0 then exitFailure else exitSuccess
29+
30+testPretty :: String -> RelationalExpr -> Test
31+testPretty tutdStr relExprADT =
32+ TestCase $ do
33+ let relExprStr = show (pretty relExprADT)
34+ print relExprStr
35+ roundTrip <- parseRelExpr relExprStr
36+ {-tutdIn <- parseRelExpr tutdStr
37+ print ("tutd parsed", tutdIn)-}
38+ assertEqual ("pretty ADT " <> tutdStr) tutdStr relExprStr
39+ assertEqual ("round-trip " <> tutdStr) relExprADT roundTrip
40+
41+--round trip tutoriald
42+parseRelExpr :: String -> IO RelationalExpr
43+parseRelExpr tutdStr =
44+ case parse relExprP "test" (pack tutdStr) of
45+ Left err ->
46+ assertFailure (errorBundlePretty err)
47+ Right parsed -> pure parsed