diff options
author | Marvin Borner | 2022-08-07 18:11:21 +0200 |
---|---|---|
committer | Marvin Borner | 2022-08-07 18:13:00 +0200 |
commit | a614ac0ed73ae6e12c0c15d057c93a5c96d1e08c (patch) | |
tree | aaae1668cfaa4c51608e026a8eaf2c37452a48b9 /src/Binary.hs | |
parent | d2a5d69f42d74e8382ca29c8c166eba3a79d20d5 (diff) |
Things
lol
Diffstat (limited to 'src/Binary.hs')
-rw-r--r-- | src/Binary.hs | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/Binary.hs b/src/Binary.hs index 2a1c891..359dea8 100644 --- a/src/Binary.hs +++ b/src/Binary.hs @@ -5,25 +5,23 @@ module Binary , fromBitString ) where -import Control.Applicative import Data.Binary ( decode , encode ) import qualified Data.BitString as Bit import qualified Data.ByteString.Lazy as Byte -import Data.Char import Data.Int ( Int8 ) import Helper toBinary :: Expression -> String toBinary (Bruijn x ) = (replicate (x + 1) '1') ++ "0" -toBinary (Abstraction exp ) = "00" ++ toBinary exp +toBinary (Abstraction e ) = "00" ++ toBinary e toBinary (Application exp1 exp2) = "01" ++ (toBinary exp1) ++ (toBinary exp2) +toBinary _ = "" -- shouldn't happen fromBinary' :: String -> (Expression, String) fromBinary' = \case - '0' : '0' : rst -> - let (exp, rst) = fromBinary' rst in (Abstraction exp, rst) + '0' : '0' : rst -> let (e, es) = fromBinary' rst in (Abstraction e, es) '0' : '1' : rst -> let (exp1, rst1) = fromBinary' rst (exp2, rst2) = fromBinary' rst1 @@ -51,6 +49,7 @@ toBitString str = Bit.concat (\case '0' -> False '1' -> True + _ -> error "invalid bit" ) str ] @@ -66,4 +65,4 @@ fromBitString bits = $ Bit.toList $ Bit.take (Bit.length bits - pad bits) $ Bit.drop 8 bits - where pad bits = decode $ Bit.realizeBitStringLazy $ Bit.take 8 bits + where pad = decode . Bit.realizeBitStringLazy . Bit.take 8 |