Skip to content

Instantly share code, notes, and snippets.

@chrisdone
Created February 3, 2016 16:50
Show Gist options
  • Save chrisdone/d4362d1302c9dd539b9b to your computer and use it in GitHub Desktop.
Save chrisdone/d4362d1302c9dd539b9b to your computer and use it in GitHub Desktop.
Pattern matching bits
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE PatternSynonyms #-}
-- | Demonstration of pattern matching on bits in a byte.
module X where
import Data.Bits
pattern Byte a b c d <- (byte -> (ByteBits a b c d))
data ByteBits = ByteBits Bool Bool Bool Bool
byte :: Bits a => a -> ByteBits
byte n = ByteBits (testBit n 3) (testBit n 2) (testBit n 1) (testBit n 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment