Craft3e 0.1.0.6 → 0.1.0.7
raw patch · 4 files changed
+83/−1 lines, 4 files
Files
- .DS_Store binary
- Chapter15/Test.hs +34/−0
- Chapter16/Store.hs +48/−0
- Craft3e.cabal +1/−1
.DS_Store view
binary file changed (6148 → 6148 bytes)
+ Chapter15/Test.hs view
@@ -0,0 +1,34 @@+-------------------------------------------------------------------------+--+-- Test.hs+--+-- The test module of the Huffman example+--+-- (c) Addison-Wesley, 1996-2011.+--+-------------------------------------------------------------------------++module Test where++-- The test module of the Huffman example++import Main+import Test.QuickCheck+import Data.List ( nub )+++-- QuickCheck testing++checkInverse :: String -> Bool++checkInverse string = + decodeMessage tree (codeMessage table string) == string+ where+ tree = codes string+ table = codeTable tree++-- prop_Hufmann :: String -> Bool++prop_Hufmann string =+ (length (nub string) > 1) ==> checkInverse string+
+ Chapter16/Store.hs view
@@ -0,0 +1,48 @@+-------------------------------------------------------------------------+-- +-- Store.hs+-- +-- An abstract data type of stores of integers, implemented as+-- a list of pairs of variables and values. +-- +-- (c) Addison-Wesley, 1996-2011. +-- +-------------------------------------------------------------------------++module Store + ( Store, + initial, -- Store+ value, -- Store -> Var -> Integer+ update -- Store -> Var -> Integer -> Store+ ) where++-- Var is the type of variables. ++type Var = Char++-- The implementation is given by a newtype declaration, with one+-- constructor, taking an argument of type [ (Integer,Var) ].++data Store = Store [ (Integer,Var) ] ++instance Eq Store where + (Store sto1) == (Store sto2) = (sto1 == sto2) ++instance Show Store where+ showsPrec n (Store sto) = showsPrec n sto +-- +initial :: Store ++initial = Store []++value :: Store -> Var -> Integer++value (Store []) v = 0+value (Store ((n,w):sto)) v + | v==w = n+ | otherwise = value (Store sto) v++update :: Store -> Var -> Integer -> Store++update (Store sto) v n = Store ((n,v):sto)+
Craft3e.cabal view
@@ -1,6 +1,6 @@ name: Craft3e-version: 0.1.0.6+version: 0.1.0.7 license: MIT license-file: LICENSE copyright: (c) Addison Wesley