packages feed

phonetic-languages-permutations-array 0.4.0.0 → 0.5.0.0

raw patch · 7 files changed

+95/−46 lines, 7 filesdep +monoid-insertleftdep −subGPVP ok

version bump matches the API change (PVP)

Dependencies added: monoid-insertleft

Dependencies removed: subG

API changes (from Hackage documentation)

- Phladiprelio.PermutationsArr: genPermutations :: Int -> Array Int [Int]
+ Phladiprelio.PermutationsArr: genPermutations :: (Ord a, Enum a, Num a) => Int -> Array Int [a]
- Phladiprelio.PermutationsArr: genPermutationsArr :: Array Int (Array Int [Int])
+ Phladiprelio.PermutationsArr: genPermutationsArr :: (Ord a, Enum a, Num a) => Array Int (Array Int [a])
- Phladiprelio.PermutationsArr: genPermutationsArrL :: Array Int [Array Int Int]
+ Phladiprelio.PermutationsArr: genPermutationsArrL :: (Ord a, Enum a, Num a) => Array Int [Array Int a]
- Phladiprelio.PermutationsArr: genPermutationsL :: Int -> [Array Int Int]
+ Phladiprelio.PermutationsArr: genPermutationsL :: (Ord a, Enum a, Num a) => Int -> [Array Int a]
- Phladiprelio.PermutationsArrMini: genPairwisePermutations :: Int -> Array Int [Int]
+ Phladiprelio.PermutationsArrMini: genPairwisePermutations :: (Ord a, Enum a, Num a) => Int -> Array Int [a]
- Phladiprelio.PermutationsArrMini: genPairwisePermutationsArr :: Array Int (Array Int [Int])
+ Phladiprelio.PermutationsArrMini: genPairwisePermutationsArr :: (Ord a, Enum a, Num a) => Array Int (Array Int [a])
- Phladiprelio.PermutationsArrMini: genPairwisePermutationsArrL :: Array Int [Array Int Int]
+ Phladiprelio.PermutationsArrMini: genPairwisePermutationsArrL :: (Ord a, Enum a, Num a) => Array Int [Array Int a]
- Phladiprelio.PermutationsArrMini: genPairwisePermutationsArrLN :: Int -> Array Int [Array Int Int]
+ Phladiprelio.PermutationsArrMini: genPairwisePermutationsArrLN :: (Ord a, Enum a, Num a) => Int -> Array Int [Array Int a]
- Phladiprelio.PermutationsArrMini: genPairwisePermutationsArrN :: Int -> Array Int (Array Int [Int])
+ Phladiprelio.PermutationsArrMini: genPairwisePermutationsArrN :: (Ord a, Enum a, Num a) => Int -> Array Int (Array Int [a])
- Phladiprelio.PermutationsArrMini: genPairwisePermutationsL :: [Array Int Int]
+ Phladiprelio.PermutationsArrMini: genPairwisePermutationsL :: (Ord a, Enum a, Num a) => [Array Int a]
- Phladiprelio.PermutationsArrMini: genPairwisePermutationsLN :: Int -> [Array Int Int]
+ Phladiprelio.PermutationsArrMini: genPairwisePermutationsLN :: (Ord a, Enum a, Num a) => Int -> [Array Int a]
- Phladiprelio.PermutationsArrMini: pairsSwapP :: [Int] -> [[Int]]
+ Phladiprelio.PermutationsArrMini: pairsSwapP :: (Ord a, Enum a, Num a) => [a] -> [[a]]
- Phladiprelio.PermutationsArrMini1: genElementaryPermutations1 :: Int -> Array Int [Int]
+ Phladiprelio.PermutationsArrMini1: genElementaryPermutations1 :: (Ord a, Enum a, Num a) => Int -> Array Int [a]
- Phladiprelio.PermutationsArrMini1: genElementaryPermutationsArr1 :: Array Int (Array Int [Int])
+ Phladiprelio.PermutationsArrMini1: genElementaryPermutationsArr1 :: (Ord a, Enum a, Num a) => Array Int (Array Int [a])
- Phladiprelio.PermutationsArrMini1: genElementaryPermutationsArrL1 :: Array Int [Array Int Int]
+ Phladiprelio.PermutationsArrMini1: genElementaryPermutationsArrL1 :: (Ord a, Enum a, Num a) => Array Int [Array Int a]
- Phladiprelio.PermutationsArrMini1: genElementaryPermutationsArrLN1 :: Int -> Array Int [Array Int Int]
+ Phladiprelio.PermutationsArrMini1: genElementaryPermutationsArrLN1 :: (Ord a, Enum a, Num a) => Int -> Array Int [Array Int a]
- Phladiprelio.PermutationsArrMini1: genElementaryPermutationsArrN1 :: Int -> Array Int (Array Int [Int])
+ Phladiprelio.PermutationsArrMini1: genElementaryPermutationsArrN1 :: (Ord a, Enum a, Num a) => Int -> Array Int (Array Int [a])
- Phladiprelio.PermutationsArrMini1: genElementaryPermutationsL1 :: [Array Int Int]
+ Phladiprelio.PermutationsArrMini1: genElementaryPermutationsL1 :: (Ord a, Enum a, Num a) => [Array Int a]
- Phladiprelio.PermutationsArrMini1: genElementaryPermutationsLN1 :: Int -> [Array Int Int]
+ Phladiprelio.PermutationsArrMini1: genElementaryPermutationsLN1 :: (Ord a, Enum a, Num a) => Int -> [Array Int a]
- Phladiprelio.PermutationsArrMini1: pairsSwapP1 :: [Int] -> [[Int]]
+ Phladiprelio.PermutationsArrMini1: pairsSwapP1 :: (Ord a, Num a) => [a] -> [[a]]

