From 6926ae6fc92dede6bb563a9cddd3dc924346f31b Mon Sep 17 00:00:00 2001 From: OleksandrZhabenko Date: Mon, 28 Dec 2020 13:01:10 +0200 Subject: [PATCH] Update on Hackage --- CHANGELOG.md | 14 ++++++ LICENSE | 20 +++++++++ Phonetic/Languages/Permutations.hs | 65 +++++++++++++++++++++++++++ Setup.hs | 2 + phonetic-languages-permutations.cabal | 25 +++++++++++ 5 files changed, 126 insertions(+) create mode 100644 CHANGELOG.md create mode 100644 LICENSE create mode 100644 Phonetic/Languages/Permutations.hs create mode 100644 Setup.hs create mode 100644 phonetic-languages-permutations.cabal diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..b1e5272 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,14 @@ +# Revision history for phonetic-languages-permutations + +## 0.1.0.0 -- 2020-11-19 + +* First version. Released on an unsuspecting world. + +## 0.1.1.0 -- 2020-11-19 + +* First version revised A. Some code improvements. + +## 0.2.0.0 -- 2020-11-20 + +* Second version. Added three more functions for permutations. + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2eaab6b --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2020 OleksandrZhabenko + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/Phonetic/Languages/Permutations.hs b/Phonetic/Languages/Permutations.hs new file mode 100644 index 0000000..1995fd9 --- /dev/null +++ b/Phonetic/Languages/Permutations.hs @@ -0,0 +1,65 @@ +-- | +-- Module : Phonetic.Languages.Permutations +-- Copyright : (c) OleksandrZhabenko 2020 +-- License : MIT +-- Stability : Experimental +-- Maintainer : olexandr543@yahoo.com +-- +-- Commonly used versions of the @phonetic-languages-common@ package functions. + +module Phonetic.Languages.Permutations ( + universalSetG + , universalSetGL + , genPermutations + , genPermutationsV + , genPermutationsL + , genPermutationsVL +) where + +import qualified Data.Vector as VB +import qualified Data.List as L (permutations) +import Data.SubG +import Data.SubG.InstancesPlus () +import qualified Data.Foldable as F (concat,foldr') +--import Data.List () +import Data.Monoid + +-- | A key point of the evaluation -- the universal set of the task represented as a 'VB.Vector' of 'VB.Vector' of @a@. +universalSetG :: + (Eq a, Foldable t, InsertLeft t a, Monoid (t a), Monoid (t (t a))) => t a + -> t (t a) + -> (t a -> VB.Vector a) -- ^ The function that is used internally to convert to the boxed 'VB.Vector' of @a@ so that the function can process further the permutations + -> ((t (t a)) -> VB.Vector (VB.Vector a)) -- ^ The function that is used internally to convert to the boxed 'VB.Vector' of 'VB.Vector' of @a@ so that the function can process further + -> VB.Vector (VB.Vector Int) -- ^ The list of permutations of 'Int' indices starting from 0 and up to n (n is probably less than 7). + -> VB.Vector (VB.Vector a) + -> VB.Vector (VB.Vector a) +universalSetG ts uss f1 f2 perms baseV = VB.map (VB.foldr' mappend mempty . VB.cons (f1 ts) . (`mappend` (f2 uss)) . VB.unsafeBackpermute baseV) perms +{-# INLINE universalSetG #-} + +-- | A key point of the evaluation -- the universal set of the task represented as a 'VB.Vector' of 'VB.Vector' of @a@. Because the order is not +universalSetGL :: + (Eq a, Foldable t, InsertLeft t a, Monoid (t a), Monoid (t (t a))) => t a + -> t (t a) + -> (t a -> [a]) -- ^ The function that is used internally to convert to the @[a]@ so that the function can process further the permutations + -> ((t (t a)) -> [[a]]) -- ^ The function that is used internally to convert to the needed representation so that the function can process further + -> [VB.Vector Int] -- ^ The list of permutations of 'Int' indices starting from 0 and up to n (n is probably less than 7). + -> VB.Vector [a] + -> [[a]] +universalSetGL ts uss f1 f2 permsL baseV = map (F.concat . F.foldr' (:) [] . (f1 ts:) . (`mappend` f2 uss) . VB.toList . VB.unsafeBackpermute baseV) permsL +{-# INLINE universalSetGL #-} + +genPermutations :: Int -> VB.Vector (VB.Vector Int) +genPermutations n = VB.map VB.fromList . VB.fromList . L.permutations . take n $ [0..] +{-# INLINE genPermutations #-} + +genPermutationsV :: VB.Vector (VB.Vector (VB.Vector Int)) +genPermutationsV = VB.map (\n -> VB.map VB.fromList . VB.fromList . L.permutations . take n $ [0..]) . VB.enumFromTo 2 $ 7 +{-# INLINE genPermutationsV #-} + +genPermutationsL :: Int -> [VB.Vector Int] +genPermutationsL n = map VB.fromList . L.permutations . take n $ [0..] +{-# INLINE genPermutationsL #-} + +genPermutationsVL :: VB.Vector [VB.Vector Int] +genPermutationsVL = VB.map (\n -> map VB.fromList . L.permutations . take n $ [0..]) . VB.enumFromTo 2 $ 7 +{-# INLINE genPermutationsVL #-} diff --git a/Setup.hs b/Setup.hs new file mode 100644 index 0000000..9a994af --- /dev/null +++ b/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/phonetic-languages-permutations.cabal b/phonetic-languages-permutations.cabal new file mode 100644 index 0000000..a765b2c --- /dev/null +++ b/phonetic-languages-permutations.cabal @@ -0,0 +1,25 @@ +-- Initial phonetic-languages-permutations.cabal generated by cabal init. +-- For further documentation, see http://haskell.org/cabal/users-guide/ + +name: phonetic-languages-permutations +version: 0.2.0.0 +synopsis: Commonly used versions of the phonetic-languages-common package +description: Permutations-related to produce universal set of the task. +homepage: https://hackage.haskell.org/package/phonetic-languages-permutations +license: MIT +license-file: LICENSE +author: OleksandrZhabenko +maintainer: olexandr543@yahoo.com +copyright: Oleksandr Zhabenko +category: Language,Math,Game +build-type: Simple +extra-source-files: CHANGELOG.md +cabal-version: >=1.10 + +library + exposed-modules: Phonetic.Languages.Permutations + -- other-modules: + -- other-extensions: + build-depends: base >=4.8 && <4.15, vector >=0.11 && <0.14, subG >=0.4.2 && <1, subG-instances >=0.1 && <1 + -- hs-source-dirs: + default-language: Haskell2010