packages feed

gray-extended 1.2 → 1.3

raw patch · 3 files changed

+23/−27 lines, 3 filesdep −base-unicode-symbolsdep ~test-framework-quickcheck2PVP ok

version bump matches the API change (PVP)

Dependencies removed: base-unicode-symbols

Dependency ranges changed: test-framework-quickcheck2

API changes (from Hackage documentation)

Files

gray-extended.cabal view
@@ -1,5 +1,5 @@ name:           gray-extended-version:        1.2+version:        1.3 synopsis:       Gray encoding schemes description:    Gray codes satisfy the property that two successive values                  differ in only one digit. Usually the term \"Gray code\"@@ -18,18 +18,16 @@  library   hs-source-dirs:  src-  build-depends:   base ==4.*,-                   base-unicode-symbols ==0.2.*+  build-depends:   base ==4.*   ghc-options:     -Wall   exposed-modules: Codec.Gray  test-suite gray-extended-tests   type:            exitcode-stdio-1.0   build-depends:   base ==4.*,-                   test-framework-quickcheck2 == 0.2.*,+                   test-framework-quickcheck2 == 0.3.*,                    QuickCheck == 2.4.*,                    test-framework == 0.*,-                   base-unicode-symbols ==0.2.*,                    gray-extended   hs-source-dirs:  test   ghc-options:     -Wall -Werror -rtsopts
src/Codec/Gray.hs view
@@ -1,4 +1,4 @@------------------------------------------------------------------------------+------------------------------------------------------------------------ -- | -- Module      :  Codec.Gray -- Copyright   :  (c) Amy de Buitléir 2011-2012@@ -8,14 +8,12 @@ -- Portability :  portable -- -- Gray encoding schemes. A Gray code is a list of values such that two--- successive values differ in only one digit. Usually the term /Gray code/--- refers to the Binary Reflected Gray code (BRGC), but non-binary Gray codes--- have also been discovered. Some Gray codes are also /cyclic/: the last and--- first values differ in only one digit.+-- successive values differ in only one digit. Usually the term /Gray+-- code/ refers to the Binary Reflected Gray code (BRGC), but non-binary+-- Gray codes have also been discovered. Some Gray codes are also+-- /cyclic/: the last and first values differ in only one digit. ---------------------------------------------------------------------------------{-# LANGUAGE UnicodeSyntax #-}-+------------------------------------------------------------------------ module Codec.Gray    (     grayCodes,@@ -24,28 +22,29 @@  import Data.List (foldl') --- | @'grayCodes' k@ generates the list of Binary Reflected Gray Code (BRGC)---   numbers of length k. This code is cyclic.-grayCodes ∷ Int → [[Bool]]+-- | @'grayCodes' k@ generates the list of Binary Reflected Gray Code+--   (BRGC) numbers of length k. This code is cyclic.+grayCodes :: Int -> [[Bool]] grayCodes 0 = [[]] grayCodes k =    let xs = grayCodes (k-1) in map (False:) xs ++ map (True:) (reverse xs) --- | @'naryGrayCodes' xs k@ generates a non-Boolean (or n-ary) Gray code of---   length @k@ using the elements of @x@ as "digits". This code is cyclic.+-- | @'naryGrayCodes' xs k@ generates a non-Boolean (or n-ary) Gray code+--   of length @k@ using the elements of @x@ as "digits". This code is+--   cyclic. -----   Ex: @'naryGrayCodes' "012" 4@ generates a ternary Gray code that is ---   four digits long.-naryGrayCodes ∷ [a] → Int → [[a]]-naryGrayCodes xs 1 = map (\x → [x]) xs+--   Ex: @'naryGrayCodes' \"012\" 4@ generates a ternary Gray code that+--   is four digits long.+naryGrayCodes :: [a] -> Int -> [[a]]+naryGrayCodes xs 1 = map (\x -> [x]) xs naryGrayCodes xs k = snd $ foldl' prefixAndShift (ys,[]) xs'   where ys = naryGrayCodes xs 1         xs' = naryGrayCodes xs (k-1)  -- | Shift elements right.-shift ∷ [a] → [a]+shift :: [a] -> [a] shift as = last as : init as -prefixAndShift ∷ ([[a]],[[a]]) → [a] → ([[a]],[[a]])+prefixAndShift :: ([[a]],[[a]]) -> [a] -> ([[a]],[[a]]) prefixAndShift (ys,zs) xs = (shift ys, zs ++ (map (xs++) ys)) 
test/Main.hs view
@@ -1,15 +1,14 @@-{-# LANGUAGE UnicodeSyntax #-} module Main where  import Codec.GrayQC ( test )  import Test.Framework as TF ( defaultMain, Test ) -tests ∷ [TF.Test]+tests :: [TF.Test] tests =    [      Codec.GrayQC.test   ] -main ∷ IO ()+main :: IO () main = defaultMain tests