diff options
| author | Jan Sucan <jan@jansucan.com> | 2023-09-27 15:59:19 +0200 |
|---|---|---|
| committer | Jan Sucan <jan@jansucan.com> | 2023-09-27 15:59:19 +0200 |
| commit | 1bb8a1fb9a13840f96fd395093ae1a8694917ac3 (patch) | |
| tree | aa8a68a308c7278507b93a74df8179202a0cd7a8 /ch09/9_b_3.hs | |
| parent | 5d47dc25454d0e2e9472aedd7b66099821e6658c (diff) | |
9_b_4: Add solution
Diffstat (limited to 'ch09/9_b_3.hs')
| -rw-r--r-- | ch09/9_b_3.hs | 68 |
1 files changed, 0 insertions, 68 deletions
diff --git a/ch09/9_b_3.hs b/ch09/9_b_3.hs deleted file mode 100644 index 882f7db..0000000 --- a/ch09/9_b_3.hs +++ /dev/null @@ -1,68 +0,0 @@ --- Take the predicates and combinators from "Gluing predicates together" on page --- 224 and make them work with our new Info type. - -{-- From examples/examples/ch09/BetterPredicate.hs modified according to the assignment --} -import Data.Time (UTCTime(..)) -import System.Directory (Permissions(..)) -import System.FilePath (takeExtension) - - -data Info = Info { - infoPath :: FilePath - , infoPerms :: Maybe Permissions - , infoSize :: Maybe Integer - , infoModTime :: Maybe UTCTime - } deriving (Eq, Ord, Show) - -type InfoF a = Info -> a - - -equalP :: (Eq a) => InfoF a -> a -> (InfoF Bool) -equalP f k = (\info -> f info == k) - -equalP' :: (Eq a) => (InfoF a) -> a -> (InfoF Bool) -equalP' f k info = (f info == k) - -liftP :: (a -> b -> Bool) -> (InfoF a) -> b -> (InfoF Bool) -liftP q f k info = f info `q` k - -greaterP, lesserP :: (Ord a) => (InfoF a) -> a -> (InfoF Bool) -greaterP = liftP (>) -lesserP = liftP (<) - -simpleAndP :: (InfoF Bool) -> (InfoF Bool) -> (InfoF Bool) -simpleAndP f g info = f info && g info - -liftP2 :: (a -> b -> Bool) -> (InfoF a) -> (InfoF b) -> (InfoF Bool) -liftP2 q f g info = f info `q` g info - -andP = liftP2 (&&) -orP = liftP2 (||) - -constP :: a -> (InfoF a) -constP k _ = k - -liftP' q f k info = f info `q` constP k info - -liftPath :: (FilePath -> a) -> (InfoF a) -liftPath f info = f (infoPath info) - -myTest2 = (liftPath takeExtension `equalP` ".cpp") `andP` - (infoSize `greaterP` (Just 131072)) -{-- End of code from examples --} - --- ghci> :l 9_b_3.hs --- [1 of 1] Compiling Main ( 9_b_3.hs, interpreted ) --- Ok, one module loaded. - --- ghci> infoA = Info "asdf.cpp" Nothing (Just 131072) Nothing --- ghci> myTest2 infoA --- False - --- ghci> infoB = Info "asdf.hs" Nothing (Just 131073) Nothing --- ghci> myTest2 infoB --- False - --- ghci> infoC = Info "asdf.cpp" Nothing (Just 131073) Nothing --- ghci> myTest2 infoC --- True |
