creatur 5.9.17 → 5.9.18
raw patch · 3 files changed
+44/−1 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ ALife.Creatur.Genetics.BRGCWord8: instance ALife.Creatur.Genetics.BRGCWord8.Genetic GHC.Integer.Type.Integer
+ ALife.Creatur.Genetics.BRGCWord8: instance ALife.Creatur.Genetics.BRGCWord8.Genetic GHC.Types.Double
+ ALife.Creatur.Genetics.BRGCWord8: instance ALife.Creatur.Genetics.BRGCWord8.Genetic GHC.Types.Int
Files
- creatur.cabal +2/−1
- src/ALife/Creatur/Genetics/BRGCWord8.hs +36/−0
- test/ALife/Creatur/Genetics/BRGCWord8QC.hs +6/−0
creatur.cabal view
@@ -1,5 +1,5 @@ name: creatur-version: 5.9.17+version: 5.9.18 cabal-version: >=1.8 build-type: Simple license: BSD3@@ -60,6 +60,7 @@ build-depends: array >=0.5.1.1 && <0.6, base ==4.9.*,+ binary >=0.8.3.0 && <0.9, bytestring >=0.10.8.1 && <0.11, cond >=0.4.1.1 && <0.5, cereal >=0.5.4.0 && <0.6,
src/ALife/Creatur/Genetics/BRGCWord8.hs view
@@ -62,6 +62,8 @@ import Control.Monad (replicateM) import Control.Monad.State.Lazy (StateT, runState, execState, evalState) import qualified Control.Monad.State.Lazy as S (put, get, gets)+import Data.Binary (Binary, encode, decode)+import Data.ByteString.Lazy (pack, unpack) import Data.Char (ord, chr) import Data.Either (partitionEithers) import Data.Functor.Identity (Identity)@@ -219,6 +221,34 @@ where x = integralToGray g get = getAndReport 8 grayWord64 +instance Genetic Int where+ put g = put (map integralToGray . integralToByteArray $ g)+ get = do+ x <- get+ case x of+ Right xs -> return $ Right (byteArrayToIntegral . map grayToIntegral $ xs)+ Left s -> return $ Left s++instance Genetic Integer where+ put g = put (map integralToGray . integralToByteArray $ g)+ get = do+ x <- get+ case x of+ Right xs -> return $ Right (byteArrayToIntegral . map grayToIntegral $ xs)+ Left s -> return $ Left s++instance Genetic Double where+ put g = put m >> put n+ where (m, n) = decodeFloat g+ get = do+ m <- get+ case m of+ Right m' -> do n <- get+ case n of+ Right n' -> return $ Right (encodeFloat m' n')+ Left s' -> return $ Left s'+ Left s -> return $ Left s+ grayWord16 :: [Word8] -> Either String (Word16, String) grayWord16 bs = Right (g, show g ++ " Word16") where g = grayToIntegral . bytesToIntegral $ bs@@ -242,6 +272,12 @@ bytesToIntegral bs = f (bs, 0) where f ([], n) = n f (k:ks, n) = f (ks, n*0x100 + fromIntegral k)++integralToByteArray :: (Integral t, Binary t) => t -> [Word8]+integralToByteArray = unpack . encode++byteArrayToIntegral :: (Integral t, Binary t) => [Word8] -> t+byteArrayToIntegral = decode . pack instance (Genetic a) => Genetic [a] where put xs = do
test/ALife/Creatur/Genetics/BRGCWord8QC.hs view
@@ -91,6 +91,12 @@ (prop_round_trippable :: Word32 -> Property), testProperty "prop_round_trippable - Word64" (prop_round_trippable :: Word64 -> Property),+ testProperty "prop_round_trippable - Int"+ (prop_round_trippable :: Int -> Property),+ testProperty "prop_round_trippable - Integer"+ (prop_round_trippable :: Integer -> Property),+ testProperty "prop_round_trippable - Double"+ (prop_round_trippable :: Double -> Property), testProperty "prop_round_trippable2 - Word8" (prop_round_trippable2 1 :: [Word8] -> Word8 -> Property), testProperty "prop_round_trippable2 - Word16"