logical-constraints 0.1.2.0 → 0.1.3.0
raw patch · 3 files changed
+32/−13 lines, 3 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
Files
- CHANGELOG.md +6/−0
- Logical/OrdConstraints.hs +22/−9
- logical-constraints.cabal +4/−4
CHANGELOG.md view
@@ -17,3 +17,9 @@ * First version revised C. Updated the metadata. +## 0.1.3.0 -- 2023-01-12++* First version revised D. Removed implicit Prelude import, changed the dependency boundaries. Code+now can throw an error or pattern match exception if the data type is contructed not validly +(to prevent usage of the incorrectly defined data).+
Logical/OrdConstraints.hs view
@@ -1,21 +1,34 @@+{-# LANGUAGE NoImplicitPrelude #-}+{-# OPTIONS_HADDOCK show-extensions #-}+ -- | -- Module : Logical.OrdConstraints--- Copyright : (c) Oleksandr Zhabenko 2022+-- Copyright : (c) Oleksandr Zhabenko 2022-2023 -- License : MIT -- Stability : Experimental -- Maintainer : oleksandr.zhabenko@yahoo.com -- -- Some simple logical encoding 'syntactical sugar' to represent point-wise or intervals-based logics.+-- If you would like to use data types not in the functions of the module imported, but in your+-- own ones, please, consider using before the 'validOrdCs' function for them. If you use just+-- the functions defined here, you do not need to use it before because it is used internally. module Logical.OrdConstraints where -import Data.Foldable-import Data.Maybe+import Control.Exception+import Data.Foldable (Foldable, any)+import GHC.Base hiding (O)+import GHC.List hiding (any)+import Text.Show +import Text.Read+import GHC.Real (rem)+import Data.Maybe (fromMaybe) -- | Data type to encode the simple logical contstraints for some 'Ord'ered data type value to be kept in some bounds (to lay in some intervals or points). 'O' constructor encodes -- point-wise logics, and 'C' encodes intervals logics. data OrdConstraints a = O [a] | C [a] deriving (Eq, Ord, Show, Read) +-- | Primary intention: the @t@ here refers to 'Foldable' @t@. type OrdCs t a = t (OrdConstraints a) -- | The predicate to check whether the data is encoded logically correct just enough to be used by the functions in the library (minimal necessary validation). Checks whether @@ -28,12 +41,12 @@ ordCs2Predicate1 :: Ord a => OrdConstraints a -> a -> Bool ordCs2Predicate1 x@(O xs) y | validOrdCs x = any (== y) xs- | otherwise = False+ | otherwise = error "Logical.OrdConstraints.ordCs2Predicate1: Not valid logical constraint by constrution semantics." ordCs2Predicate1 x@(C xs) y | validOrdCs x = any (\(t:u:_) -> y >= t && y <= u) . f $ xs- | otherwise = False+ | otherwise = error "Logical.OrdConstraints.ordCs2Predicate1: Not valid logical constraint by constrution semantics." where f (x:y:xs) = [x,y]:f xs- f _ = []+ f [] = [] ordCs2HPred1 :: (Ord a, Foldable t1) => OrdCs t1 a -> a -> Bool ordCs2HPred1 cs y = any (\c -> ordCs2Predicate1 c y) $ cs@@ -54,12 +67,12 @@ ordCs2PredicateG :: (Ord a, Foldable t) => OrdConstraints a -> (t a -> Maybe a) -> t a -> Bool ordCs2PredicateG x@(O xs) p ys | validOrdCs x = any (\k -> (fromMaybe False . fmap (== k) . p $ ys)) xs- | otherwise = False+ | otherwise = error "Logical.OrdConstraints.ordCs2PredicateG: Not valid logical constraint by constrution semantics." ordCs2PredicateG x@(C xs) p ys | validOrdCs x = any (\(t:u:_) -> fromMaybe False . fmap (\k -> k >= t && k <= u) . p $ ys) . f $ xs- | otherwise = False+ | otherwise = error "Logical.OrdConstraints.ordCs2PredicateG: Not valid logical constraint by constrution semantics." where f (x:y:xs) = [x,y]:f xs- f _ = []+ f [] = [] ordCs2HPredG :: (Ord a, Foldable t, Foldable t1) => OrdCs t1 a -> (t a -> Maybe a) -> t a -> Bool ordCs2HPredG cs p ys = any (\c -> ordCs2PredicateG c p ys) $ cs
logical-constraints.cabal view
@@ -1,12 +1,12 @@ cabal-version: 2.4 name: logical-constraints-version: 0.1.2.0+version: 0.1.3.0 -- A short (one-line) description of the package. synopsis: Simple logical constraints 'syntax-sugar' writing library. -- A longer description of the package.-description: Some library functions and data to simplify the writing of the simple logical constraints of Ord classes data instances.+description: Some library functions and data to simplify the writing of the simple logical constraints of Ord class data instances so that it represents point-wise and interval-based logics. -- A URL where users can report bugs. bug-reports: https://github.com/Oleksandr-Zhabenko/logical-constraints/issues@@ -26,7 +26,7 @@ exposed-modules: Logical.OrdConstraints -- LANGUAGE extensions used by modules in this package.- -- other-extensions:- build-depends: base >=4.7 && <5+ other-extensions: NoImplicitPrelude+ build-depends: base >=4.13 && <5 default-language: Haskell2010