-- | -- 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 , genPermutations , genPermutationsV ) where import qualified Data.Vector as VB import qualified Data.List as L (permutations) import Data.SubG import Data.SubG.InstancesPlus () 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 #-} 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 #-}