Files

CHANGELOG.md view
@@ -41,3 +41,7 @@ * Fourth version. Switched to NoImplicitPrelude extension. Some minor code improvements.  Changed the names of the modules. Updated the dependencies boundaries. +## 0.5.0.0 -- 2024-01-23++* Fifth version. Switched to using more general function signatures with specializing. Added devotion. Some minor code improvements. Added README.md file. Switched to better dependency of monoid-insertleft.+
Phladiprelio/PermutationsArr.hs view
@@ -2,12 +2,12 @@  -- | -- Module      :  Phladiprelio.PermutationsArr--- Copyright   :  (c) OleksandrZhabenko 2020-2023+-- Copyright   :  (c) OleksandrZhabenko 2020-2024 -- License     :  MIT -- Stability   :  Experimental -- Maintainer  :  oleksandr.zhabenko@yahoo.com ----- Permutations and universal set functions for the phonetic-languages series of packages+-- Permutations and universal set functions for the phonetic-languages series and phladiprelio of packages -- (PhLADiPreLiO-related). This module uses no vectors, but instead uses arrays.  module Phladiprelio.PermutationsArr (@@ -18,12 +18,13 @@   , genPermutationsArrL ) where +import GHC.Enum import GHC.List-import GHC.Num ((*), (-))+import GHC.Num (Num,(*), (-)) import GHC.Base import GHC.Arr-import qualified Data.List as L (permutations)-import Data.SubG+import qualified Data.List as L (permutations,product)+import Data.InsertLeft import qualified Data.Foldable as F (Foldable,concat,foldr',foldl') import Data.Monoid @@ -38,23 +39,25 @@   -> [[a]] universalSetGL ts uss f1 f2 permsL baseArr = map (F.concat . F.foldr' (:) [] . (f1 ts:) . (`mappend` f2 uss) . elems . amap (unsafeAt baseArr)) permsL {-# INLINE universalSetGL #-}---- | One of the popular examples:  realization of the factorial function using 'F.foldl''. Is taken from some--- teaching material.-factorial n = F.foldl' (*) 1 [1..n]+{-# SPECIALIZE universalSetGL :: String -> [String] -> (String -> String) -> ([String] -> [String]) -> [Array Int Int] -> Array Int String -> [String]   #-} -genPermutations :: Int -> Array Int [Int]-genPermutations n = listArray (0,factorial n - 1) . L.permutations . take n $ [0..]+genPermutations ::  (Ord a, Enum a, Num a) => Int -> Array Int [a]+genPermutations n = listArray (0,L.product [1..(n - 1)]) . L.permutations . take n $ [0..] {-# INLINE genPermutations #-}+{-# SPECIALIZE genPermutations :: Int  -> Array Int [Int] #-} -genPermutationsArr :: Array Int (Array Int [Int])+genPermutationsArr ::  (Ord a, Enum a, Num a) => Array Int (Array Int [a]) genPermutationsArr = amap genPermutations . listArray (0,5) $ [2..7] {-# INLINE genPermutationsArr #-}+{-# SPECIALIZE genPermutationsArr :: Array Int (Array Int [Int]) #-} -genPermutationsL :: Int -> [Array Int Int]+genPermutationsL ::  (Ord a, Enum a, Num a) => Int -> [Array Int a] genPermutationsL n = map (\xs -> listArray (0,n - 1) xs) . L.permutations . take n $ [0..] {-# INLINE genPermutationsL #-}+{-# SPECIALIZE genPermutationsL :: Int  -> [Array Int Int] #-} -genPermutationsArrL :: Array Int [Array Int Int]+genPermutationsArrL ::  (Ord a, Enum a, Num a) => Array Int [Array Int a] genPermutationsArrL = amap genPermutationsL . listArray (0,5) $ [2..7] {-# INLINE genPermutationsArrL #-}+{-# SPECIALIZE genPermutationsArrL :: Array Int [Array Int Int] #-}+
Phladiprelio/PermutationsArrMini.hs view
@@ -2,12 +2,12 @@  -- | -- Module      :  Phladiprelio.PermutationsArrMini--- Copyright   :  (c) OleksandrZhabenko 2021-2023+-- Copyright   :  (c) OleksandrZhabenko 2021-2024 -- License     :  MIT -- Stability   :  Experimental -- Maintainer  :  oleksandr.zhabenko@yahoo.com ----- Special permutations functions for the phonetic-languages series of packages. This+-- Special permutations functions for the phonetic-languages and phladiprelio series of packages. This -- module uses no vectors, but instead uses arrays.  module Phladiprelio.PermutationsArrMini (@@ -21,53 +21,62 @@   , genPairwisePermutationsArrL ) where +import GHC.Enum import Data.Bits (shiftR) import GHC.Base import GHC.Num import GHC.List import GHC.Arr -genPairwisePermutations :: Int -> Array Int [Int]+genPairwisePermutations :: (Ord a, Enum a, Num a) => Int -> Array Int [a] genPairwisePermutations n = listArray (0, shiftR (n*(n-1)) 1) . pairsSwapP . take n $ [0..] {-# INLINE genPairwisePermutations #-}+{-# SPECIALIZE genPairwisePermutations :: Int -> Array Int [Int] #-} -pairsSwapP :: [Int] -> [[Int]]+pairsSwapP :: (Ord a, Enum a, Num a) => [a] -> [[a]] pairsSwapP xs = xs:[swap2Ls k m xs | k <- xs, m <- xs , k < m]-{-# INLINABLE pairsSwapP #-}+{-# SPECIALIZE pairsSwapP :: [Int] -> [[Int]] #-}  -- | The first two arguments are considered not equal, though it is not checked.-swap2ns :: Int -> Int -> Int -> Int+swap2ns :: (Eq a) => a -> a -> a -> a swap2ns k m n  | n /= k = if n /= m then n else k  | otherwise = m {-# INLINE swap2ns #-}+{-# SPECIALIZE swap2ns :: Int -> Int -> Int -> Int #-} -swap2Ls :: Int -> Int -> [Int] -> [Int]+swap2Ls :: (Eq a) => a -> a -> [a] -> [a] swap2Ls k m = map (swap2ns k m) {-# INLINE swap2Ls #-}+{-# SPECIALIZE swap2Ls :: Int -> Int -> [Int] -> [Int] #-} -genPairwisePermutationsArrN :: Int -> Array Int (Array Int [Int])+genPairwisePermutationsArrN ::  (Ord a, Enum a, Num a) => Int -> Array Int (Array Int [a]) genPairwisePermutationsArrN n = amap genPairwisePermutations . listArray (0,n - 2) $ [2..n] {-# INLINE genPairwisePermutationsArrN #-}+{-# SPECIALIZE genPairwisePermutationsArrN :: Int -> Array Int (Array Int [Int]) #-} -genPairwisePermutationsArr :: Array Int (Array Int [Int])+genPairwisePermutationsArr ::  (Ord a, Enum a, Num a) => Array Int (Array Int [a]) genPairwisePermutationsArr = genPairwisePermutationsArrN 10 {-# INLINE genPairwisePermutationsArr #-}+{-# SPECIALIZE genPairwisePermutationsArr :: Array Int (Array Int [Int]) #-} -genPairwisePermutationsLN :: Int -> [Array Int Int]+genPairwisePermutationsLN ::  (Ord a, Enum a, Num a) => Int -> [Array Int a] genPairwisePermutationsLN n = map (\xs -> listArray (0,n - 1) xs) . pairsSwapP . take n $ [0..] {-# INLINE genPairwisePermutationsLN #-}+{-# SPECIALIZE genPairwisePermutationsLN :: Int -> [Array Int Int] #-} -genPairwisePermutationsL :: [Array Int Int]+genPairwisePermutationsL ::  (Ord a, Enum a, Num a) => [Array Int a] genPairwisePermutationsL = genPairwisePermutationsLN 10 {-# INLINE genPairwisePermutationsL #-}+{-# SPECIALIZE genPairwisePermutationsL :: [Array Int Int] #-} -genPairwisePermutationsArrLN :: Int -> Array Int [Array Int Int]+genPairwisePermutationsArrLN ::  (Ord a, Enum a, Num a) => Int -> Array Int [Array Int a] genPairwisePermutationsArrLN n = amap genPairwisePermutationsLN . listArray (0,n - 2) $ [2..n] {-# INLINE genPairwisePermutationsArrLN #-}+{-# SPECIALIZE genPairwisePermutationsArrLN :: Int -> Array Int [Array Int Int] #-} -genPairwisePermutationsArrL :: Array Int [Array Int Int]+genPairwisePermutationsArrL ::  (Ord a, Enum a, Num a) => Array Int [Array Int a] genPairwisePermutationsArrL = genPairwisePermutationsArrLN 10 {-# INLINE genPairwisePermutationsArrL #-}-+{-# SPECIALIZE genPairwisePermutationsArrL :: Array Int [Array Int Int] #-} 
Phladiprelio/PermutationsArrMini1.hs view
@@ -4,12 +4,12 @@  -- | -- Module      :  Phladiprelio.PermutationsArrMini1--- Copyright   :  (c) OleksandrZhabenko 2022-2023+-- Copyright   :  (c) OleksandrZhabenko 2022-2024 -- License     :  MIT -- Stability   :  Experimental -- Maintainer  :  oleksandr.zhabenko@yahoo.com ----- Special permutations functions for the phonetic-languages series of packages. This+-- Special permutations functions for the phonetic-languages and phladiprelio series of packages. This -- module uses no vectors, but instead uses arrays.  module Phladiprelio.PermutationsArrMini1 (@@ -26,20 +26,22 @@ import GHC.Base import GHC.Arr import GHC.List-import GHC.Num ((-), (+), abs)+import GHC.Num (Num,(-), (+), abs)+import GHC.Enum -genElementaryPermutations1 :: Int -> Array Int [Int]+genElementaryPermutations1 :: (Ord a, Enum a, Num a) => Int -> Array Int [a] genElementaryPermutations1 n = listArray (0,l-1) xs  where xs = pairsSwapP1 . take n $ [0..]        l = length xs {-# INLINE genElementaryPermutations1 #-}+{-# SPECIALIZE genElementaryPermutations1 :: Int -> Array Int [Int] #-} -pairsSwapP1 :: [Int] -> [[Int]]+pairsSwapP1 ::  (Ord a, Num a) => [a] -> [[a]] pairsSwapP1 xs = xs:[swap2Ls1 k m xs | k <- xs, m <- xs , abs (k - m) > 1] `mappend` [swap2Ls1 k (k - 1) xs | k <- drop 1 xs ]-{-# INLINABLE pairsSwapP1 #-}+{-# SPECIALIZE pairsSwapP1 :: [Int] -> [[Int]] #-}  -- | The first two arguments are considered not equal and all three of the arguments are considered greater or equal to 0, though it is not checked.-swap2ns1 :: Int -> Int -> Int -> Int+swap2ns1 ::  (Ord a, Num a) => a -> a -> a -> a swap2ns1 k n m  | n > k =     if@@ -54,31 +56,40 @@        | m > n -> m - 1        | otherwise -> k {-# INLINE swap2ns1 #-}+{-# SPECIALIZE swap2ns1 :: Int -> Int -> Int -> Int #-} -swap2Ls1 :: Int -> Int -> [Int] -> [Int]+swap2Ls1 ::  (Ord a, Num a) => a -> a -> [a] -> [a] swap2Ls1 k m = map (swap2ns1 k m) {-# INLINE swap2Ls1 #-}+{-# SPECIALIZE swap2Ls1 :: Int -> Int -> [Int] -> [Int] #-} -genElementaryPermutationsArrN1 :: Int -> Array Int (Array Int [Int])+genElementaryPermutationsArrN1 ::  (Ord a, Enum a, Num a) => Int -> Array Int (Array Int [a]) genElementaryPermutationsArrN1 n = amap genElementaryPermutations1 . listArray (0,n - 2) $ [2..n] {-# INLINE genElementaryPermutationsArrN1 #-}+{-# SPECIALIZE genElementaryPermutationsArrN1 :: Int -> Array Int (Array Int [Int]) #-} -genElementaryPermutationsArr1 :: Array Int (Array Int [Int])+genElementaryPermutationsArr1 ::  (Ord a, Enum a, Num a) => Array Int (Array Int [a]) genElementaryPermutationsArr1 = genElementaryPermutationsArrN1 10 {-# INLINE genElementaryPermutationsArr1 #-}+{-# SPECIALIZE genElementaryPermutationsArr1 :: Array Int (Array Int [Int]) #-} -genElementaryPermutationsLN1 :: Int -> [Array Int Int]+genElementaryPermutationsLN1 ::  (Ord a, Enum a, Num a) => Int -> [Array Int a] genElementaryPermutationsLN1 n = map (\xs -> listArray (0,n - 1) xs) . pairsSwapP1 . take n $ [0..] {-# INLINE genElementaryPermutationsLN1 #-}+{-# SPECIALIZE genElementaryPermutationsLN1 :: Int -> [Array Int Int] #-} -genElementaryPermutationsL1 :: [Array Int Int]+genElementaryPermutationsL1 ::  (Ord a, Enum a, Num a) => [Array Int a] genElementaryPermutationsL1 = genElementaryPermutationsLN1 10 {-# INLINE genElementaryPermutationsL1 #-}+{-# SPECIALIZE genElementaryPermutationsL1 :: [Array Int Int] #-} -genElementaryPermutationsArrLN1 :: Int -> Array Int [Array Int Int]+genElementaryPermutationsArrLN1 ::  (Ord a, Enum a, Num a) => Int -> Array Int [Array Int a] genElementaryPermutationsArrLN1 n = amap genElementaryPermutationsLN1 . listArray (0,n - 2) $ [2..n] {-# INLINE genElementaryPermutationsArrLN1 #-}+{-# SPECIALIZE genElementaryPermutationsArrLN1 :: Int -> Array Int [Array Int Int] #-} -genElementaryPermutationsArrL1 :: Array Int [Array Int Int]+genElementaryPermutationsArrL1 ::  (Ord a, Enum a, Num a) => Array Int [Array Int a] genElementaryPermutationsArrL1 = genElementaryPermutationsArrLN1 10 {-# INLINE genElementaryPermutationsArrL1 #-}+{-# SPECIALIZE genElementaryPermutationsArrL1 :: Array Int [Array Int Int] #-}+
Phladiprelio/PermutationsRepresent.hs view
@@ -16,7 +16,6 @@  import GHC.Base import Text.Show---import Data.Monoid  data PermutationsType = P Int deriving (Eq, Ord) 
+ README.md view
@@ -0,0 +1,22 @@+ Devotion+ ========++The author would like to devote this project to support the [Foundation Gastrostars](https://gastrostars.nl).++The foundation founder is [Emma Kok](https://www.emmakok.nl).++On the 06/01/2024 there is Sophie's Kok, a sister of Emma Kok, 19th Birthday (she is 18). Therefore, the version 0.5.0.0 is additionally devoted also to her. On the 22/01/2023 there is Day of Unity of Ukraine, and on the 23/01/2024 the Orthodox Christians have memory of St. Paulinus of Nola.++Besides, you can support Ukraine and Ukrainian people. ++All support is welcome, including donations for the needs of the Ukrainian army, IDPs and refugees.++If you would like to share some financial support with Gastrostars, please, contact the mentioned foundation+using the URL:++[Contact Foundation GASTROSTARS](https://gastrostars.nl/hou-mij-op-de-hoogte)++or ++[Donation Page](https://gastrostars.nl/doneren)+
phonetic-languages-permutations-array.cabal view
@@ -2,10 +2,11 @@ -- For further documentation, see http://haskell.org/cabal/users-guide/  name:                phonetic-languages-permutations-array-version:             0.4.0.0+version:             0.5.0.0 synopsis:            Permutations and universal set related functions for the phonetic-languages series description:         Permutations-related to produce universal set of the task. Uses arrays instead of vectors. homepage:            https://hackage.haskell.org/package/phonetic-languages-permutations-array+bug-reports:         https://github.com/Oleksandr-Zhabenko/phonetic-languages-permutations-array/issues license:             MIT license-file:        LICENSE author:              OleksandrZhabenko@@ -13,13 +14,13 @@ copyright:           Oleksandr Zhabenko category:            Language,Math,Game build-type:          Simple-extra-source-files:  CHANGELOG.md+extra-source-files:  CHANGELOG.md, README.md cabal-version:       >=1.10  library   exposed-modules:     Phladiprelio.PermutationsArr, Phladiprelio.PermutationsArrMini, Phladiprelio.PermutationsArrMini1, Phladiprelio.PermutationsRepresent   -- other-modules:   other-extensions:    MultiWayIf, NoImplicitPrelude-  build-depends:       base >=4.13 && <5, subG ==0.6.1.0+  build-depends:       base >=4.13 && <5, monoid-insertleft ==0.1.0.1   -- hs-source-dirs:   default-language:    Haskell2010