Created
July 8, 2019 07:24
-
-
Save bradparker/4d2712bda37cfa58d694f588bc4ef721 to your computer and use it in GitHub Desktop.
Bits
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Monad.State | |
import Data.Traversable | |
import Data.Tuple | |
toByteBits :: Integral n => n -> [n] | |
toByteBits = | |
evalState (for [1..8] (\_ -> state (\s -> swap (divMod s 2)))) | |
main = do | |
print $ toByteBits 1 | |
print $ toByteBits 2 | |
print $ toByteBits 3 | |
print $ toByteBits 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment