packages feed

phonetic-languages-constraints-array 0.1.1.0 → 0.1.2.0

raw patch · 4 files changed

+29/−7 lines, 4 filesdep ~subGPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: subG

API changes (from Hackage documentation)

+ Languages.UniquenessPeriods.Array.Constraints.Encoded: P :: a -> b -> EncodedContraints a b
+ Languages.UniquenessPeriods.Array.Constraints.Encoded: isP :: EncodedCnstrs -> Bool

Files

CHANGELOG.md view
@@ -8,3 +8,8 @@  * First version revised A. Updated the dependency boundaries to support the latest GHC and Cabal versions. Added some experimental functions that  are not further used.++## 0.1.2.0 -- 2022-04-25++* First version revised B. Added the new constraint P functionality.+
Languages/UniquenessPeriods/Array/Constraints.hs view
@@ -91,10 +91,15 @@  -------------------------------------------------------------------------------- +-- | Reduces the number of permutations using filtering leaving just those ones permutations where elements on the+-- first elements in the tuples in the first argument 'Array' places are moved to the places indexed with the second+-- elements in the tuples respectively. fixedPointsG :: (InsertLeft t (Array Int Int), Monoid (t (Array Int Int))) => Array Int (Int,Int) -> t (Array Int Int) -> t (Array Int Int) fixedPointsG arr xs = filterG (f arr) xs    where f arr1 arr2 = all (\(k,j) -> unsafeAt arr2 k == j) arr1 +-- | A simplified variant of the 'fixedPointsG' function where the specified elements stay on their place and that is+-- why are 'fixed points' in the permutation specified. fixedPointsS :: (InsertLeft t (Array Int Int), Monoid (t (Array Int Int))) => Array Int Int -> t (Array Int Int) -> t (Array Int Int) fixedPointsS arr xs = filterG (f arr) xs    where f arr1 arr2 = all (\k -> unsafeAt arr2 k == k) arr1
Languages/UniquenessPeriods/Array/Constraints/Encoded.hs view
@@ -2,7 +2,7 @@  -- | -- Module      :  Languages.UniquenessPeriods.Array.Constraints.Encoded--- Copyright   :  (c) OleksandrZhabenko 2020+-- Copyright   :  (c) OleksandrZhabenko 2020-2022 -- License     :  MIT -- Stability   :  Experimental -- Maintainer  :  olexandr543@yahoo.com@@ -28,6 +28,7 @@   , setIEl   -- ** Predicates   , isE+  , isP   , isF   , isQ   , isT@@ -42,7 +43,7 @@ import Languages.UniquenessPeriods.Array.Constraints import Data.SubG (InsertLeft(..)) -data EncodedContraints a b = E a | Q a a a a a | T a a a a | SA a a b | SB a a b | F a a a deriving (Eq, Ord)+data EncodedContraints a b = E a | P a b | Q a a a a a | T a a a a | SA a a b | SB a a b | F a a a deriving (Eq, Ord)  -- | Inspired by the: https://hackage.haskell.org/package/base-4.14.0.0/docs/Data-Maybe.html -- Is provided here as a more general way to read the 'String' into a 'EncodedCnstrs' than more restricted@@ -91,6 +92,7 @@           (_,_,Nothing,_) -> Nothing           (_,_,_,Nothing) -> Nothing           ~(Just x1, Just x2, Just x3, Just x4) -> Just (Q undefined x1 x2 x3 x4)+       "P" -> if null ts then Just (E 0) else let l = length ts in Just . P n . listArray (0,l-1) . map (\x -> case (fromJust (readMaybe [x]::Maybe Int)) of {0 -> 9; n -> n - 1}) $ ts        _   -> Nothing  | otherwise = Nothing @@ -98,6 +100,7 @@ setWordsN :: Int -> Maybe EncodedCnstrs -> Maybe EncodedCnstrs setWordsN _ Nothing = Nothing setWordsN _ (Just (E x)) = Just (E x)+setWordsN n (Just (P _ v)) = Just (P n v) setWordsN n (Just (T _ i j k)) = Just (T n i j k) setWordsN n (Just (Q _ i j k l)) = Just (Q n i j k l) setWordsN n (Just (SA _ i v)) = Just (SA n i v)@@ -107,7 +110,7 @@ -- | A safer variant of the 'readMaybeEC' more suitable for applications, e. g. for phonetic-languages series of packages. readMaybeECG :: Int -> String -> Maybe EncodedCnstrs readMaybeECG n xs-  | n <= 6 && n >=0 = setWordsN n . readMaybeEC n $ xs+  | n <= 9 && n >=0 = setWordsN n . readMaybeEC n $ xs   | otherwise = Nothing  type EncodedCnstrs = EncodedContraints Int (Array Int Int)@@ -117,6 +120,7 @@ -- @n@ is (probably must be) not greater than 6. decodeConstraint1 :: (InsertLeft t (Array Int Int), Monoid (t (Array Int Int))) => EncodedCnstrs -> t (Array Int Int) -> t (Array Int Int) decodeConstraint1 (E _) = id+decodeConstraint1 (P _ v) = fixedPointsS v decodeConstraint1 (Q _ i j k l) = unsafeQuadruples i j k l decodeConstraint1 (T _ i j k) = unsafeTriples i j k decodeConstraint1 (SA _ i v) = unsafeSeveralA i v@@ -141,6 +145,10 @@ isE (E _) = True isE _ = False +isP :: EncodedCnstrs -> Bool+isP (P _ _) = True+isP _ = False+ isF :: EncodedCnstrs -> Bool isF (F _ _ _) = True isF _ = False@@ -161,20 +169,24 @@ isSB (SB _ _ _) = True isSB _ = False +{-| Works only with the correctly defined argument though it is not checked. Use with this caution.+-} getIEl :: EncodedCnstrs -> Int getIEl (E i) = i+getIEl (P _ arr) = unsafeAt arr 0 getIEl (Q _ i _ _ _) = i getIEl (T _ i _ _) = i getIEl (SA _ i _) = i getIEl (SB _ i _) = i getIEl (F _ i _) = i +{-| Works only with the correctly defined arguments though it is not checked. Use with this caution.+-} setIEl :: Int -> EncodedCnstrs -> EncodedCnstrs setIEl i (E _) = E i+setIEl i (P n arr) = P n (arr // [(0,i)]) setIEl i (Q n _ j k l) = Q n i j k l setIEl i (T n _ j k) = T n i j k setIEl i (SA n _ v) = SA n i v setIEl i (SB n _ v) = SB n i v setIEl i (F n _ j) = F n i j--
phonetic-languages-constraints-array.cabal view
@@ -2,7 +2,7 @@ -- For further documentation, see http://haskell.org/cabal/users-guide/  name:                phonetic-languages-constraints-array-version:             0.1.1.0+version:             0.1.2.0 synopsis:            Constraints to filter the needed permutations description:         Provides several the most important variants of constraints. Can be used with the phonetic-languages-common series of package. Instead of vectors, uses arrays. homepage:            https://hackage.haskell.org/package/phonetic-languages-constraints-array@@ -20,6 +20,6 @@   exposed-modules:     Languages.UniquenessPeriods.Array.Constraints, Languages.UniquenessPeriods.Array.Constraints.Encoded   -- other-modules:   other-extensions:    BangPatterns, FlexibleInstances, FlexibleContexts-  build-depends:       base >=4.8 && <5, subG >= 0.5.3 && <1+  build-depends:       base >=4.8 && <5, subG == 0.5.3.0   -- hs-source-dirs:   default-language:    Haskell2010