Skip to content
Snippets Groups Projects
Commit 3c39d92e authored by Btadford's avatar Btadford
Browse files

Problem2Solved

parent 598b548e
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@ import CQLGrammar
import System.Environment
import Control.Exception
import System.IO
import Data.List
main :: IO()
main = catch readTest noLex
......@@ -31,6 +32,7 @@ evaluateCQL f = do putStrLn ("Placeholder to evaluate")
-- For column n you get the nth element from each row in TableType
type TableType = [[String]]
type Tables = [(String, TableType)]
type RowType = [String]
-- Recurses through Function types to evaluate
......@@ -38,11 +40,11 @@ evaluateFunc :: Function -> Tables -> IO TableType
evaluateFunc (TmSeq x@(TmLet var def) f2) tables = do table <- createDef var def
let tables' = table : tables
evaluateFunc f2 tables'
evaluateFunc (TmSeq f1 f2) tables = evaluateFunc f1 tables
evaluateFunc (TmJoin x y) tables = do x' <- selectFromTable x tables
y' <- selectFromTable y tables
let result = joinTables x' y'
return result
--evaluateFunc (TmSeq f1 f2) tables = evaluateFunc f1 tables
--evaluateFunc (TmJoin x y) tables = do x' <- selectFromTable x tables
-- y' <- selectFromTable y tables
-- let result = joinTables x' y'
-- return result
-- Selects the desired data from a table
selectFromTable :: Select -> Tables -> IO [TableType]
......@@ -72,6 +74,20 @@ conjunction table1 [] = []
conjunction [] table2 = []
conjunction table1 table2 = (map (++ head table2) table1 ) ++ conjunction (table1) (tail table2)
-- getRow table1 = head table1
permuteArray :: TableType -> TableType
permuteArray [] = []
permuteArray table1 = sort ( (permuteAndMatch (head table1)) : permuteArray (tail table1) )
permuteAndMatch :: RowType -> RowType
permuteAndMatch [] = []
permuteAndMatch row | length rowString /= 3 = []
| rowString !! 0 == rowString !! 1 = [ ([rowString !! 2] ++ [rowString !! 0] )]
| otherwise = []
where rowString = head row
-- TODO: Joins two lists of tables together
--joinTables :: [TableType] -> [TableType] -> TableType
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment