{-# LANGUAGE CPP, BangPatterns #-}
module DobutokO.Poetry.StrictV where
#ifdef __GLASGOW_HASKELL__
#if __GLASGOW_HASKELL__>=804
/* code that applies only to GHC 8.4.* and higher versions */
import Data.Semigroup ((<>))
import Prelude hiding ((<>))
#endif
#endif
import qualified Data.Vector as V
import qualified Data.List as L (permutations)
uniquenessVariants2GN :: V.Vector ([Int] -> Int) -> (String -> [Int]) -> String -> V.Vector ([Int],V.Vector Int, String)
uniquenessVariants2GN vN g !xs = uniquenessVariants2GNP [] [] vN g xs
{-# INLINE uniquenessVariants2GN #-}
uniquenessVariants2GNP :: String -> String -> V.Vector ([Int] -> Int) -> (String -> [Int]) -> String -> V.Vector ([Int],V.Vector Int, String)
uniquenessVariants2GNP !ts !us vN g !xs
| null . words $ xs = V.empty
| otherwise = let !v0 = V.fromList . take 8 . words $ xs in
V.fromList . map ((\vs -> let !rs = g vs in (rs, (V.map (\f -> f rs) vN), vs)) . unwords . preAppend ts [us] . V.toList .
V.backpermute v0 . V.fromList) . L.permutations $ ([0..(V.length v0 - 1)]::[Int])
preAppend :: [a] -> [[a]] -> [[a]] -> [[a]]
#ifdef __GLASGOW_HASKELL__
#if __GLASGOW_HASKELL__>=804
preAppend ts !uss tss = ts:tss <> uss
#endif
#endif
#ifdef __GLASGOW_HASKELL__
#if __GLASGOW_HASKELL__<804
preAppend ts !uss tss = ts:tss ++ uss
#endif
#endif
{-# INLINE preAppend #-}