bool8 0.0 → 0.0.1
raw patch · 2 files changed
+16/−13 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- bool8.cabal +2/−2
- src/Data/Bool8.hs +14/−11
bool8.cabal view
@@ -1,5 +1,5 @@ Name: bool8-Version: 0.0+Version: 0.0.1 Synopsis: Alternative Bool type stored as byte Description: The standard 'Bool' type has a 'Storable' instance@@ -21,7 +21,7 @@ Tested-With: GHC==8.0.2, GHC==8.2.2 Source-Repository this- Tag: 0.0+ Tag: 0.0.1 Type: darcs Location: http://hub.darcs.net/thielema/bool8
src/Data/Bool8.hs view
@@ -6,39 +6,42 @@ ) where import Foreign.Storable (Storable, poke, peek, sizeOf, alignment)-import Foreign.Ptr (castPtr)+import Foreign.Ptr (Ptr, castPtr) import Data.Functor ((<$>)) import Data.Word (Word8) -newtype Bool8 = Bool8 Word8+newtype Bool8 = Bool8 Bool deriving (Eq, Ord) instance Show Bool8 where- show (Bool8 0) = "Bool8.false"+ show (Bool8 False) = "Bool8.false" show _ = "Bool8.true" instance Bounded Bool8 where minBound = false maxBound = true +word8Ptr :: Ptr Bool8 -> Ptr Word8+word8Ptr = castPtr+ instance Storable Bool8 where sizeOf _ = 1 alignment _ = 1- peek ptr = Bool8 <$> peek (castPtr ptr)- poke ptr (Bool8 b) = poke (castPtr ptr) b+ peek ptr = Bool8 . (0/=) <$> peek (word8Ptr ptr)+ poke ptr (Bool8 b) = poke (word8Ptr ptr) (fromIntegral $ fromEnum b) instance Enum Bool8 where- fromEnum (Bool8 b) = fromIntegral b- toEnum k = Bool8 $ if k==0 then 0 else 1+ fromEnum (Bool8 b) = fromEnum b+ toEnum = Bool8 . toEnum false, true :: Bool8-false = Bool8 0-true = Bool8 1+false = Bool8 False+true = Bool8 True toBool :: Bool8 -> Bool-toBool (Bool8 b) = b/=0+toBool (Bool8 b) = b fromBool :: Bool -> Bool8-fromBool b = if b then true else false+fromBool = Bool8