aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Helper.hs
diff options
context:
space:
mode:
authorMarvin Borner2023-03-05 16:28:58 +0100
committerMarvin Borner2023-03-05 16:28:58 +0100
commitf5dc226df6ef8e5f257352409965603bbdaabd42 (patch)
treedb9f656c9093df336c58f556139da01b4ca573c9 /src/Helper.hs
parentca808bc09373f123514bf865a4518bebac3bbbc3 (diff)
Made stdin and argument conversion lazy
Diffstat (limited to 'src/Helper.hs')
-rw-r--r--src/Helper.hs16
1 files changed, 5 insertions, 11 deletions
diff --git a/src/Helper.hs b/src/Helper.hs
index 9571c00..110fd4f 100644
--- a/src/Helper.hs
+++ b/src/Helper.hs
@@ -9,8 +9,8 @@ module Helper where
import qualified Control.Monad.State as S
import Data.Array
import qualified Data.BitString as Bit
-import qualified Data.ByteString as Byte
-import qualified Data.ByteString.Char8 as C
+import qualified Data.ByteString.Lazy as Byte
+import qualified Data.ByteString.Lazy.Char8 as C
import Data.List
import qualified Data.Map as M
import Text.Megaparsec
@@ -195,14 +195,14 @@ encodeByte bits = Abstraction $ Abstraction $ Abstraction $ binarify
-- TODO: There must be a better way to do this :D
encodeBytes :: Byte.ByteString -> Expression
encodeBytes bytes = listify $ map
- (encodeByte . Bit.toList . Bit.bitString . Byte.pack . (: []))
+ (encodeByte . Bit.toList . Bit.bitStringLazy . Byte.pack . (: []))
(Byte.unpack bytes)
stringToExpression :: String -> Expression
stringToExpression = encodeBytes . C.pack
charToExpression :: Char -> Expression
-charToExpression ch = encodeByte $ Bit.toList $ Bit.bitString $ C.pack [ch]
+charToExpression ch = encodeByte $ Bit.toList $ Bit.bitStringLazy $ C.pack [ch]
encodeStdin :: IO Expression
encodeStdin = do
@@ -232,7 +232,7 @@ decodeStdout e = do
u <- unlistify e
pure $ C.unpack $ Byte.concat $ map
(\m -> case decodeByte m of
- Just b -> Bit.realizeBitStringStrict $ Bit.fromList b
+ Just b -> Bit.realizeBitStringLazy $ Bit.fromList b
Nothing -> Byte.empty
)
u
@@ -373,9 +373,3 @@ ternaryToDecimal e = do
resolve (Abstraction (Abstraction (Abstraction (Abstraction n)))) =
resolve' n
resolve _ = Nothing
-
-huh :: (a -> Bool) -> [a] -> ([a], [a])
-huh f s = (left, right)
- where
- (left, right') = break f s
- right = if null right' then [] else tail right'