Migrated String to Text
This commit is contained in:
parent
717cfd7b34
commit
27c4349f53
7
dist/build/autogen/cabal_macros.h
vendored
7
dist/build/autogen/cabal_macros.h
vendored
@ -63,3 +63,10 @@
|
||||
(major1) == 3 && (major2) < 2 || \
|
||||
(major1) == 3 && (major2) == 2 && (minor) <= 0)
|
||||
|
||||
/* package text-0.11.3.1 */
|
||||
#define VERSION_text "0.11.3.1"
|
||||
#define MIN_VERSION_text(major1,major2,minor) (\
|
||||
(major1) < 0 || \
|
||||
(major1) == 0 && (major2) < 11 || \
|
||||
(major1) == 0 && (major2) == 11 && (minor) <= 3)
|
||||
|
||||
|
BIN
dist/build/hgraph/hgraph
vendored
BIN
dist/build/hgraph/hgraph
vendored
Binary file not shown.
BIN
dist/build/hgraph/hgraph-tmp/Main.hi
vendored
BIN
dist/build/hgraph/hgraph-tmp/Main.hi
vendored
Binary file not shown.
BIN
dist/build/test-hgraph/test-hgraph
vendored
BIN
dist/build/test-hgraph/test-hgraph
vendored
Binary file not shown.
BIN
dist/build/test-hgraph/test-hgraph-tmp/Main.hi
vendored
BIN
dist/build/test-hgraph/test-hgraph-tmp/Main.hi
vendored
Binary file not shown.
2
dist/setup-config
vendored
2
dist/setup-config
vendored
File diff suppressed because one or more lines are too long
@ -10,7 +10,7 @@ data-dir: ""
|
||||
executable hgraph
|
||||
build-depends: QuickCheck -any, Stream -any, accelerate -any,
|
||||
base -any, bytestring -any, deepseq -any, ghc -any, monad-par -any,
|
||||
parallel -any
|
||||
parallel -any, text -any
|
||||
main-is: Main.hs
|
||||
buildable: True
|
||||
hs-source-dirs: src
|
||||
@ -19,7 +19,7 @@ executable hgraph
|
||||
test-suite test-hgraph
|
||||
build-depends: QuickCheck -any, Stream -any, accelerate -any,
|
||||
base -any, bytestring -any, deepseq -any, ghc -any, monad-par -any,
|
||||
parallel -any
|
||||
parallel -any, text -any
|
||||
type: exitcode-stdio-1.0
|
||||
main-is: Main.hs
|
||||
buildable: True
|
||||
|
48
src/Main.hs
48
src/Main.hs
@ -24,12 +24,14 @@ import Data.List
|
||||
import System.Exit (exitFailure)
|
||||
import System.Environment
|
||||
import Test.QuickCheck.All (quickCheckAll)
|
||||
import qualified Data.ByteString.Lazy.Char8 as B
|
||||
import qualified Data.ByteString.Char8 as B
|
||||
import Data.ByteString.Lazy.Char8 (ByteString)
|
||||
import Control.Monad.Par.Scheds.Trace
|
||||
import qualified Data.Stream as S
|
||||
import Data.Either (lefts, rights)
|
||||
import Debug.Trace
|
||||
import qualified Data.Text as T
|
||||
import Data.Text.Encoding
|
||||
import qualified Data.Array.Accelerate as A
|
||||
-- change to Data.Array.Accelerate.CUDA as I and link accelerate-cuda to use GPU instead of CPU
|
||||
import Data.Array.Accelerate.Interpreter as I
|
||||
@ -38,19 +40,20 @@ import Stream hiding (map)
|
||||
|
||||
type Matrix e = A.Array A.DIM2 e
|
||||
|
||||
createGraph :: String -> Either [Int] String
|
||||
createGraph input = traceEvent "creating graph" createGraph' input (Left [])
|
||||
createGraph :: T.Text -> Either [Int] T.Text
|
||||
createGraph input = createGraph' input (Left [])
|
||||
where
|
||||
createGraph' :: String -> Either [Int] String -> Either [Int] String
|
||||
createGraph' [] r = traceEvent "recursion done." r
|
||||
createGraph' (a:as) r =
|
||||
let next = (createGraph' as r) in
|
||||
createGraph' :: T.Text -> Either [Int] T.Text -> Either [Int] T.Text
|
||||
createGraph' a r
|
||||
| T.null a = r
|
||||
| otherwise =
|
||||
let next = (createGraph' (T.tail a) r) in
|
||||
case next of
|
||||
Left xs ->
|
||||
case a of
|
||||
case T.head a of
|
||||
'0' -> Left $ 0:xs
|
||||
'1' -> Left $ 1:xs
|
||||
_ -> Right $ "cannot parse " ++ (a:as)
|
||||
_ -> Right $ T.append (T.pack "cannot parse ") a
|
||||
Right errstr ->
|
||||
Right errstr
|
||||
--createGraph input = Right $ "Parsing-error in line: " ++ input
|
||||
@ -80,19 +83,17 @@ graphFolder l = graphFolder' l (Left [[]])
|
||||
concatWith :: String -> String -> String -> String
|
||||
concatWith d a b = a ++ d ++ b
|
||||
|
||||
emptyLine :: String -> Bool
|
||||
emptyLine "" = True
|
||||
emptyLine "\n" = True
|
||||
emptyLine "\r\n" = True
|
||||
emptyLine "\r" = True
|
||||
emptyLine _ = False
|
||||
emptyLine :: T.Text -> Bool
|
||||
emptyLine a
|
||||
| T.null a = True
|
||||
| otherwise = False
|
||||
|
||||
emptyLog :: [String] -> Bool
|
||||
emptyLog :: [T.Text] -> Bool
|
||||
emptyLog [] = True
|
||||
emptyLog a = emptyLine $ foldl1 (++) a
|
||||
emptyLog a = False --emptyLine $ foldl True (&&) (map emptyLine a)
|
||||
|
||||
-- TODO: implement calculation
|
||||
doCalculation :: Matrix Int -> ByteString
|
||||
doCalculation :: Matrix Int -> B.ByteString
|
||||
doCalculation a = B.pack $ "" --(show a) ++ "\n"
|
||||
|
||||
|
||||
@ -108,10 +109,10 @@ exeMain = do
|
||||
-- and filter empty lines
|
||||
(createGraph) (filter (not . emptyLine)
|
||||
-- split at \n, convert to String
|
||||
(map B.unpack (B.split '\n' input)))
|
||||
(T.lines (decodeUtf8 input)))
|
||||
--egraph <- return $ graphFolder unrefined_graph
|
||||
(graph, log, lines) <- return $ ((foldl1 (++) (lefts unrefined_graph), -- concatenated graph
|
||||
foldl (concatWith "\n") "" (rights unrefined_graph), -- concat error-log
|
||||
T.intercalate (T.singleton '\n') (rights unrefined_graph), -- concat error-log
|
||||
length unrefined_graph) -- number of elements in graph
|
||||
-- in parallel
|
||||
`using` parTuple3 rdeepseq rdeepseq rdeepseq)
|
||||
@ -119,13 +120,14 @@ exeMain = do
|
||||
-- validate graph
|
||||
log <- return $ let l = length graph in
|
||||
if l /= lines*lines then
|
||||
log ++ "Lines dont match up. Read " ++ (show l) ++ " lines. Expected "
|
||||
++ (show (lines*lines)) ++ " lines.\n"
|
||||
T.append log $ T.pack $ "Lines dont match up. Read " ++ (show l) ++
|
||||
" chars. Expected " ++ (show (lines*lines)) ++
|
||||
" chars.\n"
|
||||
else
|
||||
log
|
||||
output <- return $ case emptyLine log of
|
||||
True -> doCalculation $ A.fromList (A.Z A.:. lines A.:. lines) graph
|
||||
_ -> B.pack $ "Error detected:\n" ++ log ++ "\n\n"
|
||||
_ -> encodeUtf8 $ T.append (T.append (T.pack "Error detected:\n") log) (T.pack "\n\n")
|
||||
B.putStr output
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user