on master help sign in
randomize tuple order in tutd terminal output

resolves #53

commitb656f5768ff40aa00d0f4bbfaff123cbdcc36ade authorAgentM <agentm@themactionfaction.com> dateMon 14 Nov 2016, 11:47 (10 years ago) parente4ee8e0
3 files changed+25−10
project-m36.cabal+12−9 src/bin/TutorialD/Interpreter/Base.hs+6−1 src/lib/ProjectM36/Relation.hs+7
project-m36.cabal+12−9
@@ -21,6 +21,8 @@ Library
2121 ,hashable
2222 ,haskeline
2323 ,directory
24+ ,MonadRandom
25+ ,random-shuffle
2426 --critical uuid bug in lesser versions https://www.reddit.com/r/haskell/comments/4myot5/psa_make_sure_to_use_uuid_1312/
2527 ,uuid >= 1.3.12
2628 ,cassava ==0.4.*
@@ -144,6 +146,7 @@ Executable tutd
144146 mtl,
145147 uuid,
146148 deepseq-generics,
149+ MonadRandom,
147150 vector,
148151 text,
149152 vector-binary-instances,
@@ -255,7 +258,7 @@ Executable project-m36-server
255258Executable bigrel
256259 Default-Language: Haskell2010
257260 Default-Extensions: OverloadedStrings
258− Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, network-transport-tcp, distributed-process, distributed-process-extras, distributed-process-client-server, uuid, stm, deepseq, deepseq-generics, binary, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, megaparsec, text, base64-bytestring, data-interval, filepath, optparse-applicative, stm-containers, list-t, ghc, ghc-paths, transformers, project-m36 == 0.1
261+ Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, network-transport-tcp, distributed-process, distributed-process-extras, distributed-process-client-server, uuid, stm, deepseq, deepseq-generics, binary, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, megaparsec, text, base64-bytestring, data-interval, filepath, optparse-applicative, stm-containers, list-t, ghc, ghc-paths, transformers, project-m36 == 0.1, MonadRandom
259262 Other-Modules: TutorialD.Interpreter.Base,
260263 TutorialD.Interpreter.DatabaseContextExpr,
261264 TutorialD.Interpreter.RelationalExpr,
@@ -271,7 +274,7 @@ Test-Suite test-tutoriald
271274 Default-Extensions: OverloadedStrings
272275 type: exitcode-stdio-1.0
273276 main-is: test/TutorialD/Interpreter.hs
274− Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, network-transport-tcp, distributed-process, distributed-process-extras, distributed-process-client-server, 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 == 0.1
277+ Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, network-transport-tcp, distributed-process, distributed-process-extras, distributed-process-client-server, 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 == 0.1, MonadRandom
275278 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
276279 GHC-Options: -Wall
277280 Hs-Source-Dirs: ./src/bin, ., test
@@ -283,7 +286,7 @@ Test-Suite test-tutoriald-atomfunctionscript
283286 type: exitcode-stdio-1.0
284287 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
285288 main-is: test/TutorialD/Interpreter/AtomFunctionScript.hs
286− Build-Depends: base, HUnit, project-m36 == 0.1, uuid, containers, megaparsec, text, vector, directory, bytestring, mtl, haskeline
289+ Build-Depends: base, HUnit, project-m36 == 0.1, uuid, containers, megaparsec, text, vector, directory, bytestring, mtl, haskeline, MonadRandom
287290 GHC-Options: -Wall
288291 Hs-Source-Dirs: ./src/bin, ./test, .
289292 CPP-Options: -DPROJECTM36_VERSION="v0.1"
@@ -310,7 +313,7 @@ Test-Suite test-transactiongraph-persist
310313 Default-Extensions: OverloadedStrings
311314 type: exitcode-stdio-1.0
312315 main-is: test/TransactionGraph/Persist.hs
313− Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, network-transport-tcp, distributed-process, distributed-process-extras, distributed-process-client-server, uuid, stm, deepseq, deepseq-generics, binary, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, megaparsec, text, base64-bytestring, data-interval, filepath, stm-containers, project-m36 == 0.1
316+ Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, network-transport-tcp, distributed-process, distributed-process-extras, distributed-process-client-server, uuid, stm, deepseq, deepseq-generics, binary, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, megaparsec, text, base64-bytestring, data-interval, filepath, stm-containers, project-m36 == 0.1, MonadRandom
314317 Other-Modules: TutorialD.Interpreter.Base, TutorialD.Interpreter.RelationalExpr, TutorialD.Interpreter.Types, TutorialD.Interpreter.DatabaseContextExpr, TutorialD.Interpreter.Import.BasicExamples
315318 Hs-Source-Dirs: ., ./src/bin
316319 GHC-Options: -Wall
@@ -329,7 +332,7 @@ Test-Suite test-tutoriald-import-tutoriald
329332 Default-Extensions: OverloadedStrings
330333 type: exitcode-stdio-1.0
331334 main-is: test/TutorialD/Interpreter/Import/TutorialD.hs
332− Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, network-transport-tcp, distributed-process, distributed-process-extras, distributed-process-client-server, uuid, stm, deepseq, deepseq-generics, binary, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, megaparsec, text, base64-bytestring, data-interval, filepath, stm-containers, project-m36 == 0.1
335+ Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, network-transport-tcp, distributed-process, distributed-process-extras, distributed-process-client-server, uuid, stm, deepseq, deepseq-generics, binary, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, megaparsec, text, base64-bytestring, data-interval, filepath, stm-containers, project-m36 == 0.1, MonadRandom
333336 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
334337 GHC-Options: -Wall
335338 Hs-Source-Dirs: ., ./src/bin
@@ -381,7 +384,7 @@ Test-Suite test-server
381384Executable Example-SimpleClient
382385 Default-Language: Haskell2010
383386 Default-Extensions: OverloadedStrings
384− Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, network-transport-tcp, distributed-process, distributed-process-extras, distributed-process-client-server, 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, ghc, ghc-paths, project-m36 == 0.1
387+ Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, network-transport-tcp, distributed-process, distributed-process-extras, distributed-process-client-server, 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, ghc, ghc-paths, project-m36 == 0.1, MonadRandom
385388 Main-Is: examples/SimpleClient.hs
386389 GHC-Options: -Wall
387390
@@ -400,14 +403,14 @@ Test-Suite test-scripts
400403 Default-Extensions: OverloadedStrings
401404 type: exitcode-stdio-1.0
402405 main-is: test/scripts.hs
403− Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, network-transport-tcp, distributed-process, distributed-process-extras, distributed-process-client-server, 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, project-m36 == 0.1
406+ Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, network-transport-tcp, distributed-process, distributed-process-extras, distributed-process-client-server, 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, project-m36 == 0.1, MonadRandom
404407 Other-Modules: TutorialD.Interpreter.Base, TutorialD.Interpreter.DatabaseContextExpr, TutorialD.Interpreter.Import.Base, TutorialD.Interpreter.Import.TutorialD, TutorialD.Interpreter.RelationalExpr, TutorialD.Interpreter.Types, TutorialD.Interpreter.Import.BasicExamples
405408 GHC-Options: -Wall
406409 Hs-Source-Dirs: ., ./src/bin
407410
408411Executable project-m36-websocket-server
409412 Default-Language: Haskell2010
410− Build-Depends: base, aeson, path-pieces, either, conduit, http-api-data, template-haskell, persistent-template, websockets, aeson, uuid-aeson, optparse-applicative, project-m36 == 0.1, containers, bytestring, text, vector, uuid, megaparsec, haskeline, mtl, directory, base64-bytestring
413+ Build-Depends: base, aeson, path-pieces, either, conduit, http-api-data, template-haskell, persistent-template, websockets, aeson, uuid-aeson, optparse-applicative, project-m36 == 0.1, containers, bytestring, text, vector, uuid, megaparsec, haskeline, mtl, directory, base64-bytestring, MonadRandom
411414 Main-Is: ProjectM36/Server/WebSocket/websocket-server.hs
412415 Other-Modules: ProjectM36.Client.Json, ProjectM36.Server.RemoteCallTypes.Json, ProjectM36.Server.WebSocket, 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.TransactionGraphOperator, TutorialD.Interpreter.Types, TutorialD.Interpreter.TransGraphRelationalOperator
413416 GHC-Options: -Wall
@@ -419,7 +422,7 @@ Test-Suite test-websocket-server
419422 Default-Language: Haskell2010
420423 type: exitcode-stdio-1.0
421424 main-is: test/Server/WebSocket.hs
422− Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, network-transport-tcp, distributed-process, distributed-process-extras, distributed-process-client-server, 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, uuid-aeson, project-m36 == 0.1
425+ Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, network-transport-tcp, distributed-process, distributed-process-extras, distributed-process-client-server, 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, uuid-aeson, project-m36 == 0.1, MonadRandom
423426 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
424427 Default-Extensions: OverloadedStrings
425428 GHC-Options: -Wall
src/bin/TutorialD/Interpreter/Base.hs+6−1
@@ -16,6 +16,8 @@ import GHC.Generics
1616import Data.Monoid
1717import Control.Monad (void)
1818import qualified Data.UUID as U
19+import Control.Monad.Random
20+import ProjectM36.Relation
1921
2022displayOpResult :: TutorialDOperatorResult -> IO ()
2123displayOpResult QuitResult = return ()
@@ -24,7 +26,10 @@ displayOpResult (DisplayIOResult ioout) = ioout
2426displayOpResult (DisplayErrorResult err) = let outputf = if T.length err > 0 && T.last err /= '\n' then TIO.hPutStrLn else TIO.hPutStr in
2527 outputf stderr ("ERR: " <> err)
2628displayOpResult QuietSuccessResult = return ()
27−displayOpResult (DisplayRelationResult rel) = TIO.putStrLn (showRelation rel)
29+displayOpResult (DisplayRelationResult rel) = do
30+ gen <- newStdGen
31+ let randomlySortedRel = evalRand (randomizeTupleOrder rel) gen
32+ TIO.putStrLn (showRelation randomlySortedRel)
2833displayOpResult (DisplayParseErrorResult promptLength err) = TIO.putStrLn pointyString >> TIO.putStrLn ("ERR:" <> T.pack (show err))
2934 where
3035 pointyString = T.justifyRight (promptLength + (sourceColumn (errorPos err))) '_' "^"
src/lib/ProjectM36/Relation.hs+7
@@ -17,6 +17,8 @@ import qualified ProjectM36.TypeConstructorDef as TCD
1717import qualified ProjectM36.DataConstructorDef as DCD
1818import qualified Data.Text as T
1919import Data.Either (isRight)
20+import System.Random.Shuffle
21+import Control.Monad.Random
2022--import Debug.Trace
2123
2224attributes :: Relation -> Attributes
@@ -309,4 +311,9 @@ relationVariablesAsRelation relVarMap = mkRelationFromList attrs tups
309311 Right rel -> RelationAtom rel
310312 attrAtoms a = [TextAtom (A.attributeName a), TextAtom (prettyAtomType (A.atomType a))]
311313
314+-- | Randomly resort the tuples. This is useful for emphasizing that two relations are equal even when they are printed to the console in different orders.
315+randomizeTupleOrder :: MonadRandom m => Relation -> m Relation
316+randomizeTupleOrder (Relation attrs tupSet) = do
317+ newTupSet <- shuffleM (asList tupSet)
318+ pure (Relation attrs (RelationTupleSet newTupSet))
312319