-- |
-- 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 (
  uniquenessVariants2GNB
  , uniquenessVariants2GNPB
) 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 list of 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 list of 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. Vector a
VB.empty
  | 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 a. a -> Vector a -> Vector a
`VB.cons`) (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