Skip to content

Instantly share code, notes, and snippets.

@bradparker
Created July 8, 2019 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradparker/4d2712bda37cfa58d694f588bc4ef721 to your computer and use it in GitHub Desktop.
Save bradparker/4d2712bda37cfa58d694f588bc4ef721 to your computer and use it in GitHub Desktop.
Bits
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