diff options
author | Marvin Borner | 2023-02-23 14:26:41 +0100 |
---|---|---|
committer | Marvin Borner | 2023-02-23 14:26:41 +0100 |
commit | 2940495ac437a23084383567be6b3bef9ee9fb8d (patch) | |
tree | 0fbdc4460ec2c8a56e421c4c2d88c0835165a161 /src/Binary.hs | |
parent | 4748f92183ba9ffe58f84b6b4cba364df49161cc (diff) |
Added unary/binary encoding suffixes
Diffstat (limited to 'src/Binary.hs')
-rw-r--r-- | src/Binary.hs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/Binary.hs b/src/Binary.hs index ad67b20..ac08ca7 100644 --- a/src/Binary.hs +++ b/src/Binary.hs @@ -18,7 +18,7 @@ toBinary :: Expression -> String toBinary (Bruijn x ) = (replicate (x + 1) '1') ++ "0" toBinary (Abstraction e ) = "00" ++ toBinary e toBinary (Application exp1 exp2) = "01" ++ (toBinary exp1) ++ (toBinary exp2) -toBinary _ = error "invalid" +toBinary _ = invalidProgramState fromBinary' :: String -> (Expression, String) fromBinary' inp = case inp of @@ -28,7 +28,7 @@ fromBinary' inp = case inp of (exp2, rst2) = fromBinary' rst1 in (Application exp1 exp2, rst2) '1' : _ : rst -> binaryBruijn rst - e -> error $ "invalid: " <> e + _ -> invalidProgramState where binaryBruijn rst = let idx = (length $ takeWhile (== '1') $ inp) - 1 @@ -49,7 +49,7 @@ toBitString str = Bit.concat (\case '0' -> False '1' -> True - _ -> error "invalid bit" + _ -> invalidProgramState ) str ] |