-- |
-- Module      :  Phonetic.Languages.Simplified.StrictVG
-- Copyright   :  (c) OleksandrZhabenko 2020
-- License     :  MIT
-- Stability   :  Experimental
-- Maintainer  :  olexandr543@yahoo.com
--
-- Simplified version of the @phonetic-languages-common@ package.

{-# LANGUAGE BangPatterns #-}

module Phonetic.Languages.Simplified.StrictVG (
  -- * Working with vectors
  uniquenessVariants2GNB
  , uniquenessVariants2GNPB
  -- * Working with lists
  , uniquenessVariants2GNBL
  , uniquenessVariants2GNPBL
) where

import Phonetic.Languages.Permutations
import qualified Data.Vector as VB
import Phonetic.Languages.Simplified.DataG
import qualified Data.Foldable as F
import Data.SubG
import Data.SubG.InstancesPlus ()
import Data.Monoid

uniquenessVariants2GNB ::
  (Eq a, Foldable t, InsertLeft t a, Monoid (t a), Monoid (t (t a))) => a -- ^ The first most common element in the \"whitespace symbols\" structure
  -> (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 a -> t a) -- ^ The function that is used internally to convert from the boxed 'VB.Vector' of @a@ so that the function can process further
  -> VB.Vector (VB.Vector Int) -- ^ The permutations of 'Int' indices starting from 0 and up to n (n is probably less than 8).
  -> t (t a) -- ^ Must be obtained as 'subG' @whspss xs@
  -> VB.Vector (t a)
uniquenessVariants2GNB :: a
-> (t a -> Vector a)
-> (t (t a) -> Vector (Vector a))
-> (Vector a -> t a)
-> Vector (Vector Int)
-> t (t a)
-> Vector (t a)
uniquenessVariants2GNB !a
hd t a -> Vector a
f1 t (t a) -> Vector (Vector a)
f2 Vector a -> t a
f3 Vector (Vector Int)
perms !t (t a)
subs = t a
-> t a
-> a
-> (t a -> Vector a)
-> (t (t a) -> Vector (Vector a))
-> (Vector a -> t a)
-> Vector (Vector Int)
-> t (t a)
-> Vector (t a)
forall a (t :: * -> *).
(Eq a, Foldable t, InsertLeft t a, Monoid (t a),
 Monoid (t (t a))) =>
t a
-> t a
-> a
-> (t a -> Vector a)
-> (t (t a) -> Vector (Vector a))
-> (Vector a -> t a)
-> Vector (Vector Int)
-> t (t a)
-> Vector (t a)
uniquenessVariants2GNPB t a
forall a. Monoid a => a
mempty t a
forall a. Monoid a => a
mempty a
hd t a -> Vector a
f1 t (t a) -> Vector (Vector a)
f2 Vector a -> t a
f3 Vector (Vector Int)
perms t (t a)
subs
{-# INLINE uniquenessVariants2GNB #-}

uniquenessVariants2GNPB ::
  (Eq a, Foldable t, InsertLeft t a, Monoid (t a), Monoid (t (t a))) => t a
  -> t a
  ->  a -- ^ The first most common element in the whitespace symbols structure
  -> (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 a -> t a) -- ^ The function that is used internally to convert from the boxed 'VB.Vector' of @a@ so that the function can process further
  -> VB.Vector (VB.Vector Int) -- ^ The permutations of 'Int' indices starting from 0 and up to n (n is probably less than 7).
  -> t (t a) -- ^ Must be obtained as @subG whspss xs@
  -> VB.Vector (t a)
uniquenessVariants2GNPB :: t a
-> t a
-> a
-> (t a -> Vector a)
-> (t (t a) -> Vector (Vector a))
-> (Vector a -> t a)
-> Vector (Vector Int)
-> t (t a)
-> Vector (t a)
uniquenessVariants2GNPB !t a
ts !t a
us !a
hd t a -> Vector a
f1 t (t a) -> Vector (Vector a)
f2 Vector a -> t a
f3 Vector (Vector Int)
perms !t (t a)
subs
  | t (t a) -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
F.null t (t a)
subs = Vector (t a)
forall a. Monoid a => a
mempty
  | Bool
otherwise =
     let !uss :: t (t a)
uss = (a
hd a -> t a -> t a
forall (t :: * -> *) a. InsertLeft t a => a -> t a -> t a
%@ t a
us) t a -> t (t a) -> t (t a)
forall (t :: * -> *) a. InsertLeft t a => t a -> t (t a) -> t (t a)
%^ t (t a)
forall a. Monoid a => a
mempty
         !baseV :: Vector (Vector a)
baseV = (Vector a -> Vector a) -> Vector (Vector a) -> Vector (Vector a)
forall a b. (a -> b) -> Vector a -> Vector b
VB.map (a
hd a -> Vector a -> Vector a
forall (t :: * -> *) a. InsertLeft t a => a -> t a -> t a
%@) (Vector (Vector a) -> Vector (Vector a))
-> (t (t a) -> Vector (Vector a)) -> t (t a) -> Vector (Vector a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t (t a) -> Vector (Vector a)
f2 (t (t a) -> Vector (Vector a)) -> t (t a) -> Vector (Vector a)
forall a b. (a -> b) -> a -> b
$ t (t a)
subs
         !ns :: Vector (Vector a)
ns = t a
-> t (t a)
-> (t a -> Vector a)
-> (t (t a) -> Vector (Vector a))
-> Vector (Vector Int)
-> Vector (Vector a)
-> Vector (Vector a)
forall a (t :: * -> *).
(Eq a, Foldable t, InsertLeft t a, Monoid (t a),
 Monoid (t (t a))) =>
t a
-> t (t a)
-> (t a -> Vector a)
-> (t (t a) -> Vector (Vector a))
-> Vector (Vector Int)
-> Vector (Vector a)
-> Vector (Vector a)
universalSetG t a
ts t (t a)
uss t a -> Vector a
f1 t (t a) -> Vector (Vector a)
f2 Vector (Vector Int)
perms Vector (Vector a)
baseV in (Vector a -> t a) -> Vector (Vector a) -> Vector (t a)
forall a b. (a -> b) -> Vector a -> Vector b
VB.map Vector a -> t a
f3 Vector (Vector a)
ns

uniquenessVariants2GNBL ::
  (Eq a, Foldable t, InsertLeft t a, Monoid (t a), Monoid (t (t a))) => a -- ^ The first most common element in the \"whitespace symbols\" structure
  -> (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 @[[a]]@ so that the function can process further
  -> ([a] -> t a) -- ^ The function that is used internally to convert to the needed representation so that the function can process further
  -> [VB.Vector Int] -- ^ The permutations of 'Int' indices starting from 0 and up to n (n is probably less than 8).
  -> t (t a) -- ^ Must be obtained as 'subG' @whspss xs@
  -> [t a]
uniquenessVariants2GNBL :: a
-> (t a -> [a])
-> (t (t a) -> [[a]])
-> ([a] -> t a)
-> [Vector Int]
-> t (t a)
-> [t a]
uniquenessVariants2GNBL !a
hd t a -> [a]
f1 t (t a) -> [[a]]
f2 [a] -> t a
f3 [Vector Int]
perms !t (t a)
subs = t a
-> t a
-> a
-> (t a -> [a])
-> (t (t a) -> [[a]])
-> ([a] -> t a)
-> [Vector Int]
-> t (t a)
-> [t a]
forall a (t :: * -> *).
(Eq a, Foldable t, InsertLeft t a, Monoid (t a),
 Monoid (t (t a))) =>
t a
-> t a
-> a
-> (t a -> [a])
-> (t (t a) -> [[a]])
-> ([a] -> t a)
-> [Vector Int]
-> t (t a)
-> [t a]
uniquenessVariants2GNPBL t a
forall a. Monoid a => a
mempty t a
forall a. Monoid a => a
mempty a
hd t a -> [a]
f1 t (t a) -> [[a]]
f2 [a] -> t a
f3 [Vector Int]
perms t (t a)
subs
{-# INLINE uniquenessVariants2GNBL #-}

uniquenessVariants2GNPBL ::
  (Eq a, Foldable t, InsertLeft t a, Monoid (t a), Monoid (t (t a))) => t a
  -> t a
  ->  a -- ^ The first most common element in the whitespace symbols structure
  -> (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 @[[a]]@ so that the function can process further
  -> ([a] -> t a) -- ^ The function that is used internally to convert to the needed representation that the function can process further
  -> [VB.Vector Int] -- ^ The permutations of 'Int' indices starting from 0 and up to n (n is probably less than 7).
  -> t (t a) -- ^ Must be obtained as @subG whspss xs@
  -> [t a]
uniquenessVariants2GNPBL :: t a
-> t a
-> a
-> (t a -> [a])
-> (t (t a) -> [[a]])
-> ([a] -> t a)
-> [Vector Int]
-> t (t a)
-> [t a]
uniquenessVariants2GNPBL !t a
ts !t a
us !a
hd t a -> [a]
f1 t (t a) -> [[a]]
f2 [a] -> t a
f3 [Vector Int]
perms !t (t a)
subs
  | t (t a) -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
F.null t (t a)
subs = [t a]
forall a. Monoid a => a
mempty
  | Bool
otherwise =
     let !uss :: t (t a)
uss = (a
hd a -> t a -> t a
forall (t :: * -> *) a. InsertLeft t a => a -> t a -> t a
%@ t a
us) t a -> t (t a) -> t (t a)
forall (t :: * -> *) a. InsertLeft t a => t a -> t (t a) -> t (t a)
%^ t (t a)
forall a. Monoid a => a
mempty
         !baseV :: Vector [a]
baseV = [[a]] -> Vector [a]
forall a. [a] -> Vector a
VB.fromList ([[a]] -> Vector [a])
-> (t (t a) -> [[a]]) -> t (t a) -> Vector [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([a] -> [a]) -> [[a]] -> [[a]]
forall a b. (a -> b) -> [a] -> [b]
map (a
hd a -> [a] -> [a]
forall (t :: * -> *) a. InsertLeft t a => a -> t a -> t a
%@) ([[a]] -> [[a]]) -> (t (t a) -> [[a]]) -> t (t a) -> [[a]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t (t a) -> [[a]]
f2 (t (t a) -> Vector [a]) -> t (t a) -> Vector [a]
forall a b. (a -> b) -> a -> b
$ t (t a)
subs
         !ns :: [[a]]
ns = t a
-> t (t a)
-> (t a -> [a])
-> (t (t a) -> [[a]])
-> [Vector Int]
-> Vector [a]
-> [[a]]
forall a (t :: * -> *).
(Eq a, Foldable t, InsertLeft t a, Monoid (t a),
 Monoid (t (t a))) =>
t a
-> t (t a)
-> (t a -> [a])
-> (t (t a) -> [[a]])
-> [Vector Int]
-> Vector [a]
-> [[a]]
universalSetGL t a
ts t (t a)
uss t a -> [a]
f1 t (t a) -> [[a]]
f2 [Vector Int]
perms Vector [a]
baseV in ([a] -> t a) -> [[a]] -> [t a]
forall a b. (a -> b) -> [a] -> [b]
map [a] -> t a
f3 [[a]]
ns