{-# LANGUAGE TypeFamilies, DeriveDataTypeable, DeriveGeneric, TypeOperators #-}
{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, FlexibleContexts #-}
{-# LANGUAGE Trustworthy, UndecidableInstances #-}

{- |
    Module      :  SDP.Templates.AnyBorder
    Copyright   :  (c) Andrey Mulik 2020
    License     :  BSD-style
    Maintainer  :  work.a.mulik@gmail.com
    Portability :  non-portable (GHC extensions)
    
    "SDP.Plate.AnyBorder" provides 'AnyBorder' - template of generalized by
    index type structure, based on 'Int'-indexed primitive.
-}
module SDP.Templates.AnyBorder
(
  -- * Export
  module SDP.IndexedM,
  module SDP.Shaped,
  module SDP.Sort,
  module SDP.Scan,
  
  -- * Border template
  AnyBorder (..)
)
where

import Prelude ()
import SDP.SafePrelude
import SDP.IndexedM
import SDP.Shaped
import SDP.SortM
import SDP.Sort
import SDP.Scan

import Data.Default.Class
import Data.Typeable
import Data.String
import Data.Data

import Text.Read.SDP
import Text.Show.SDP

import GHC.Generics
import qualified GHC.Exts as E

import Control.Exception.SDP

default ()

--------------------------------------------------------------------------------

{- |
  'AnyBorder' is template, that appends arbitrary bounds to any structure.
  
  * 'Eq', 'Ord', 'Eq1' and 'Ord1' instances ingores bounds.
  * 'Thaw' and 'Freeze' instances for @'AnyBorder' rep e@ inherit @rep e@
  behavior.
-}
data AnyBorder rep i e = AnyBorder !i !i !(rep e)
  deriving ( Typeable, Typeable (AnyBorder rep i e)
DataType
Constr
Typeable (AnyBorder rep i e)
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g)
    -> AnyBorder rep i e
    -> c (AnyBorder rep i e))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (AnyBorder rep i e))
-> (AnyBorder rep i e -> Constr)
-> (AnyBorder rep i e -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (AnyBorder rep i e)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (AnyBorder rep i e)))
-> ((forall b. Data b => b -> b)
    -> AnyBorder rep i e -> AnyBorder rep i e)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> AnyBorder rep i e -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> AnyBorder rep i e -> r)
-> (forall u.
    (forall d. Data d => d -> u) -> AnyBorder rep i e -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> AnyBorder rep i e -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> AnyBorder rep i e -> m (AnyBorder rep i e))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> AnyBorder rep i e -> m (AnyBorder rep i e))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> AnyBorder rep i e -> m (AnyBorder rep i e))
-> Data (AnyBorder rep i e)
AnyBorder rep i e -> DataType
AnyBorder rep i e -> Constr
(forall b. Data b => b -> b)
-> AnyBorder rep i e -> AnyBorder rep i e
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> AnyBorder rep i e
-> c (AnyBorder rep i e)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (AnyBorder rep i e)
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int -> (forall d. Data d => d -> u) -> AnyBorder rep i e -> u
forall u. (forall d. Data d => d -> u) -> AnyBorder rep i e -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> AnyBorder rep i e -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> AnyBorder rep i e -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> AnyBorder rep i e -> m (AnyBorder rep i e)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> AnyBorder rep i e -> m (AnyBorder rep i e)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (AnyBorder rep i e)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> AnyBorder rep i e
-> c (AnyBorder rep i e)
forall (rep :: * -> *) i e.
(Typeable rep, Typeable e, Data i, Data (rep e)) =>
Typeable (AnyBorder rep i e)
forall (rep :: * -> *) i e.
(Typeable rep, Typeable e, Data i, Data (rep e)) =>
AnyBorder rep i e -> DataType
forall (rep :: * -> *) i e.
(Typeable rep, Typeable e, Data i, Data (rep e)) =>
AnyBorder rep i e -> Constr
forall (rep :: * -> *) i e.
(Typeable rep, Typeable e, Data i, Data (rep e)) =>
(forall b. Data b => b -> b)
-> AnyBorder rep i e -> AnyBorder rep i e
forall (rep :: * -> *) i e u.
(Typeable rep, Typeable e, Data i, Data (rep e)) =>
Int -> (forall d. Data d => d -> u) -> AnyBorder rep i e -> u
forall (rep :: * -> *) i e u.
(Typeable rep, Typeable e, Data i, Data (rep e)) =>
(forall d. Data d => d -> u) -> AnyBorder rep i e -> [u]
forall (rep :: * -> *) i e r r'.
(Typeable rep, Typeable e, Data i, Data (rep e)) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> AnyBorder rep i e -> r
forall (rep :: * -> *) i e r r'.
(Typeable rep, Typeable e, Data i, Data (rep e)) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> AnyBorder rep i e -> r
forall (rep :: * -> *) i e (m :: * -> *).
(Typeable rep, Typeable e, Data i, Data (rep e), Monad m) =>
(forall d. Data d => d -> m d)
-> AnyBorder rep i e -> m (AnyBorder rep i e)
forall (rep :: * -> *) i e (m :: * -> *).
(Typeable rep, Typeable e, Data i, Data (rep e), MonadPlus m) =>
(forall d. Data d => d -> m d)
-> AnyBorder rep i e -> m (AnyBorder rep i e)
forall (rep :: * -> *) i e (c :: * -> *).
(Typeable rep, Typeable e, Data i, Data (rep e)) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (AnyBorder rep i e)
forall (rep :: * -> *) i e (c :: * -> *).
(Typeable rep, Typeable e, Data i, Data (rep e)) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> AnyBorder rep i e
-> c (AnyBorder rep i e)
forall (rep :: * -> *) i e (t :: * -> *) (c :: * -> *).
(Typeable rep, Typeable e, Data i, Data (rep e), Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (AnyBorder rep i e))
forall (rep :: * -> *) i e (t :: * -> * -> *) (c :: * -> *).
(Typeable rep, Typeable e, Data i, Data (rep e), Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (AnyBorder rep i e))
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (AnyBorder rep i e))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (AnyBorder rep i e))
$cAnyBorder :: Constr
$tAnyBorder :: DataType
gmapMo :: (forall d. Data d => d -> m d)
-> AnyBorder rep i e -> m (AnyBorder rep i e)
$cgmapMo :: forall (rep :: * -> *) i e (m :: * -> *).
(Typeable rep, Typeable e, Data i, Data (rep e), MonadPlus m) =>
(forall d. Data d => d -> m d)
-> AnyBorder rep i e -> m (AnyBorder rep i e)
gmapMp :: (forall d. Data d => d -> m d)
-> AnyBorder rep i e -> m (AnyBorder rep i e)
$cgmapMp :: forall (rep :: * -> *) i e (m :: * -> *).
(Typeable rep, Typeable e, Data i, Data (rep e), MonadPlus m) =>
(forall d. Data d => d -> m d)
-> AnyBorder rep i e -> m (AnyBorder rep i e)
gmapM :: (forall d. Data d => d -> m d)
-> AnyBorder rep i e -> m (AnyBorder rep i e)
$cgmapM :: forall (rep :: * -> *) i e (m :: * -> *).
(Typeable rep, Typeable e, Data i, Data (rep e), Monad m) =>
(forall d. Data d => d -> m d)
-> AnyBorder rep i e -> m (AnyBorder rep i e)
gmapQi :: Int -> (forall d. Data d => d -> u) -> AnyBorder rep i e -> u
$cgmapQi :: forall (rep :: * -> *) i e u.
(Typeable rep, Typeable e, Data i, Data (rep e)) =>
Int -> (forall d. Data d => d -> u) -> AnyBorder rep i e -> u
gmapQ :: (forall d. Data d => d -> u) -> AnyBorder rep i e -> [u]
$cgmapQ :: forall (rep :: * -> *) i e u.
(Typeable rep, Typeable e, Data i, Data (rep e)) =>
(forall d. Data d => d -> u) -> AnyBorder rep i e -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> AnyBorder rep i e -> r
$cgmapQr :: forall (rep :: * -> *) i e r r'.
(Typeable rep, Typeable e, Data i, Data (rep e)) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> AnyBorder rep i e -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> AnyBorder rep i e -> r
$cgmapQl :: forall (rep :: * -> *) i e r r'.
(Typeable rep, Typeable e, Data i, Data (rep e)) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> AnyBorder rep i e -> r
gmapT :: (forall b. Data b => b -> b)
-> AnyBorder rep i e -> AnyBorder rep i e
$cgmapT :: forall (rep :: * -> *) i e.
(Typeable rep, Typeable e, Data i, Data (rep e)) =>
(forall b. Data b => b -> b)
-> AnyBorder rep i e -> AnyBorder rep i e
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (AnyBorder rep i e))
$cdataCast2 :: forall (rep :: * -> *) i e (t :: * -> * -> *) (c :: * -> *).
(Typeable rep, Typeable e, Data i, Data (rep e), Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (AnyBorder rep i e))
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (AnyBorder rep i e))
$cdataCast1 :: forall (rep :: * -> *) i e (t :: * -> *) (c :: * -> *).
(Typeable rep, Typeable e, Data i, Data (rep e), Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (AnyBorder rep i e))
dataTypeOf :: AnyBorder rep i e -> DataType
$cdataTypeOf :: forall (rep :: * -> *) i e.
(Typeable rep, Typeable e, Data i, Data (rep e)) =>
AnyBorder rep i e -> DataType
toConstr :: AnyBorder rep i e -> Constr
$ctoConstr :: forall (rep :: * -> *) i e.
(Typeable rep, Typeable e, Data i, Data (rep e)) =>
AnyBorder rep i e -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (AnyBorder rep i e)
$cgunfold :: forall (rep :: * -> *) i e (c :: * -> *).
(Typeable rep, Typeable e, Data i, Data (rep e)) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (AnyBorder rep i e)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> AnyBorder rep i e
-> c (AnyBorder rep i e)
$cgfoldl :: forall (rep :: * -> *) i e (c :: * -> *).
(Typeable rep, Typeable e, Data i, Data (rep e)) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> AnyBorder rep i e
-> c (AnyBorder rep i e)
$cp1Data :: forall (rep :: * -> *) i e.
(Typeable rep, Typeable e, Data i, Data (rep e)) =>
Typeable (AnyBorder rep i e)
Data, (forall x. AnyBorder rep i e -> Rep (AnyBorder rep i e) x)
-> (forall x. Rep (AnyBorder rep i e) x -> AnyBorder rep i e)
-> Generic (AnyBorder rep i e)
forall x. Rep (AnyBorder rep i e) x -> AnyBorder rep i e
forall x. AnyBorder rep i e -> Rep (AnyBorder rep i e) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (rep :: * -> *) i e x.
Rep (AnyBorder rep i e) x -> AnyBorder rep i e
forall (rep :: * -> *) i e x.
AnyBorder rep i e -> Rep (AnyBorder rep i e) x
$cto :: forall (rep :: * -> *) i e x.
Rep (AnyBorder rep i e) x -> AnyBorder rep i e
$cfrom :: forall (rep :: * -> *) i e x.
AnyBorder rep i e -> Rep (AnyBorder rep i e) x
Generic )

--------------------------------------------------------------------------------

{- Eq ad Eq1 instances. -}

instance (Index i, Eq (rep e)) => Eq (AnyBorder rep i e)
  where
    == :: AnyBorder rep i e -> AnyBorder rep i e -> Bool
(==) = (rep e -> rep e -> Bool)
-> (AnyBorder rep i e -> rep e)
-> AnyBorder rep i e
-> AnyBorder rep i e
-> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on rep e -> rep e -> Bool
forall a. Eq a => a -> a -> Bool
(==) AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack

instance (Index i, Eq1 rep) => Eq1 (AnyBorder rep i)
  where
    liftEq :: (a -> b -> Bool) -> AnyBorder rep i a -> AnyBorder rep i b -> Bool
liftEq a -> b -> Bool
f AnyBorder rep i a
xs AnyBorder rep i b
ys = (a -> b -> Bool) -> rep a -> rep b -> Bool
forall (f :: * -> *) a b.
Eq1 f =>
(a -> b -> Bool) -> f a -> f b -> Bool
liftEq a -> b -> Bool
f (AnyBorder rep i a -> rep a
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i a
xs) (AnyBorder rep i b -> rep b
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i b
ys)

--------------------------------------------------------------------------------

{- Ord and Ord1 instances. -}

instance (Index i, Ord (rep e)) => Ord (AnyBorder rep i e)
  where
    compare :: AnyBorder rep i e -> AnyBorder rep i e -> Ordering
compare = (rep e -> rep e -> Ordering)
-> (AnyBorder rep i e -> rep e)
-> AnyBorder rep i e
-> AnyBorder rep i e
-> Ordering
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on rep e -> rep e -> Ordering
forall o. Ord o => Compare o
(<=>) AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack

instance (Index i, Ord1 rep) => Ord1 (AnyBorder rep i)
  where
    liftCompare :: (a -> b -> Ordering)
-> AnyBorder rep i a -> AnyBorder rep i b -> Ordering
liftCompare a -> b -> Ordering
f AnyBorder rep i a
xs AnyBorder rep i b
ys = (a -> b -> Ordering) -> rep a -> rep b -> Ordering
forall (f :: * -> *) a b.
Ord1 f =>
(a -> b -> Ordering) -> f a -> f b -> Ordering
liftCompare a -> b -> Ordering
f (AnyBorder rep i a -> rep a
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i a
xs) (AnyBorder rep i b -> rep b
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i b
ys)

--------------------------------------------------------------------------------

{- Show and Read instances. -}

instance {-# OVERLAPPABLE #-} (Indexed1 rep Int e, Index i, Show i, Show e) => Show (AnyBorder rep i e)
  where
    showsPrec :: Int -> AnyBorder rep i e -> ShowS
showsPrec = String -> Int -> AnyBorder rep i e -> ShowS
forall v i e.
(Indexed v i e, Show i, Show e) =>
String -> Int -> v -> ShowS
assocsPrec String
"array "

instance (Indexed1 rep Int Char, Index i, Show i) => Show (AnyBorder rep i Char)
  where
    showsPrec :: Int -> AnyBorder rep i Char -> ShowS
showsPrec = String -> ShowS
forall a. Show a => a -> ShowS
shows (String -> ShowS)
-> (Int -> AnyBorder rep i Char -> String)
-> Int
-> AnyBorder rep i Char
-> ShowS
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
... (AnyBorder rep i Char -> String)
-> Int -> AnyBorder rep i Char -> String
forall a b. a -> b -> a
const AnyBorder rep i Char -> String
forall l e. Linear l e => l -> [e]
listL

instance (Index i, Read i, Read e, Indexed1 rep Int e) => Read (AnyBorder rep i e)
  where
    readPrec :: ReadPrec (AnyBorder rep i e)
readPrec = String -> ReadPrec (AnyBorder rep i e)
forall v i e.
(Indexed v i e, Read i, Read e) =>
String -> ReadPrec v
indexedPrec' String
"array"
    readList :: ReadS [AnyBorder rep i e]
readList = ReadS [AnyBorder rep i e]
forall a. Read a => ReadS [a]
readListDefault

--------------------------------------------------------------------------------

{- Overloaded Lists and String support. -}

instance (Index i, IsString (rep Char), Bordered1 rep Int Char) => IsString (AnyBorder rep i Char)
  where
    fromString :: String -> AnyBorder rep i Char
fromString = rep Char -> AnyBorder rep i Char
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (rep Char -> AnyBorder rep i Char)
-> (String -> rep Char) -> String -> AnyBorder rep i Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> rep Char
forall a. IsString a => String -> a
fromString

instance (Index i, E.IsList (rep e), Bordered1 rep Int e) => E.IsList (AnyBorder rep i e)
  where
    type Item (AnyBorder rep i e) = E.Item (rep e)
    
    fromListN :: Int -> [Item (AnyBorder rep i e)] -> AnyBorder rep i e
fromListN = rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (rep e -> AnyBorder rep i e)
-> (Int -> [Item (rep e)] -> rep e)
-> Int
-> [Item (rep e)]
-> AnyBorder rep i e
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
... Int -> [Item (rep e)] -> rep e
forall l. IsList l => Int -> [Item l] -> l
E.fromListN
    fromList :: [Item (AnyBorder rep i e)] -> AnyBorder rep i e
fromList  = rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (rep e -> AnyBorder rep i e)
-> ([Item (rep e)] -> rep e) -> [Item (rep e)] -> AnyBorder rep i e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Item (rep e)] -> rep e
forall l. IsList l => [Item l] -> l
E.fromList
    toList :: AnyBorder rep i e -> [Item (AnyBorder rep i e)]
toList    = rep e -> [Item (rep e)]
forall l. IsList l => l -> [Item l]
E.toList (rep e -> [Item (rep e)])
-> (AnyBorder rep i e -> rep e)
-> AnyBorder rep i e
-> [Item (rep e)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack

--------------------------------------------------------------------------------

{- Semigroup, Monoid, Nullable, Default and Estimate instances. -}

instance (Index i, Bordered (rep e) Int, Nullable (rep e)) => Nullable (AnyBorder rep i e)
  where
    isNull :: AnyBorder rep i e -> Bool
isNull = \ (AnyBorder i
l i
u rep e
rep) -> (i, i) -> Bool
forall i. Index i => (i, i) -> Bool
isEmpty (i
l, i
u) Bool -> Bool -> Bool
|| rep e -> Bool
forall e. Nullable e => e -> Bool
isNull rep e
rep
    lzero :: AnyBorder rep i e
lzero  = rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds rep e
forall e. Nullable e => e
lzero

instance (Linear1 (AnyBorder rep i) e) => Semigroup (AnyBorder rep i e) where <> :: AnyBorder rep i e -> AnyBorder rep i e -> AnyBorder rep i e
(<>) = AnyBorder rep i e -> AnyBorder rep i e -> AnyBorder rep i e
forall l e. Linear l e => l -> l -> l
(++)
instance (Linear1 (AnyBorder rep i) e) => Monoid    (AnyBorder rep i e) where mempty :: AnyBorder rep i e
mempty = AnyBorder rep i e
forall e. Nullable e => e
Z
instance (Linear1 (AnyBorder rep i) e) => Default   (AnyBorder rep i e) where def :: AnyBorder rep i e
def = AnyBorder rep i e
forall e. Nullable e => e
Z

instance (Index i) => Estimate (AnyBorder rep i e)
  where
    <==> :: Compare (AnyBorder rep i e)
(<==>) = (Int -> Int -> Ordering)
-> (AnyBorder rep i e -> Int) -> Compare (AnyBorder rep i e)
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on Int -> Int -> Ordering
forall o. Ord o => Compare o
(<=>) AnyBorder rep i e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
    .<=. :: AnyBorder rep i e -> AnyBorder rep i e -> Bool
(.<=.) = (Int -> Int -> Bool)
-> (AnyBorder rep i e -> Int)
-> AnyBorder rep i e
-> AnyBorder rep i e
-> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(<=)  AnyBorder rep i e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
    .>=. :: AnyBorder rep i e -> AnyBorder rep i e -> Bool
(.>=.) = (Int -> Int -> Bool)
-> (AnyBorder rep i e -> Int)
-> AnyBorder rep i e
-> AnyBorder rep i e
-> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(>=)  AnyBorder rep i e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
    .>. :: AnyBorder rep i e -> AnyBorder rep i e -> Bool
(.>.)  = (Int -> Int -> Bool)
-> (AnyBorder rep i e -> Int)
-> AnyBorder rep i e
-> AnyBorder rep i e
-> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(>)   AnyBorder rep i e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
    .<. :: AnyBorder rep i e -> AnyBorder rep i e -> Bool
(.<.)  = (Int -> Int -> Bool)
-> (AnyBorder rep i e -> Int)
-> AnyBorder rep i e
-> AnyBorder rep i e
-> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(<)   AnyBorder rep i e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
    
    <.=> :: AnyBorder rep i e -> Int -> Ordering
(<.=>) = Int -> Int -> Ordering
forall o. Ord o => Compare o
(<=>) (Int -> Int -> Ordering)
-> (AnyBorder rep i e -> Int)
-> AnyBorder rep i e
-> Int
-> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
    .>= :: AnyBorder rep i e -> Int -> Bool
(.>=)  = Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(>=)  (Int -> Int -> Bool)
-> (AnyBorder rep i e -> Int) -> AnyBorder rep i e -> Int -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
    .<= :: AnyBorder rep i e -> Int -> Bool
(.<=)  = Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(<=)  (Int -> Int -> Bool)
-> (AnyBorder rep i e -> Int) -> AnyBorder rep i e -> Int -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
    .> :: AnyBorder rep i e -> Int -> Bool
(.>)   = Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(>)   (Int -> Int -> Bool)
-> (AnyBorder rep i e -> Int) -> AnyBorder rep i e -> Int -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> Int
forall b i. Bordered b i => b -> Int
sizeOf
    .< :: AnyBorder rep i e -> Int -> Bool
(.<)   = Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(<)   (Int -> Int -> Bool)
-> (AnyBorder rep i e -> Int) -> AnyBorder rep i e -> Int -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> Int
forall b i. Bordered b i => b -> Int
sizeOf

--------------------------------------------------------------------------------

{- Functor, Zip and Applicative instances. -}

instance (Index i, Functor rep) => Functor (AnyBorder rep i)
  where
    fmap :: (a -> b) -> AnyBorder rep i a -> AnyBorder rep i b
fmap a -> b
f (AnyBorder i
l i
u rep a
rep) = i -> i -> rep b -> AnyBorder rep i b
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder i
l i
u (a -> b
f (a -> b) -> rep a -> rep b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> rep a
rep)

instance (Index i, Zip rep) => Zip (AnyBorder rep i)
  where
    all2 :: (a -> b -> Bool) -> AnyBorder rep i a -> AnyBorder rep i b -> Bool
all2 a -> b -> Bool
f AnyBorder rep i a
as AnyBorder rep i b
bs             = (a -> b -> Bool) -> rep a -> rep b -> Bool
forall (z :: * -> *) a b.
Zip z =>
(a -> b -> Bool) -> z a -> z b -> Bool
all2 a -> b -> Bool
f (AnyBorder rep i a -> rep a
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i a
as) (AnyBorder rep i b -> rep b
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i b
bs)
    all3 :: (a -> b -> c -> Bool)
-> AnyBorder rep i a
-> AnyBorder rep i b
-> AnyBorder rep i c
-> Bool
all3 a -> b -> c -> Bool
f AnyBorder rep i a
as AnyBorder rep i b
bs AnyBorder rep i c
cs          = (a -> b -> c -> Bool) -> rep a -> rep b -> rep c -> Bool
forall (z :: * -> *) a b c.
Zip z =>
(a -> b -> c -> Bool) -> z a -> z b -> z c -> Bool
all3 a -> b -> c -> Bool
f (AnyBorder rep i a -> rep a
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i a
as) (AnyBorder rep i b -> rep b
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i b
bs) (AnyBorder rep i c -> rep c
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i c
cs)
    all4 :: (a -> b -> c -> d -> Bool)
-> AnyBorder rep i a
-> AnyBorder rep i b
-> AnyBorder rep i c
-> AnyBorder rep i d
-> Bool
all4 a -> b -> c -> d -> Bool
f AnyBorder rep i a
as AnyBorder rep i b
bs AnyBorder rep i c
cs AnyBorder rep i d
ds       = (a -> b -> c -> d -> Bool)
-> rep a -> rep b -> rep c -> rep d -> Bool
forall (z :: * -> *) a b c d.
Zip z =>
(a -> b -> c -> d -> Bool) -> z a -> z b -> z c -> z d -> Bool
all4 a -> b -> c -> d -> Bool
f (AnyBorder rep i a -> rep a
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i a
as) (AnyBorder rep i b -> rep b
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i b
bs) (AnyBorder rep i c -> rep c
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i c
cs) (AnyBorder rep i d -> rep d
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i d
ds)
    all5 :: (a -> b -> c -> d -> e -> Bool)
-> AnyBorder rep i a
-> AnyBorder rep i b
-> AnyBorder rep i c
-> AnyBorder rep i d
-> AnyBorder rep i e
-> Bool
all5 a -> b -> c -> d -> e -> Bool
f AnyBorder rep i a
as AnyBorder rep i b
bs AnyBorder rep i c
cs AnyBorder rep i d
ds AnyBorder rep i e
es    = (a -> b -> c -> d -> e -> Bool)
-> rep a -> rep b -> rep c -> rep d -> rep e -> Bool
forall (z :: * -> *) a b c d e.
Zip z =>
(a -> b -> c -> d -> e -> Bool)
-> z a -> z b -> z c -> z d -> z e -> Bool
all5 a -> b -> c -> d -> e -> Bool
f (AnyBorder rep i a -> rep a
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i a
as) (AnyBorder rep i b -> rep b
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i b
bs) (AnyBorder rep i c -> rep c
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i c
cs) (AnyBorder rep i d -> rep d
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i d
ds) (AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i e
es)
    all6 :: (a -> b -> c -> d -> e -> f -> Bool)
-> AnyBorder rep i a
-> AnyBorder rep i b
-> AnyBorder rep i c
-> AnyBorder rep i d
-> AnyBorder rep i e
-> AnyBorder rep i f
-> Bool
all6 a -> b -> c -> d -> e -> f -> Bool
f AnyBorder rep i a
as AnyBorder rep i b
bs AnyBorder rep i c
cs AnyBorder rep i d
ds AnyBorder rep i e
es AnyBorder rep i f
fs = (a -> b -> c -> d -> e -> f -> Bool)
-> rep a -> rep b -> rep c -> rep d -> rep e -> rep f -> Bool
forall (z :: * -> *) a b c d e f.
Zip z =>
(a -> b -> c -> d -> e -> f -> Bool)
-> z a -> z b -> z c -> z d -> z e -> z f -> Bool
all6 a -> b -> c -> d -> e -> f -> Bool
f (AnyBorder rep i a -> rep a
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i a
as) (AnyBorder rep i b -> rep b
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i b
bs) (AnyBorder rep i c -> rep c
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i c
cs) (AnyBorder rep i d -> rep d
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i d
ds) (AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i e
es) (AnyBorder rep i f -> rep f
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i f
fs)
    
    any2 :: (a -> b -> Bool) -> AnyBorder rep i a -> AnyBorder rep i b -> Bool
any2 a -> b -> Bool
f AnyBorder rep i a
as AnyBorder rep i b
bs             = (a -> b -> Bool) -> rep a -> rep b -> Bool
forall (z :: * -> *) a b.
Zip z =>
(a -> b -> Bool) -> z a -> z b -> Bool
any2 a -> b -> Bool
f (AnyBorder rep i a -> rep a
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i a
as) (AnyBorder rep i b -> rep b
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i b
bs)
    any3 :: (a -> b -> c -> Bool)
-> AnyBorder rep i a
-> AnyBorder rep i b
-> AnyBorder rep i c
-> Bool
any3 a -> b -> c -> Bool
f AnyBorder rep i a
as AnyBorder rep i b
bs AnyBorder rep i c
cs          = (a -> b -> c -> Bool) -> rep a -> rep b -> rep c -> Bool
forall (z :: * -> *) a b c.
Zip z =>
(a -> b -> c -> Bool) -> z a -> z b -> z c -> Bool
any3 a -> b -> c -> Bool
f (AnyBorder rep i a -> rep a
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i a
as) (AnyBorder rep i b -> rep b
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i b
bs) (AnyBorder rep i c -> rep c
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i c
cs)
    any4 :: (a -> b -> c -> d -> Bool)
-> AnyBorder rep i a
-> AnyBorder rep i b
-> AnyBorder rep i c
-> AnyBorder rep i d
-> Bool
any4 a -> b -> c -> d -> Bool
f AnyBorder rep i a
as AnyBorder rep i b
bs AnyBorder rep i c
cs AnyBorder rep i d
ds       = (a -> b -> c -> d -> Bool)
-> rep a -> rep b -> rep c -> rep d -> Bool
forall (z :: * -> *) a b c d.
Zip z =>
(a -> b -> c -> d -> Bool) -> z a -> z b -> z c -> z d -> Bool
any4 a -> b -> c -> d -> Bool
f (AnyBorder rep i a -> rep a
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i a
as) (AnyBorder rep i b -> rep b
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i b
bs) (AnyBorder rep i c -> rep c
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i c
cs) (AnyBorder rep i d -> rep d
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i d
ds)
    any5 :: (a -> b -> c -> d -> e -> Bool)
-> AnyBorder rep i a
-> AnyBorder rep i b
-> AnyBorder rep i c
-> AnyBorder rep i d
-> AnyBorder rep i e
-> Bool
any5 a -> b -> c -> d -> e -> Bool
f AnyBorder rep i a
as AnyBorder rep i b
bs AnyBorder rep i c
cs AnyBorder rep i d
ds AnyBorder rep i e
es    = (a -> b -> c -> d -> e -> Bool)
-> rep a -> rep b -> rep c -> rep d -> rep e -> Bool
forall (z :: * -> *) a b c d e.
Zip z =>
(a -> b -> c -> d -> e -> Bool)
-> z a -> z b -> z c -> z d -> z e -> Bool
any5 a -> b -> c -> d -> e -> Bool
f (AnyBorder rep i a -> rep a
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i a
as) (AnyBorder rep i b -> rep b
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i b
bs) (AnyBorder rep i c -> rep c
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i c
cs) (AnyBorder rep i d -> rep d
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i d
ds) (AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i e
es)
    any6 :: (a -> b -> c -> d -> e -> f -> Bool)
-> AnyBorder rep i a
-> AnyBorder rep i b
-> AnyBorder rep i c
-> AnyBorder rep i d
-> AnyBorder rep i e
-> AnyBorder rep i f
-> Bool
any6 a -> b -> c -> d -> e -> f -> Bool
f AnyBorder rep i a
as AnyBorder rep i b
bs AnyBorder rep i c
cs AnyBorder rep i d
ds AnyBorder rep i e
es AnyBorder rep i f
fs = (a -> b -> c -> d -> e -> f -> Bool)
-> rep a -> rep b -> rep c -> rep d -> rep e -> rep f -> Bool
forall (z :: * -> *) a b c d e f.
Zip z =>
(a -> b -> c -> d -> e -> f -> Bool)
-> z a -> z b -> z c -> z d -> z e -> z f -> Bool
any6 a -> b -> c -> d -> e -> f -> Bool
f (AnyBorder rep i a -> rep a
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i a
as) (AnyBorder rep i b -> rep b
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i b
bs) (AnyBorder rep i c -> rep c
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i c
cs) (AnyBorder rep i d -> rep d
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i d
ds) (AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i e
es) (AnyBorder rep i f -> rep f
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i f
fs)
    
    zipWith :: (a -> b -> c)
-> AnyBorder rep i a -> AnyBorder rep i b -> AnyBorder rep i c
zipWith a -> b -> c
f AnyBorder rep i a
as AnyBorder rep i b
bs =
      let (i
l, i
u) = Int -> (i, i)
forall i. Index i => Int -> (i, i)
defaultBounds (Int -> (i, i)) -> Int -> (i, i)
forall a b. (a -> b) -> a -> b
$ [Int] -> Int
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum [AnyBorder rep i a -> Int
forall b i. Bordered b i => b -> Int
sizeOf AnyBorder rep i a
as, AnyBorder rep i b -> Int
forall b i. Bordered b i => b -> Int
sizeOf AnyBorder rep i b
bs]
      in  i -> i -> rep c -> AnyBorder rep i c
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder i
l i
u (rep c -> AnyBorder rep i c) -> rep c -> AnyBorder rep i c
forall a b. (a -> b) -> a -> b
$ (a -> b -> c) -> rep a -> rep b -> rep c
forall (z :: * -> *) a b c.
Zip z =>
(a -> b -> c) -> z a -> z b -> z c
zipWith a -> b -> c
f (AnyBorder rep i a -> rep a
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i a
as) (AnyBorder rep i b -> rep b
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i b
bs)
    
    zipWith3 :: (a -> b -> c -> d)
-> AnyBorder rep i a
-> AnyBorder rep i b
-> AnyBorder rep i c
-> AnyBorder rep i d
zipWith3 a -> b -> c -> d
f AnyBorder rep i a
as AnyBorder rep i b
bs AnyBorder rep i c
cs =
      let (i
l, i
u) = Int -> (i, i)
forall i. Index i => Int -> (i, i)
defaultBounds (Int -> (i, i)) -> Int -> (i, i)
forall a b. (a -> b) -> a -> b
$ [Int] -> Int
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum [AnyBorder rep i a -> Int
forall b i. Bordered b i => b -> Int
sizeOf AnyBorder rep i a
as, AnyBorder rep i b -> Int
forall b i. Bordered b i => b -> Int
sizeOf AnyBorder rep i b
bs, AnyBorder rep i c -> Int
forall b i. Bordered b i => b -> Int
sizeOf AnyBorder rep i c
cs]
      in  i -> i -> rep d -> AnyBorder rep i d
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder i
l i
u (rep d -> AnyBorder rep i d) -> rep d -> AnyBorder rep i d
forall a b. (a -> b) -> a -> b
$ (a -> b -> c -> d) -> rep a -> rep b -> rep c -> rep d
forall (z :: * -> *) a b c d.
Zip z =>
(a -> b -> c -> d) -> z a -> z b -> z c -> z d
zipWith3 a -> b -> c -> d
f (AnyBorder rep i a -> rep a
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i a
as) (AnyBorder rep i b -> rep b
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i b
bs) (AnyBorder rep i c -> rep c
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i c
cs)
    
    zipWith4 :: (a -> b -> c -> d -> e)
-> AnyBorder rep i a
-> AnyBorder rep i b
-> AnyBorder rep i c
-> AnyBorder rep i d
-> AnyBorder rep i e
zipWith4 a -> b -> c -> d -> e
f AnyBorder rep i a
as AnyBorder rep i b
bs AnyBorder rep i c
cs AnyBorder rep i d
ds =
      let (i
l, i
u) = Int -> (i, i)
forall i. Index i => Int -> (i, i)
defaultBounds (Int -> (i, i)) -> Int -> (i, i)
forall a b. (a -> b) -> a -> b
$ [Int] -> Int
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum [AnyBorder rep i a -> Int
forall b i. Bordered b i => b -> Int
sizeOf AnyBorder rep i a
as, AnyBorder rep i b -> Int
forall b i. Bordered b i => b -> Int
sizeOf AnyBorder rep i b
bs, AnyBorder rep i c -> Int
forall b i. Bordered b i => b -> Int
sizeOf AnyBorder rep i c
cs, AnyBorder rep i d -> Int
forall b i. Bordered b i => b -> Int
sizeOf AnyBorder rep i d
ds]
      in  i -> i -> rep e -> AnyBorder rep i e
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder i
l i
u (rep e -> AnyBorder rep i e) -> rep e -> AnyBorder rep i e
forall a b. (a -> b) -> a -> b
$ (a -> b -> c -> d -> e)
-> rep a -> rep b -> rep c -> rep d -> rep e
forall (z :: * -> *) a b c d e.
Zip z =>
(a -> b -> c -> d -> e) -> z a -> z b -> z c -> z d -> z e
zipWith4 a -> b -> c -> d -> e
f (AnyBorder rep i a -> rep a
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i a
as) (AnyBorder rep i b -> rep b
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i b
bs) (AnyBorder rep i c -> rep c
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i c
cs) (AnyBorder rep i d -> rep d
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i d
ds)
    
    zipWith5 :: (a -> b -> c -> d -> e -> f)
-> AnyBorder rep i a
-> AnyBorder rep i b
-> AnyBorder rep i c
-> AnyBorder rep i d
-> AnyBorder rep i e
-> AnyBorder rep i f
zipWith5 a -> b -> c -> d -> e -> f
f AnyBorder rep i a
as AnyBorder rep i b
bs AnyBorder rep i c
cs AnyBorder rep i d
ds AnyBorder rep i e
es =
      let (i
l, i
u) = Int -> (i, i)
forall i. Index i => Int -> (i, i)
defaultBounds (Int -> (i, i)) -> Int -> (i, i)
forall a b. (a -> b) -> a -> b
$ [Int] -> Int
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum [AnyBorder rep i a -> Int
forall b i. Bordered b i => b -> Int
sizeOf AnyBorder rep i a
as, AnyBorder rep i b -> Int
forall b i. Bordered b i => b -> Int
sizeOf AnyBorder rep i b
bs, AnyBorder rep i c -> Int
forall b i. Bordered b i => b -> Int
sizeOf AnyBorder rep i c
cs, AnyBorder rep i d -> Int
forall b i. Bordered b i => b -> Int
sizeOf AnyBorder rep i d
ds, AnyBorder rep i e -> Int
forall b i. Bordered b i => b -> Int
sizeOf AnyBorder rep i e
es]
      in  i -> i -> rep f -> AnyBorder rep i f
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder i
l i
u (rep f -> AnyBorder rep i f) -> rep f -> AnyBorder rep i f
forall a b. (a -> b) -> a -> b
$ (a -> b -> c -> d -> e -> f)
-> rep a -> rep b -> rep c -> rep d -> rep e -> rep f
forall (z :: * -> *) a b c d e f.
Zip z =>
(a -> b -> c -> d -> e -> f)
-> z a -> z b -> z c -> z d -> z e -> z f
zipWith5 a -> b -> c -> d -> e -> f
f (AnyBorder rep i a -> rep a
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i a
as) (AnyBorder rep i b -> rep b
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i b
bs) (AnyBorder rep i c -> rep c
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i c
cs) (AnyBorder rep i d -> rep d
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i d
ds) (AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i e
es)
    
    zipWith6 :: (a -> b -> c -> d -> e -> f -> g)
-> AnyBorder rep i a
-> AnyBorder rep i b
-> AnyBorder rep i c
-> AnyBorder rep i d
-> AnyBorder rep i e
-> AnyBorder rep i f
-> AnyBorder rep i g
zipWith6 a -> b -> c -> d -> e -> f -> g
f AnyBorder rep i a
as AnyBorder rep i b
bs AnyBorder rep i c
cs AnyBorder rep i d
ds AnyBorder rep i e
es AnyBorder rep i f
fs =
      let (i
l, i
u) = Int -> (i, i)
forall i. Index i => Int -> (i, i)
defaultBounds (Int -> (i, i)) -> Int -> (i, i)
forall a b. (a -> b) -> a -> b
$ [Int] -> Int
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum [AnyBorder rep i a -> Int
forall b i. Bordered b i => b -> Int
sizeOf AnyBorder rep i a
as, AnyBorder rep i b -> Int
forall b i. Bordered b i => b -> Int
sizeOf AnyBorder rep i b
bs, AnyBorder rep i c -> Int
forall b i. Bordered b i => b -> Int
sizeOf AnyBorder rep i c
cs, AnyBorder rep i d -> Int
forall b i. Bordered b i => b -> Int
sizeOf AnyBorder rep i d
ds, AnyBorder rep i e -> Int
forall b i. Bordered b i => b -> Int
sizeOf AnyBorder rep i e
es, AnyBorder rep i f -> Int
forall b i. Bordered b i => b -> Int
sizeOf AnyBorder rep i f
fs]
      in  i -> i -> rep g -> AnyBorder rep i g
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder i
l i
u (rep g -> AnyBorder rep i g) -> rep g -> AnyBorder rep i g
forall a b. (a -> b) -> a -> b
$ (a -> b -> c -> d -> e -> f -> g)
-> rep a -> rep b -> rep c -> rep d -> rep e -> rep f -> rep g
forall (z :: * -> *) a b c d e f g.
Zip z =>
(a -> b -> c -> d -> e -> f -> g)
-> z a -> z b -> z c -> z d -> z e -> z f -> z g
zipWith6 a -> b -> c -> d -> e -> f -> g
f (AnyBorder rep i a -> rep a
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i a
as) (AnyBorder rep i b -> rep b
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i b
bs) (AnyBorder rep i c -> rep c
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i c
cs) (AnyBorder rep i d -> rep d
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i d
ds) (AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i e
es) (AnyBorder rep i f -> rep f
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i f
fs)

instance (Index i, Applicative rep) => Applicative (AnyBorder rep i)
  where
    pure :: a -> AnyBorder rep i a
pure = (i -> i -> rep a -> AnyBorder rep i a)
-> (i, i) -> rep a -> AnyBorder rep i a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry i -> i -> rep a -> AnyBorder rep i a
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder (Int -> (i, i)
forall i. Index i => Int -> (i, i)
defaultBounds Int
1) (rep a -> AnyBorder rep i a)
-> (a -> rep a) -> a -> AnyBorder rep i a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> rep a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
    
    (AnyBorder i
lf i
uf rep (a -> b)
fs) <*> :: AnyBorder rep i (a -> b) -> AnyBorder rep i a -> AnyBorder rep i b
<*> (AnyBorder i
le i
ue rep a
es) =
      let (i
l, i
u) = Int -> (i, i)
forall i. Index i => Int -> (i, i)
defaultBounds ((i, i) -> Int
forall i. Index i => (i, i) -> Int
size (i
lf, i
uf) Int -> Int -> Int
forall a. Num a => a -> a -> a
* (i, i) -> Int
forall i. Index i => (i, i) -> Int
size (i
le, i
ue))
      in  i -> i -> rep b -> AnyBorder rep i b
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder i
l i
u (rep (a -> b)
fs rep (a -> b) -> rep a -> rep b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> rep a
es)

--------------------------------------------------------------------------------

{- Foldable and Traversable instances. -}

instance (Index i, Foldable rep) => Foldable (AnyBorder rep i)
  where
    foldr :: (a -> b -> b) -> b -> AnyBorder rep i a -> b
foldr  a -> b -> b
f b
base = (a -> b -> b) -> b -> rep a -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr  a -> b -> b
f b
base (rep a -> b)
-> (AnyBorder rep i a -> rep a) -> AnyBorder rep i a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i a -> rep a
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    foldl :: (b -> a -> b) -> b -> AnyBorder rep i a -> b
foldl  b -> a -> b
f b
base = (b -> a -> b) -> b -> rep a -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl  b -> a -> b
f b
base (rep a -> b)
-> (AnyBorder rep i a -> rep a) -> AnyBorder rep i a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i a -> rep a
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    foldr' :: (a -> b -> b) -> b -> AnyBorder rep i a -> b
foldr' a -> b -> b
f b
base = (a -> b -> b) -> b -> rep a -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr' a -> b -> b
f b
base (rep a -> b)
-> (AnyBorder rep i a -> rep a) -> AnyBorder rep i a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i a -> rep a
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    foldl' :: (b -> a -> b) -> b -> AnyBorder rep i a -> b
foldl' b -> a -> b
f b
base = (b -> a -> b) -> b -> rep a -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' b -> a -> b
f b
base (rep a -> b)
-> (AnyBorder rep i a -> rep a) -> AnyBorder rep i a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i a -> rep a
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    
    foldr1 :: (a -> a -> a) -> AnyBorder rep i a -> a
foldr1 a -> a -> a
f = (a -> a -> a) -> rep a -> a
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldr1 a -> a -> a
f (rep a -> a)
-> (AnyBorder rep i a -> rep a) -> AnyBorder rep i a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i a -> rep a
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    foldl1 :: (a -> a -> a) -> AnyBorder rep i a -> a
foldl1 a -> a -> a
f = (a -> a -> a) -> rep a -> a
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldl1 a -> a -> a
f (rep a -> a)
-> (AnyBorder rep i a -> rep a) -> AnyBorder rep i a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i a -> rep a
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    
    length :: AnyBorder rep i a -> Int
length = rep a -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (rep a -> Int)
-> (AnyBorder rep i a -> rep a) -> AnyBorder rep i a -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i a -> rep a
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    toList :: AnyBorder rep i a -> [a]
toList = rep a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (rep a -> [a])
-> (AnyBorder rep i a -> rep a) -> AnyBorder rep i a -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i a -> rep a
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    null :: AnyBorder rep i a -> Bool
null   = rep a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null   (rep a -> Bool)
-> (AnyBorder rep i a -> rep a) -> AnyBorder rep i a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i a -> rep a
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack

instance (Index i, Traversable rep) => Traversable (AnyBorder rep i)
  where
    traverse :: (a -> f b) -> AnyBorder rep i a -> f (AnyBorder rep i b)
traverse a -> f b
f (AnyBorder i
l i
u rep a
es) = i -> i -> rep b -> AnyBorder rep i b
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder i
l i
u (rep b -> AnyBorder rep i b) -> f (rep b) -> f (AnyBorder rep i b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a -> f b) -> rep a -> f (rep b)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse a -> f b
f rep a
es

--------------------------------------------------------------------------------

{- Bordered, Linear and Split instances. -}

instance (Index i) => Bordered (AnyBorder rep i e) i
  where
    lower :: AnyBorder rep i e -> i
lower    (AnyBorder i
l i
_ rep e
_) = i
l
    upper :: AnyBorder rep i e -> i
upper    (AnyBorder i
_ i
u rep e
_) = i
u
    bounds :: AnyBorder rep i e -> (i, i)
bounds   (AnyBorder i
l i
u rep e
_) = (i
l, i
u)
    sizeOf :: AnyBorder rep i e -> Int
sizeOf   (AnyBorder i
l i
u rep e
_) = (i, i) -> Int
forall i. Index i => (i, i) -> Int
size    (i
l, i
u)
    indices :: AnyBorder rep i e -> [i]
indices  (AnyBorder i
l i
u rep e
_) = (i, i) -> [i]
forall i. Index i => (i, i) -> [i]
range   (i
l, i
u)
    indexOf :: AnyBorder rep i e -> Int -> i
indexOf  (AnyBorder i
l i
u rep e
_) = (i, i) -> Int -> i
forall i. Index i => (i, i) -> Int -> i
index   (i
l, i
u)
    indexIn :: AnyBorder rep i e -> i -> Bool
indexIn  (AnyBorder i
l i
u rep e
_) = (i, i) -> i -> Bool
forall i. Index i => (i, i) -> i -> Bool
inRange (i
l, i
u)
    offsetOf :: AnyBorder rep i e -> i -> Int
offsetOf (AnyBorder i
l i
u rep e
_) = (i, i) -> i -> Int
forall i. Index i => (i, i) -> i -> Int
offset  (i
l, i
u)

instance (Index i, Linear1 rep e, Bordered1 rep Int e) => Linear (AnyBorder rep i e) e
  where
    single :: e -> AnyBorder rep i e
single = rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (rep e -> AnyBorder rep i e)
-> (e -> rep e) -> e -> AnyBorder rep i e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> rep e
forall l e. Linear l e => e -> l
single
    
    toHead :: e -> AnyBorder rep i e -> AnyBorder rep i e
toHead e
e AnyBorder rep i e
es = rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (e
e e -> rep e -> rep e
forall l e. Linear l e => e -> l -> l
:> AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i e
es)
    toLast :: AnyBorder rep i e -> e -> AnyBorder rep i e
toLast AnyBorder rep i e
es e
e = rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i e
es rep e -> e -> rep e
forall l e. Linear l e => l -> e -> l
:< e
e)
    
    head :: AnyBorder rep i e -> e
head = rep e -> e
forall l e. Linear l e => l -> e
head (rep e -> e)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    last :: AnyBorder rep i e -> e
last = rep e -> e
forall l e. Linear l e => l -> e
last (rep e -> e)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    tail :: AnyBorder rep i e -> AnyBorder rep i e
tail = rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (rep e -> AnyBorder rep i e)
-> (AnyBorder rep i e -> rep e)
-> AnyBorder rep i e
-> AnyBorder rep i e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. rep e -> rep e
forall l e. Linear l e => l -> l
tail (rep e -> rep e)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> rep e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    init :: AnyBorder rep i e -> AnyBorder rep i e
init = rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (rep e -> AnyBorder rep i e)
-> (AnyBorder rep i e -> rep e)
-> AnyBorder rep i e
-> AnyBorder rep i e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. rep e -> rep e
forall l e. Linear l e => l -> l
init (rep e -> rep e)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> rep e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    
    fromList :: [e] -> AnyBorder rep i e
fromList  = [e] -> AnyBorder rep i e
forall l e (f :: * -> *). (Linear l e, Foldable f) => f e -> l
fromFoldable
    fromListN :: Int -> [e] -> AnyBorder rep i e
fromListN = rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (rep e -> AnyBorder rep i e)
-> (Int -> [e] -> rep e) -> Int -> [e] -> AnyBorder rep i e
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
... Int -> [e] -> rep e
forall l e. Linear l e => Int -> [e] -> l
fromListN
    replicate :: Int -> e -> AnyBorder rep i e
replicate = rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (rep e -> AnyBorder rep i e)
-> (Int -> e -> rep e) -> Int -> e -> AnyBorder rep i e
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
... Int -> e -> rep e
forall l e. Linear l e => Int -> e -> l
replicate
    iterate :: Int -> (e -> e) -> e -> AnyBorder rep i e
iterate Int
n = rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (rep e -> AnyBorder rep i e)
-> ((e -> e) -> e -> rep e) -> (e -> e) -> e -> AnyBorder rep i e
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
... Int -> (e -> e) -> e -> rep e
forall l e. Linear l e => Int -> (e -> e) -> e -> l
iterate Int
n
    
    fromFoldable :: f e -> AnyBorder rep i e
fromFoldable = rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (rep e -> AnyBorder rep i e)
-> (f e -> rep e) -> f e -> AnyBorder rep i e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f e -> rep e
forall l e (f :: * -> *). (Linear l e, Foldable f) => f e -> l
fromFoldable
    
    listL :: AnyBorder rep i e -> [e]
listL = rep e -> [e]
forall l e. Linear l e => l -> [e]
listL (rep e -> [e])
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> [e]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    listR :: AnyBorder rep i e -> [e]
listR = rep e -> [e]
forall l e. Linear l e => l -> [e]
listR (rep e -> [e])
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> [e]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    
    {-# INLINE (!^) #-}
    !^ :: AnyBorder rep i e -> Int -> e
(!^) = rep e -> Int -> e
forall l e. Linear l e => l -> Int -> e
(!^) (rep e -> Int -> e)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> Int -> e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    ++ :: AnyBorder rep i e -> AnyBorder rep i e -> AnyBorder rep i e
(++) = rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (rep e -> AnyBorder rep i e)
-> (AnyBorder rep i e -> AnyBorder rep i e -> rep e)
-> AnyBorder rep i e
-> AnyBorder rep i e
-> AnyBorder rep i e
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
... (rep e -> rep e -> rep e)
-> (AnyBorder rep i e -> rep e)
-> AnyBorder rep i e
-> AnyBorder rep i e
-> rep e
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on rep e -> rep e -> rep e
forall l e. Linear l e => l -> l -> l
(++) AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    
    write :: AnyBorder rep i e -> Int -> e -> AnyBorder rep i e
write (AnyBorder i
l i
u rep e
es) Int
n e
e = i -> i -> rep e -> AnyBorder rep i e
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder i
l i
u (rep e -> Int -> e -> rep e
forall l e. Linear l e => l -> Int -> e -> l
write rep e
es Int
n e
e)
    
    concatMap :: (a -> AnyBorder rep i e) -> f a -> AnyBorder rep i e
concatMap = rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (rep e -> AnyBorder rep i e)
-> ((a -> AnyBorder rep i e) -> f a -> rep e)
-> (a -> AnyBorder rep i e)
-> f a
-> AnyBorder rep i e
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
... (a -> rep e) -> f a -> rep e
forall l e (f :: * -> *) a.
(Linear l e, Foldable f) =>
(a -> l) -> f a -> l
concatMap ((a -> rep e) -> f a -> rep e)
-> ((a -> AnyBorder rep i e) -> a -> rep e)
-> (a -> AnyBorder rep i e)
-> f a
-> rep e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack (AnyBorder rep i e -> rep e)
-> (a -> AnyBorder rep i e) -> a -> rep e
forall b c a. (b -> c) -> (a -> b) -> a -> c
.)
    concat :: f (AnyBorder rep i e) -> AnyBorder rep i e
concat    = rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds  (rep e -> AnyBorder rep i e)
-> (f (AnyBorder rep i e) -> rep e)
-> f (AnyBorder rep i e)
-> AnyBorder rep i e
forall b c a. (b -> c) -> (a -> b) -> a -> c
.  (AnyBorder rep i e -> rep e) -> f (AnyBorder rep i e) -> rep e
forall l e (f :: * -> *) a.
(Linear l e, Foldable f) =>
(a -> l) -> f a -> l
concatMap AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    
    partitions :: f (e -> Bool) -> AnyBorder rep i e -> [AnyBorder rep i e]
partitions  f (e -> Bool)
f = ([e] -> AnyBorder rep i e) -> [[e]] -> [AnyBorder rep i e]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [e] -> AnyBorder rep i e
forall l e. Linear l e => [e] -> l
fromList ([[e]] -> [AnyBorder rep i e])
-> (AnyBorder rep i e -> [[e]])
-> AnyBorder rep i e
-> [AnyBorder rep i e]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f (e -> Bool) -> [e] -> [[e]]
forall l e (f :: * -> *).
(Linear l e, Foldable f) =>
f (e -> Bool) -> l -> [l]
partitions f (e -> Bool)
f ([e] -> [[e]])
-> (AnyBorder rep i e -> [e]) -> AnyBorder rep i e -> [[e]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> [e]
forall l e. Linear l e => l -> [e]
listL
    intersperse :: e -> AnyBorder rep i e -> AnyBorder rep i e
intersperse e
e = rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (rep e -> AnyBorder rep i e)
-> (AnyBorder rep i e -> rep e)
-> AnyBorder rep i e
-> AnyBorder rep i e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> rep e -> rep e
forall l e. Linear l e => e -> l -> l
intersperse e
e (rep e -> rep e)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> rep e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    
    filter :: (e -> Bool) -> AnyBorder rep i e -> AnyBorder rep i e
filter e -> Bool
f = rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (rep e -> AnyBorder rep i e)
-> (AnyBorder rep i e -> rep e)
-> AnyBorder rep i e
-> AnyBorder rep i e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (e -> Bool) -> rep e -> rep e
forall l e. Linear l e => (e -> Bool) -> l -> l
filter e -> Bool
f (rep e -> rep e)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> rep e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    
    reverse :: AnyBorder rep i e -> AnyBorder rep i e
reverse (AnyBorder i
l i
u rep e
rep) = i -> i -> rep e -> AnyBorder rep i e
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder i
l i
u (rep e -> rep e
forall l e. Linear l e => l -> l
reverse rep e
rep)
    force :: AnyBorder rep i e -> AnyBorder rep i e
force   (AnyBorder i
l i
u rep e
rep) = i -> i -> rep e -> AnyBorder rep i e
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder i
l i
u (rep e -> rep e
forall l e. Linear l e => l -> l
force   rep e
rep)
    
    select :: (e -> Maybe a) -> AnyBorder rep i e -> [a]
select   e -> Maybe a
f = (e -> Maybe a) -> rep e -> [a]
forall l e a. Linear l e => (e -> Maybe a) -> l -> [a]
select e -> Maybe a
f (rep e -> [a])
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    extract :: (e -> Maybe a) -> AnyBorder rep i e -> ([a], AnyBorder rep i e)
extract  e -> Maybe a
f = (rep e -> AnyBorder rep i e)
-> ([a], rep e) -> ([a], AnyBorder rep i e)
forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (([a], rep e) -> ([a], AnyBorder rep i e))
-> (AnyBorder rep i e -> ([a], rep e))
-> AnyBorder rep i e
-> ([a], AnyBorder rep i e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (e -> Maybe a) -> rep e -> ([a], rep e)
forall l e a. Linear l e => (e -> Maybe a) -> l -> ([a], l)
extract  e -> Maybe a
f (rep e -> ([a], rep e))
-> (AnyBorder rep i e -> rep e)
-> AnyBorder rep i e
-> ([a], rep e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    selects :: f (e -> Maybe a) -> AnyBorder rep i e -> ([[a]], AnyBorder rep i e)
selects f (e -> Maybe a)
fs = (rep e -> AnyBorder rep i e)
-> ([[a]], rep e) -> ([[a]], AnyBorder rep i e)
forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (([[a]], rep e) -> ([[a]], AnyBorder rep i e))
-> (AnyBorder rep i e -> ([[a]], rep e))
-> AnyBorder rep i e
-> ([[a]], AnyBorder rep i e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f (e -> Maybe a) -> rep e -> ([[a]], rep e)
forall l e (f :: * -> *) a.
(Linear l e, Foldable f) =>
f (e -> Maybe a) -> l -> ([[a]], l)
selects f (e -> Maybe a)
fs (rep e -> ([[a]], rep e))
-> (AnyBorder rep i e -> rep e)
-> AnyBorder rep i e
-> ([[a]], rep e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    
    nubBy :: Equal e -> AnyBorder rep i e -> AnyBorder rep i e
nubBy Equal e
f = rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (rep e -> AnyBorder rep i e)
-> (AnyBorder rep i e -> rep e)
-> AnyBorder rep i e
-> AnyBorder rep i e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Equal e -> rep e -> rep e
forall l e. Linear l e => Equal e -> l -> l
nubBy Equal e
f (rep e -> rep e)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> rep e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    nub :: AnyBorder rep i e -> AnyBorder rep i e
nub     = rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (rep e -> AnyBorder rep i e)
-> (AnyBorder rep i e -> rep e)
-> AnyBorder rep i e
-> AnyBorder rep i e
forall b c a. (b -> c) -> (a -> b) -> a -> c
.   rep e -> rep e
forall l e. (Linear l e, Eq e) => l -> l
nub   (rep e -> rep e)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> rep e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    
    ofoldr :: (Int -> e -> b -> b) -> b -> AnyBorder rep i e -> b
ofoldr Int -> e -> b -> b
f b
base = (Int -> e -> b -> b) -> b -> rep e -> b
forall l e b. Linear l e => (Int -> e -> b -> b) -> b -> l -> b
ofoldr Int -> e -> b -> b
f b
base (rep e -> b)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    ofoldl :: (Int -> b -> e -> b) -> b -> AnyBorder rep i e -> b
ofoldl Int -> b -> e -> b
f b
base = (Int -> b -> e -> b) -> b -> rep e -> b
forall l e b. Linear l e => (Int -> b -> e -> b) -> b -> l -> b
ofoldl Int -> b -> e -> b
f b
base (rep e -> b)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    
    o_foldr :: (e -> b -> b) -> b -> AnyBorder rep i e -> b
o_foldr e -> b -> b
f b
base = (e -> b -> b) -> b -> rep e -> b
forall l e b. Linear l e => (e -> b -> b) -> b -> l -> b
o_foldr e -> b -> b
f b
base (rep e -> b)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    o_foldl :: (b -> e -> b) -> b -> AnyBorder rep i e -> b
o_foldl b -> e -> b
f b
base = (b -> e -> b) -> b -> rep e -> b
forall l e b. Linear l e => (b -> e -> b) -> b -> l -> b
o_foldl b -> e -> b
f b
base (rep e -> b)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack

instance (Index i, Split1 rep e, Bordered1 rep Int e) => Split (AnyBorder rep i e) e
  where
    take :: Int -> AnyBorder rep i e -> AnyBorder rep i e
take Int
n = rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (rep e -> AnyBorder rep i e)
-> (AnyBorder rep i e -> rep e)
-> AnyBorder rep i e
-> AnyBorder rep i e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> rep e -> rep e
forall s e. Split s e => Int -> s -> s
take Int
n (rep e -> rep e)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> rep e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    drop :: Int -> AnyBorder rep i e -> AnyBorder rep i e
drop Int
n = rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (rep e -> AnyBorder rep i e)
-> (AnyBorder rep i e -> rep e)
-> AnyBorder rep i e
-> AnyBorder rep i e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> rep e -> rep e
forall s e. Split s e => Int -> s -> s
drop Int
n (rep e -> rep e)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> rep e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    keep :: Int -> AnyBorder rep i e -> AnyBorder rep i e
keep Int
n = rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (rep e -> AnyBorder rep i e)
-> (AnyBorder rep i e -> rep e)
-> AnyBorder rep i e
-> AnyBorder rep i e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> rep e -> rep e
forall s e. Split s e => Int -> s -> s
keep Int
n (rep e -> rep e)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> rep e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    sans :: Int -> AnyBorder rep i e -> AnyBorder rep i e
sans Int
n = rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (rep e -> AnyBorder rep i e)
-> (AnyBorder rep i e -> rep e)
-> AnyBorder rep i e
-> AnyBorder rep i e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> rep e -> rep e
forall s e. Split s e => Int -> s -> s
sans Int
n (rep e -> rep e)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> rep e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    
    splits :: f Int -> AnyBorder rep i e -> [AnyBorder rep i e]
splits f Int
ns = (rep e -> AnyBorder rep i e) -> [rep e] -> [AnyBorder rep i e]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds ([rep e] -> [AnyBorder rep i e])
-> (AnyBorder rep i e -> [rep e])
-> AnyBorder rep i e
-> [AnyBorder rep i e]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f Int -> rep e -> [rep e]
forall s e (f :: * -> *).
(Split s e, Foldable f) =>
f Int -> s -> [s]
splits f Int
ns (rep e -> [rep e])
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> [rep e]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    chunks :: Int -> AnyBorder rep i e -> [AnyBorder rep i e]
chunks Int
ns = (rep e -> AnyBorder rep i e) -> [rep e] -> [AnyBorder rep i e]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds ([rep e] -> [AnyBorder rep i e])
-> (AnyBorder rep i e -> [rep e])
-> AnyBorder rep i e
-> [AnyBorder rep i e]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> rep e -> [rep e]
forall s e. Split s e => Int -> s -> [s]
chunks Int
ns (rep e -> [rep e])
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> [rep e]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    parts :: f Int -> AnyBorder rep i e -> [AnyBorder rep i e]
parts  f Int
ns = (rep e -> AnyBorder rep i e) -> [rep e] -> [AnyBorder rep i e]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds ([rep e] -> [AnyBorder rep i e])
-> (AnyBorder rep i e -> [rep e])
-> AnyBorder rep i e
-> [AnyBorder rep i e]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f Int -> rep e -> [rep e]
forall s e (f :: * -> *).
(Split s e, Foldable f) =>
f Int -> s -> [s]
parts  f Int
ns (rep e -> [rep e])
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> [rep e]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    
    justifyL :: Int -> e -> AnyBorder rep i e -> AnyBorder rep i e
justifyL Int
n e
e = rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (rep e -> AnyBorder rep i e)
-> (AnyBorder rep i e -> rep e)
-> AnyBorder rep i e
-> AnyBorder rep i e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> e -> rep e -> rep e
forall s e. Split s e => Int -> e -> s -> s
justifyL Int
n e
e (rep e -> rep e)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> rep e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    justifyR :: Int -> e -> AnyBorder rep i e -> AnyBorder rep i e
justifyR Int
n e
e = rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (rep e -> AnyBorder rep i e)
-> (AnyBorder rep i e -> rep e)
-> AnyBorder rep i e
-> AnyBorder rep i e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> e -> rep e -> rep e
forall s e. Split s e => Int -> e -> s -> s
justifyR Int
n e
e (rep e -> rep e)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> rep e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    
    isPrefixOf :: AnyBorder rep i e -> AnyBorder rep i e -> Bool
isPrefixOf AnyBorder rep i e
xs AnyBorder rep i e
ys = AnyBorder rep i e
xs AnyBorder rep i e -> AnyBorder rep i e -> Bool
forall e. Estimate e => e -> e -> Bool
.<=. AnyBorder rep i e
ys Bool -> Bool -> Bool
&& (rep e -> rep e -> Bool)
-> (AnyBorder rep i e -> rep e)
-> AnyBorder rep i e
-> AnyBorder rep i e
-> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on rep e -> rep e -> Bool
forall s e. (Split s e, Eq e) => s -> s -> Bool
isPrefixOf AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i e
xs AnyBorder rep i e
ys
    isSuffixOf :: AnyBorder rep i e -> AnyBorder rep i e -> Bool
isSuffixOf AnyBorder rep i e
xs AnyBorder rep i e
ys = AnyBorder rep i e
xs AnyBorder rep i e -> AnyBorder rep i e -> Bool
forall e. Estimate e => e -> e -> Bool
.<=. AnyBorder rep i e
ys Bool -> Bool -> Bool
&& (rep e -> rep e -> Bool)
-> (AnyBorder rep i e -> rep e)
-> AnyBorder rep i e
-> AnyBorder rep i e
-> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on rep e -> rep e -> Bool
forall s e. (Split s e, Eq e) => s -> s -> Bool
isSuffixOf AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i e
xs AnyBorder rep i e
ys
    
    prefix :: (e -> Bool) -> AnyBorder rep i e -> Int
prefix e -> Bool
p = (e -> Bool) -> rep e -> Int
forall s e. Split s e => (e -> Bool) -> s -> Int
prefix e -> Bool
p (rep e -> Int)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    suffix :: (e -> Bool) -> AnyBorder rep i e -> Int
suffix e -> Bool
p = (e -> Bool) -> rep e -> Int
forall s e. Split s e => (e -> Bool) -> s -> Int
suffix e -> Bool
p (rep e -> Int)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack

--------------------------------------------------------------------------------

{- BorderedM, LinearM and SplitM instances. -}

instance (Index i, BorderedM1 m rep Int e) => BorderedM m (AnyBorder rep i e) i
  where
    nowIndexIn :: AnyBorder rep i e -> i -> m Bool
nowIndexIn (AnyBorder i
l i
u rep e
_) = Bool -> m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> m Bool) -> (i -> Bool) -> i -> m Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (i, i) -> i -> Bool
forall i. Index i => (i, i) -> i -> Bool
inRange (i
l, i
u)
    getIndices :: AnyBorder rep i e -> m [i]
getIndices (AnyBorder i
l i
u rep e
_) = [i] -> m [i]
forall (m :: * -> *) a. Monad m => a -> m a
return ([i] -> m [i]) -> [i] -> m [i]
forall a b. (a -> b) -> a -> b
$ (i, i) -> [i]
forall i. Index i => (i, i) -> [i]
range (i
l, i
u)
    getSizeOf :: AnyBorder rep i e -> m Int
getSizeOf  (AnyBorder i
l i
u rep e
_) = Int -> m Int
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> m Int) -> Int -> m Int
forall a b. (a -> b) -> a -> b
$ (i, i) -> Int
forall i. Index i => (i, i) -> Int
size (i
l, i
u)
    getBounds :: AnyBorder rep i e -> m (i, i)
getBounds  (AnyBorder i
l i
u rep e
_) = (i, i) -> m (i, i)
forall (m :: * -> *) a. Monad m => a -> m a
return (i
l, i
u)
    getLower :: AnyBorder rep i e -> m i
getLower   (AnyBorder i
l i
_ rep e
_) = i -> m i
forall (m :: * -> *) a. Monad m => a -> m a
return i
l
    getUpper :: AnyBorder rep i e -> m i
getUpper   (AnyBorder i
_ i
u rep e
_) = i -> m i
forall (m :: * -> *) a. Monad m => a -> m a
return i
u

instance (Index i, LinearM1 m rep e, BorderedM1 m rep Int e) => LinearM m (AnyBorder rep i e) e
  where
    newNull :: m (AnyBorder rep i e)
newNull = (i -> i -> rep e -> AnyBorder rep i e)
-> (i, i) -> rep e -> AnyBorder rep i e
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry i -> i -> rep e -> AnyBorder rep i e
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder (Int -> (i, i)
forall i. Index i => Int -> (i, i)
defaultBounds Int
0) (rep e -> AnyBorder rep i e) -> m (rep e) -> m (AnyBorder rep i e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (rep e)
forall (m :: * -> *) l e. LinearM m l e => m l
newNull
    
    nowNull :: AnyBorder rep i e -> m Bool
nowNull (AnyBorder i
l i
u rep e
es) = (i, i) -> Bool
forall i. Index i => (i, i) -> Bool
isEmpty (i
l, i
u) Bool -> m Bool -> m Bool -> m Bool
forall a. Bool -> a -> a -> a
? Bool -> m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True (m Bool -> m Bool) -> m Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ rep e -> m Bool
forall (m :: * -> *) l e. LinearM m l e => l -> m Bool
nowNull rep e
es
    
    getHead :: AnyBorder rep i e -> m e
getHead = rep e -> m e
forall (m :: * -> *) l e. LinearM m l e => l -> m e
getHead (rep e -> m e)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> m e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    getLast :: AnyBorder rep i e -> m e
getLast = rep e -> m e
forall (m :: * -> *) l e. LinearM m l e => l -> m e
getLast (rep e -> m e)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> m e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    
    prepend :: e -> AnyBorder rep i e -> m (AnyBorder rep i e)
prepend e
e = rep e -> m (AnyBorder rep i e)
forall i (m :: * -> *) (rep :: * -> *) e.
(Index i, BorderedM1 m rep Int e) =>
rep e -> m (AnyBorder rep i e)
withBounds' (rep e -> m (AnyBorder rep i e))
-> (AnyBorder rep i e -> m (rep e))
-> AnyBorder rep i e
-> m (AnyBorder rep i e)
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< e -> rep e -> m (rep e)
forall (m :: * -> *) l e. LinearM m l e => e -> l -> m l
prepend e
e (rep e -> m (rep e))
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> m (rep e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    append :: AnyBorder rep i e -> e -> m (AnyBorder rep i e)
append AnyBorder rep i e
es = rep e -> m (AnyBorder rep i e)
forall i (m :: * -> *) (rep :: * -> *) e.
(Index i, BorderedM1 m rep Int e) =>
rep e -> m (AnyBorder rep i e)
withBounds' (rep e -> m (AnyBorder rep i e))
-> (e -> m (rep e)) -> e -> m (AnyBorder rep i e)
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< rep e -> e -> m (rep e)
forall (m :: * -> *) l e. LinearM m l e => l -> e -> m l
append (AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i e
es)
    
    newLinear :: [e] -> m (AnyBorder rep i e)
newLinear = rep e -> m (AnyBorder rep i e)
forall i (m :: * -> *) (rep :: * -> *) e.
(Index i, BorderedM1 m rep Int e) =>
rep e -> m (AnyBorder rep i e)
withBounds' (rep e -> m (AnyBorder rep i e))
-> ([e] -> m (rep e)) -> [e] -> m (AnyBorder rep i e)
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< [e] -> m (rep e)
forall (m :: * -> *) l e. LinearM m l e => [e] -> m l
newLinear
    filled :: Int -> e -> m (AnyBorder rep i e)
filled  Int
n = rep e -> m (AnyBorder rep i e)
forall i (m :: * -> *) (rep :: * -> *) e.
(Index i, BorderedM1 m rep Int e) =>
rep e -> m (AnyBorder rep i e)
withBounds' (rep e -> m (AnyBorder rep i e))
-> (e -> m (rep e)) -> e -> m (AnyBorder rep i e)
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Int -> e -> m (rep e)
forall (m :: * -> *) l e. LinearM m l e => Int -> e -> m l
filled Int
n
    
    getLeft :: AnyBorder rep i e -> m [e]
getLeft   = rep e -> m [e]
forall (m :: * -> *) l e. LinearM m l e => l -> m [e]
getLeft  (rep e -> m [e])
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> m [e]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    getRight :: AnyBorder rep i e -> m [e]
getRight  = rep e -> m [e]
forall (m :: * -> *) l e. LinearM m l e => l -> m [e]
getRight (rep e -> m [e])
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> m [e]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    
    {-# INLINE (!#>) #-}
    !#> :: AnyBorder rep i e -> Int -> m e
(!#>) = rep e -> Int -> m e
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> m e
(!#>) (rep e -> Int -> m e)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> Int -> m e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    
    {-# INLINE writeM #-}
    writeM :: AnyBorder rep i e -> Int -> e -> m ()
writeM = rep e -> Int -> e -> m ()
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> e -> m ()
writeM (rep e -> Int -> e -> m ())
-> (AnyBorder rep i e -> rep e)
-> AnyBorder rep i e
-> Int
-> e
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    
    copied :: AnyBorder rep i e -> m (AnyBorder rep i e)
copied   (AnyBorder i
l i
u rep e
es) = i -> i -> rep e -> AnyBorder rep i e
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder i
l i
u (rep e -> AnyBorder rep i e) -> m (rep e) -> m (AnyBorder rep i e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> rep e -> m (rep e)
forall (m :: * -> *) l e. LinearM m l e => l -> m l
copied  rep e
es
    copied' :: AnyBorder rep i e -> Int -> Int -> m (AnyBorder rep i e)
copied'  (AnyBorder i
l i
u rep e
es) = (i -> i -> rep e -> AnyBorder rep i e
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder i
l i
u (rep e -> AnyBorder rep i e) -> m (rep e) -> m (AnyBorder rep i e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>) (m (rep e) -> m (AnyBorder rep i e))
-> (Int -> Int -> m (rep e)) -> Int -> Int -> m (AnyBorder rep i e)
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
... rep e -> Int -> Int -> m (rep e)
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> Int -> m l
copied' rep e
es
    reversed :: AnyBorder rep i e -> m (AnyBorder rep i e)
reversed (AnyBorder i
l i
u rep e
es) = i -> i -> rep e -> AnyBorder rep i e
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder i
l i
u (rep e -> AnyBorder rep i e) -> m (rep e) -> m (AnyBorder rep i e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> rep e -> m (rep e)
forall (m :: * -> *) l e. LinearM m l e => l -> m l
reversed rep e
es
    
    copyTo :: AnyBorder rep i e -> Int -> AnyBorder rep i e -> Int -> Int -> m ()
copyTo AnyBorder rep i e
src Int
os AnyBorder rep i e
trg Int
ot = rep e -> Int -> rep e -> Int -> Int -> m ()
forall (m :: * -> *) l e.
LinearM m l e =>
l -> Int -> l -> Int -> Int -> m ()
copyTo (AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i e
src) Int
os (AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i e
trg) Int
ot
    
    ofoldrM :: (Int -> e -> r -> m r) -> r -> AnyBorder rep i e -> m r
ofoldrM Int -> e -> r -> m r
f r
e = (Int -> e -> r -> m r) -> r -> rep e -> m r
forall (m :: * -> *) l e r.
LinearM m l e =>
(Int -> e -> r -> m r) -> r -> l -> m r
ofoldrM Int -> e -> r -> m r
f r
e (rep e -> m r)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> m r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    ofoldlM :: (Int -> r -> e -> m r) -> r -> AnyBorder rep i e -> m r
ofoldlM Int -> r -> e -> m r
f r
e = (Int -> r -> e -> m r) -> r -> rep e -> m r
forall (m :: * -> *) l e r.
LinearM m l e =>
(Int -> r -> e -> m r) -> r -> l -> m r
ofoldlM Int -> r -> e -> m r
f r
e (rep e -> m r)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> m r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    
    foldrM :: (e -> r -> m r) -> r -> AnyBorder rep i e -> m r
foldrM e -> r -> m r
f r
e = (e -> r -> m r) -> r -> rep e -> m r
forall (m :: * -> *) l e r.
LinearM m l e =>
(e -> r -> m r) -> r -> l -> m r
foldrM e -> r -> m r
f r
e (rep e -> m r)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> m r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    foldlM :: (r -> e -> m r) -> r -> AnyBorder rep i e -> m r
foldlM r -> e -> m r
f r
e = (r -> e -> m r) -> r -> rep e -> m r
forall (m :: * -> *) l e r.
LinearM m l e =>
(r -> e -> m r) -> r -> l -> m r
foldlM r -> e -> m r
f r
e (rep e -> m r)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> m r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack

instance (Index i, BorderedM1 m rep Int e, SplitM1 m rep e) => SplitM m (AnyBorder rep i e) e
  where
    takeM :: Int -> AnyBorder rep i e -> m (AnyBorder rep i e)
takeM Int
n es :: AnyBorder rep i e
es@(AnyBorder i
l i
u rep e
rep)
        | Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 = m (AnyBorder rep i e)
forall (m :: * -> *) l e. LinearM m l e => m l
newNull
        | Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
c = AnyBorder rep i e -> m (AnyBorder rep i e)
forall (m :: * -> *) a. Monad m => a -> m a
return AnyBorder rep i e
es
        |  Bool
True  = i -> i -> rep e -> AnyBorder rep i e
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder i
l ((i, i) -> Int -> i
forall i. Index i => (i, i) -> Int -> i
index (i
l, i
u) Int
n) (rep e -> AnyBorder rep i e) -> m (rep e) -> m (AnyBorder rep i e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> rep e -> m (rep e)
forall (m :: * -> *) s e. SplitM m s e => Int -> s -> m s
takeM Int
n rep e
rep
      where
        c :: Int
c = (i, i) -> Int
forall i. Index i => (i, i) -> Int
size (i
l, i
u)
    
    dropM :: Int -> AnyBorder rep i e -> m (AnyBorder rep i e)
dropM Int
n es :: AnyBorder rep i e
es@(AnyBorder i
l i
u rep e
rep)
        | Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
c = m (AnyBorder rep i e)
forall (m :: * -> *) l e. LinearM m l e => m l
newNull
        | Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 = AnyBorder rep i e -> m (AnyBorder rep i e)
forall (m :: * -> *) a. Monad m => a -> m a
return AnyBorder rep i e
es
        |  Bool
True  = i -> i -> rep e -> AnyBorder rep i e
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder ((i, i) -> Int -> i
forall i. Index i => (i, i) -> Int -> i
index (i
l, i
u) Int
n) i
u (rep e -> AnyBorder rep i e) -> m (rep e) -> m (AnyBorder rep i e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> rep e -> m (rep e)
forall (m :: * -> *) s e. SplitM m s e => Int -> s -> m s
dropM Int
n rep e
rep
      where
        c :: Int
c = (i, i) -> Int
forall i. Index i => (i, i) -> Int
size (i
l, i
u)
    
    keepM :: Int -> AnyBorder rep i e -> m (AnyBorder rep i e)
keepM Int
n es :: AnyBorder rep i e
es@(AnyBorder i
l i
u rep e
rep)
        | Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 = m (AnyBorder rep i e)
forall (m :: * -> *) l e. LinearM m l e => m l
newNull
        | Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
c = AnyBorder rep i e -> m (AnyBorder rep i e)
forall (m :: * -> *) a. Monad m => a -> m a
return AnyBorder rep i e
es
        |  Bool
True  = i -> i -> rep e -> AnyBorder rep i e
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder ((i, i) -> Int -> i
forall i. Index i => (i, i) -> Int -> i
index (i
l, i
u) (Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n)) i
u (rep e -> AnyBorder rep i e) -> m (rep e) -> m (AnyBorder rep i e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> rep e -> m (rep e)
forall (m :: * -> *) s e. SplitM m s e => Int -> s -> m s
keepM Int
n rep e
rep
      where
        c :: Int
c = (i, i) -> Int
forall i. Index i => (i, i) -> Int
size (i
l, i
u)
    
    sansM :: Int -> AnyBorder rep i e -> m (AnyBorder rep i e)
sansM Int
n es :: AnyBorder rep i e
es@(AnyBorder i
l i
u rep e
rep)
        | Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
c = m (AnyBorder rep i e)
forall (m :: * -> *) l e. LinearM m l e => m l
newNull
        | Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 = AnyBorder rep i e -> m (AnyBorder rep i e)
forall (m :: * -> *) a. Monad m => a -> m a
return AnyBorder rep i e
es
        |  Bool
True  = i -> i -> rep e -> AnyBorder rep i e
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder ((i, i) -> Int -> i
forall i. Index i => (i, i) -> Int -> i
index (i
l, i
u) (Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n)) i
u (rep e -> AnyBorder rep i e) -> m (rep e) -> m (AnyBorder rep i e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> rep e -> m (rep e)
forall (m :: * -> *) s e. SplitM m s e => Int -> s -> m s
sansM Int
n rep e
rep
      where
        c :: Int
c = (i, i) -> Int
forall i. Index i => (i, i) -> Int
size (i
l, i
u)
    
    splitM :: Int
-> AnyBorder rep i e -> m (AnyBorder rep i e, AnyBorder rep i e)
splitM Int
n es :: AnyBorder rep i e
es@(AnyBorder i
l i
u rep e
rep)
        | Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 = do AnyBorder rep i e
e' <- m (AnyBorder rep i e)
forall (m :: * -> *) l e. LinearM m l e => m l
newNull; (AnyBorder rep i e, AnyBorder rep i e)
-> m (AnyBorder rep i e, AnyBorder rep i e)
forall (m :: * -> *) a. Monad m => a -> m a
return (AnyBorder rep i e
e', AnyBorder rep i e
es)
        | Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
c = do AnyBorder rep i e
e' <- m (AnyBorder rep i e)
forall (m :: * -> *) l e. LinearM m l e => m l
newNull; (AnyBorder rep i e, AnyBorder rep i e)
-> m (AnyBorder rep i e, AnyBorder rep i e)
forall (m :: * -> *) a. Monad m => a -> m a
return (AnyBorder rep i e
es, AnyBorder rep i e
e')
        |  Bool
True  = (rep e -> AnyBorder rep i e)
-> (rep e -> AnyBorder rep i e)
-> (rep e, rep e)
-> (AnyBorder rep i e, AnyBorder rep i e)
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap (i -> i -> rep e -> AnyBorder rep i e
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder i
l i
i) (i -> i -> rep e -> AnyBorder rep i e
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder i
i i
u) ((rep e, rep e) -> (AnyBorder rep i e, AnyBorder rep i e))
-> m (rep e, rep e) -> m (AnyBorder rep i e, AnyBorder rep i e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> rep e -> m (rep e, rep e)
forall (m :: * -> *) s e. SplitM m s e => Int -> s -> m (s, s)
splitM Int
n rep e
rep
      where
        i :: i
i = (i, i) -> Int -> i
forall i. Index i => (i, i) -> Int -> i
index (i
l, i
u) Int
n
        c :: Int
c = (i, i) -> Int
forall i. Index i => (i, i) -> Int
size  (i
l, i
u)
    
    divideM :: Int
-> AnyBorder rep i e -> m (AnyBorder rep i e, AnyBorder rep i e)
divideM Int
n es :: AnyBorder rep i e
es@(AnyBorder i
l i
u rep e
rep)
        | Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 = do AnyBorder rep i e
e' <- m (AnyBorder rep i e)
forall (m :: * -> *) l e. LinearM m l e => m l
newNull; (AnyBorder rep i e, AnyBorder rep i e)
-> m (AnyBorder rep i e, AnyBorder rep i e)
forall (m :: * -> *) a. Monad m => a -> m a
return (AnyBorder rep i e
es, AnyBorder rep i e
e')
        | Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
c = do AnyBorder rep i e
e' <- m (AnyBorder rep i e)
forall (m :: * -> *) l e. LinearM m l e => m l
newNull; (AnyBorder rep i e, AnyBorder rep i e)
-> m (AnyBorder rep i e, AnyBorder rep i e)
forall (m :: * -> *) a. Monad m => a -> m a
return (AnyBorder rep i e
e', AnyBorder rep i e
es)
        |  Bool
True  = (rep e -> AnyBorder rep i e)
-> (rep e -> AnyBorder rep i e)
-> (rep e, rep e)
-> (AnyBorder rep i e, AnyBorder rep i e)
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap (i -> i -> rep e -> AnyBorder rep i e
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder i
l i
i) (i -> i -> rep e -> AnyBorder rep i e
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder i
i i
u) ((rep e, rep e) -> (AnyBorder rep i e, AnyBorder rep i e))
-> m (rep e, rep e) -> m (AnyBorder rep i e, AnyBorder rep i e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> rep e -> m (rep e, rep e)
forall (m :: * -> *) s e. SplitM m s e => Int -> s -> m (s, s)
divideM Int
n rep e
rep
      where
        i :: i
i = (i, i) -> Int -> i
forall i. Index i => (i, i) -> Int -> i
index (i
l, i
u) (Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n)
        c :: Int
c = (i, i) -> Int
forall i. Index i => (i, i) -> Int
size  (i
l, i
u)
    
    prefixM :: (e -> Bool) -> AnyBorder rep i e -> m Int
prefixM e -> Bool
p = (e -> Bool) -> rep e -> m Int
forall (m :: * -> *) s e. SplitM m s e => (e -> Bool) -> s -> m Int
prefixM e -> Bool
p (rep e -> m Int)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> m Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    suffixM :: (e -> Bool) -> AnyBorder rep i e -> m Int
suffixM e -> Bool
p = (e -> Bool) -> rep e -> m Int
forall (m :: * -> *) s e. SplitM m s e => (e -> Bool) -> s -> m Int
suffixM e -> Bool
p (rep e -> m Int)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> m Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    mprefix :: (e -> m Bool) -> AnyBorder rep i e -> m Int
mprefix e -> m Bool
p = (e -> m Bool) -> rep e -> m Int
forall (m :: * -> *) s e.
SplitM m s e =>
(e -> m Bool) -> s -> m Int
mprefix e -> m Bool
p (rep e -> m Int)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> m Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    msuffix :: (e -> m Bool) -> AnyBorder rep i e -> m Int
msuffix e -> m Bool
p = (e -> m Bool) -> rep e -> m Int
forall (m :: * -> *) s e.
SplitM m s e =>
(e -> m Bool) -> s -> m Int
msuffix e -> m Bool
p (rep e -> m Int)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> m Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack

--------------------------------------------------------------------------------

{- Set, Scan and Sort instances. -}

instance (SetWith1 (AnyBorder rep i) e, Nullable (AnyBorder rep i e), Ord e) => Set (AnyBorder rep i e) e

instance (Index i, SetWith1 rep e, Linear1 rep e, Bordered1 rep Int e) => SetWith (AnyBorder rep i e) e
  where
    isSubsetWith :: Compare e -> AnyBorder rep i e -> AnyBorder rep i e -> Bool
isSubsetWith Compare e
f = Compare e -> rep e -> rep e -> Bool
forall s o. SetWith s o => Compare o -> s -> s -> Bool
isSubsetWith Compare e
f (rep e -> rep e -> Bool)
-> (AnyBorder rep i e -> rep e)
-> AnyBorder rep i e
-> AnyBorder rep i e
-> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    
    setWith :: Compare e -> AnyBorder rep i e -> AnyBorder rep i e
setWith Compare e
f = rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (rep e -> AnyBorder rep i e)
-> (AnyBorder rep i e -> rep e)
-> AnyBorder rep i e
-> AnyBorder rep i e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Compare e -> rep e -> rep e
forall s o. SetWith s o => Compare o -> s -> s
setWith Compare e
f (rep e -> rep e)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> rep e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    
    subsets :: AnyBorder rep i e -> [AnyBorder rep i e]
subsets = (rep e -> AnyBorder rep i e) -> [rep e] -> [AnyBorder rep i e]
forall a b. (a -> b) -> [a] -> [b]
map rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds ([rep e] -> [AnyBorder rep i e])
-> (AnyBorder rep i e -> [rep e])
-> AnyBorder rep i e
-> [AnyBorder rep i e]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. rep e -> [rep e]
forall s o. (SetWith s o, Ord o) => s -> [s]
subsets (rep e -> [rep e])
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> [rep e]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    
    insertWith :: Compare e -> e -> AnyBorder rep i e -> AnyBorder rep i e
insertWith Compare e
f e
e = rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (rep e -> AnyBorder rep i e)
-> (AnyBorder rep i e -> rep e)
-> AnyBorder rep i e
-> AnyBorder rep i e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Compare e -> e -> rep e -> rep e
forall s o. SetWith s o => Compare o -> o -> s -> s
insertWith Compare e
f e
e (rep e -> rep e)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> rep e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    deleteWith :: Compare e -> e -> AnyBorder rep i e -> AnyBorder rep i e
deleteWith Compare e
f e
e = rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (rep e -> AnyBorder rep i e)
-> (AnyBorder rep i e -> rep e)
-> AnyBorder rep i e
-> AnyBorder rep i e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Compare e -> e -> rep e -> rep e
forall s o. SetWith s o => Compare o -> o -> s -> s
deleteWith Compare e
f e
e (rep e -> rep e)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> rep e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    
    intersectionWith :: Compare e
-> AnyBorder rep i e -> AnyBorder rep i e -> AnyBorder rep i e
intersectionWith Compare e
f = rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (rep e -> AnyBorder rep i e)
-> (AnyBorder rep i e -> AnyBorder rep i e -> rep e)
-> AnyBorder rep i e
-> AnyBorder rep i e
-> AnyBorder rep i e
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
... (rep e -> rep e -> rep e)
-> (AnyBorder rep i e -> rep e)
-> AnyBorder rep i e
-> AnyBorder rep i e
-> rep e
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on (Compare e -> rep e -> rep e -> rep e
forall s o. SetWith s o => Compare o -> s -> s -> s
intersectionWith Compare e
f) AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    unionWith :: Compare e
-> AnyBorder rep i e -> AnyBorder rep i e -> AnyBorder rep i e
unionWith        Compare e
f = rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (rep e -> AnyBorder rep i e)
-> (AnyBorder rep i e -> AnyBorder rep i e -> rep e)
-> AnyBorder rep i e
-> AnyBorder rep i e
-> AnyBorder rep i e
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
... (rep e -> rep e -> rep e)
-> (AnyBorder rep i e -> rep e)
-> AnyBorder rep i e
-> AnyBorder rep i e
-> rep e
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on (Compare e -> rep e -> rep e -> rep e
forall s o. SetWith s o => Compare o -> s -> s -> s
unionWith        Compare e
f) AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    differenceWith :: Compare e
-> AnyBorder rep i e -> AnyBorder rep i e -> AnyBorder rep i e
differenceWith   Compare e
f = rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (rep e -> AnyBorder rep i e)
-> (AnyBorder rep i e -> AnyBorder rep i e -> rep e)
-> AnyBorder rep i e
-> AnyBorder rep i e
-> AnyBorder rep i e
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
... (rep e -> rep e -> rep e)
-> (AnyBorder rep i e -> rep e)
-> AnyBorder rep i e
-> AnyBorder rep i e
-> rep e
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on (Compare e -> rep e -> rep e -> rep e
forall s o. SetWith s o => Compare o -> s -> s -> s
differenceWith   Compare e
f) AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    symdiffWith :: Compare e
-> AnyBorder rep i e -> AnyBorder rep i e -> AnyBorder rep i e
symdiffWith      Compare e
f = rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (rep e -> AnyBorder rep i e)
-> (AnyBorder rep i e -> AnyBorder rep i e -> rep e)
-> AnyBorder rep i e
-> AnyBorder rep i e
-> AnyBorder rep i e
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
... (rep e -> rep e -> rep e)
-> (AnyBorder rep i e -> rep e)
-> AnyBorder rep i e
-> AnyBorder rep i e
-> rep e
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on (Compare e -> rep e -> rep e -> rep e
forall s o. SetWith s o => Compare o -> s -> s -> s
symdiffWith      Compare e
f) AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    
    memberWith :: Compare e -> e -> AnyBorder rep i e -> Bool
memberWith   Compare e
f e
e = Compare e -> e -> rep e -> Bool
forall s o. SetWith s o => Compare o -> o -> s -> Bool
memberWith   Compare e
f e
e (rep e -> Bool)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    lookupLTWith :: Compare e -> e -> AnyBorder rep i e -> Maybe e
lookupLTWith Compare e
f e
o = Compare e -> e -> rep e -> Maybe e
forall s o. SetWith s o => Compare o -> o -> s -> Maybe o
lookupLTWith Compare e
f e
o (rep e -> Maybe e)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> Maybe e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    lookupGTWith :: Compare e -> e -> AnyBorder rep i e -> Maybe e
lookupGTWith Compare e
f e
o = Compare e -> e -> rep e -> Maybe e
forall s o. SetWith s o => Compare o -> o -> s -> Maybe o
lookupGTWith Compare e
f e
o (rep e -> Maybe e)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> Maybe e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    lookupLEWith :: Compare e -> e -> AnyBorder rep i e -> Maybe e
lookupLEWith Compare e
f e
o = Compare e -> e -> rep e -> Maybe e
forall s o. SetWith s o => Compare o -> o -> s -> Maybe o
lookupLEWith Compare e
f e
o (rep e -> Maybe e)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> Maybe e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    lookupGEWith :: Compare e -> e -> AnyBorder rep i e -> Maybe e
lookupGEWith Compare e
f e
o = Compare e -> e -> rep e -> Maybe e
forall s o. SetWith s o => Compare o -> o -> s -> Maybe o
lookupGEWith Compare e
f e
o (rep e -> Maybe e)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> Maybe e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack

instance (Linear1 (AnyBorder rep i) e) => Scan (AnyBorder rep i e) e

instance (Index i, Sort (rep e) e) => Sort (AnyBorder rep i e) e
  where
    sortBy :: Compare e -> AnyBorder rep i e -> AnyBorder rep i e
sortBy Compare e
cmp = \ (AnyBorder i
l i
u rep e
rep) -> i -> i -> rep e -> AnyBorder rep i e
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder i
l i
u (Compare e -> rep e -> rep e
forall s e. Sort s e => Compare e -> s -> s
sortBy Compare e
cmp rep e
rep)
    sortedBy :: (e -> e -> Bool) -> AnyBorder rep i e -> Bool
sortedBy e -> e -> Bool
f = (e -> e -> Bool) -> rep e -> Bool
forall s e. Sort s e => (e -> e -> Bool) -> s -> Bool
sortedBy e -> e -> Bool
f (rep e -> Bool)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack

--------------------------------------------------------------------------------

{- Map, Indexed and Shaped instances. -}

instance (Index i, Indexed1 rep Int e) => Map (AnyBorder rep i e) i e
  where
    toMap :: [(i, e)] -> AnyBorder rep i e
toMap [(i, e)]
ascs = [(i, e)] -> Bool
forall e. Nullable e => e -> Bool
isNull [(i, e)]
ascs Bool -> AnyBorder rep i e -> AnyBorder rep i e -> AnyBorder rep i e
forall a. Bool -> a -> a -> a
? AnyBorder rep i e
forall e. Nullable e => e
Z (AnyBorder rep i e -> AnyBorder rep i e)
-> AnyBorder rep i e -> AnyBorder rep i e
forall a b. (a -> b) -> a -> b
$ (i, i) -> [(i, e)] -> AnyBorder rep i e
forall v i e. Indexed v i e => (i, i) -> [(i, e)] -> v
assoc ([(i, e)] -> (i, i)
forall a b. Ord a => [(a, b)] -> (a, a)
ascsBounds [(i, e)]
ascs) [(i, e)]
ascs
    
    toMap' :: e -> [(i, e)] -> AnyBorder rep i e
toMap' e
e [(i, e)]
ascs = [(i, e)] -> Bool
forall e. Nullable e => e -> Bool
isNull [(i, e)]
ascs Bool -> AnyBorder rep i e -> AnyBorder rep i e -> AnyBorder rep i e
forall a. Bool -> a -> a -> a
? AnyBorder rep i e
forall e. Nullable e => e
Z (AnyBorder rep i e -> AnyBorder rep i e)
-> AnyBorder rep i e -> AnyBorder rep i e
forall a b. (a -> b) -> a -> b
$ (i, i) -> e -> [(i, e)] -> AnyBorder rep i e
forall v i e. Indexed v i e => (i, i) -> e -> [(i, e)] -> v
assoc' ([(i, e)] -> (i, i)
forall a b. Ord a => [(a, b)] -> (a, a)
ascsBounds [(i, e)]
ascs) e
e [(i, e)]
ascs
    
    {-# INLINE (.!) #-}
    .! :: AnyBorder rep i e -> i -> e
(.!) (AnyBorder i
l i
u rep e
rep) = (rep e
rep rep e -> Int -> e
forall l e. Linear l e => l -> Int -> e
!^) (Int -> e) -> (i -> Int) -> i -> e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (i, i) -> i -> Int
forall i. Index i => (i, i) -> i -> Int
offset (i
l, i
u)
    
    AnyBorder rep i e
Z // :: AnyBorder rep i e -> [(i, e)] -> AnyBorder rep i e
// [(i, e)]
ascs = [(i, e)] -> AnyBorder rep i e
forall map key e. Map map key e => [(key, e)] -> map
toMap [(i, e)]
ascs
    (AnyBorder i
l i
u rep e
rep) // [(i, e)]
ascs =
      let ies :: [(Int, e)]
ies = [ ((i, i) -> i -> Int
forall i. Index i => (i, i) -> i -> Int
offset (i
l, i
u) i
i, e
e) | (i
i, e
e) <- [(i, e)]
ascs, (i, i) -> i -> Bool
forall i. Index i => (i, i) -> i -> Bool
inRange (i
l, i
u) i
i ]
      in  i -> i -> rep e -> AnyBorder rep i e
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder i
l i
u (rep e
rep rep e -> [(Int, e)] -> rep e
forall map key e. Map map key e => map -> [(key, e)] -> map
// [(Int, e)]
ies)
    
    e -> Bool
p .$ :: (e -> Bool) -> AnyBorder rep i e -> Maybe i
.$ (AnyBorder i
l i
u rep e
rep) = (i, i) -> Int -> i
forall i. Index i => (i, i) -> Int -> i
index (i
l, i
u) (Int -> i) -> Maybe Int -> Maybe i
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> e -> Bool
p (e -> Bool) -> rep e -> Maybe Int
forall map key e. Map map key e => (e -> Bool) -> map -> Maybe key
.$ rep e
rep
    e -> Bool
p *$ :: (e -> Bool) -> AnyBorder rep i e -> [i]
*$ (AnyBorder i
l i
u rep e
rep) = (i, i) -> Int -> i
forall i. Index i => (i, i) -> Int -> i
index (i
l, i
u) (Int -> i) -> [Int] -> [i]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> e -> Bool
p (e -> Bool) -> rep e -> [Int]
forall map key e. Map map key e => (e -> Bool) -> map -> [key]
*$ rep e
rep
    
    kfoldr :: (i -> e -> b -> b) -> b -> AnyBorder rep i e -> b
kfoldr i -> e -> b -> b
f b
base (AnyBorder i
l i
u rep e
es) = (Int -> e -> b -> b) -> b -> rep e -> b
forall map key e b.
Map map key e =>
(key -> e -> b -> b) -> b -> map -> b
kfoldr (i -> e -> b -> b
f (i -> e -> b -> b) -> (Int -> i) -> Int -> e -> b -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (i, i) -> Int -> i
forall i. Index i => (i, i) -> Int -> i
index (i
l, i
u)) b
base rep e
es
    kfoldl :: (i -> b -> e -> b) -> b -> AnyBorder rep i e -> b
kfoldl i -> b -> e -> b
f b
base (AnyBorder i
l i
u rep e
es) = (Int -> b -> e -> b) -> b -> rep e -> b
forall map key e b.
Map map key e =>
(key -> b -> e -> b) -> b -> map -> b
kfoldl (i -> b -> e -> b
f (i -> b -> e -> b) -> (Int -> i) -> Int -> b -> e -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (i, i) -> Int -> i
forall i. Index i => (i, i) -> Int -> i
index (i
l, i
u)) b
base rep e
es

instance (Index i, Indexed1 rep Int e) => Indexed (AnyBorder rep i e) i e
  where
    assoc :: (i, i) -> [(i, e)] -> AnyBorder rep i e
assoc bnds :: (i, i)
bnds@(i
l, i
u) [(i, e)]
ascs = i -> i -> rep e -> AnyBorder rep i e
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder i
l i
u ((Int, Int) -> [(Int, e)] -> rep e
forall v i e. Indexed v i e => (i, i) -> [(i, e)] -> v
assoc (Int, Int)
bnds' [(Int, e)]
ies)
      where
        ies :: [(Int, e)]
ies   = [ ((i, i) -> i -> Int
forall i. Index i => (i, i) -> i -> Int
offset (i, i)
bnds i
i, e
e) | (i
i, e
e) <- [(i, e)]
ascs, (i, i) -> i -> Bool
forall i. Index i => (i, i) -> i -> Bool
inRange (i, i)
bnds i
i ]
        bnds' :: (Int, Int)
bnds' = Int -> (Int, Int)
forall i. Index i => Int -> (i, i)
defaultBounds ((i, i) -> Int
forall i. Index i => (i, i) -> Int
size (i, i)
bnds)
    
    assoc' :: (i, i) -> e -> [(i, e)] -> AnyBorder rep i e
assoc' bnds :: (i, i)
bnds@(i
l, i
u) e
defvalue [(i, e)]
ascs = i -> i -> rep e -> AnyBorder rep i e
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder i
l i
u ((Int, Int) -> e -> [(Int, e)] -> rep e
forall v i e. Indexed v i e => (i, i) -> e -> [(i, e)] -> v
assoc' (Int, Int)
bnds' e
defvalue [(Int, e)]
ies)
      where
        ies :: [(Int, e)]
ies   = [ ((i, i) -> i -> Int
forall i. Index i => (i, i) -> i -> Int
offset (i, i)
bnds i
i, e
e) | (i
i, e
e) <- [(i, e)]
ascs, (i, i) -> i -> Bool
forall i. Index i => (i, i) -> i -> Bool
inRange (i, i)
bnds i
i ]
        bnds' :: (Int, Int)
bnds' = Int -> (Int, Int)
forall i. Index i => Int -> (i, i)
defaultBounds (Int -> (Int, Int)) -> Int -> (Int, Int)
forall a b. (a -> b) -> a -> b
$ (i, i) -> Int
forall i. Index i => (i, i) -> Int
size (i, i)
bnds
    
    fromIndexed :: m -> AnyBorder rep i e
fromIndexed = rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (rep e -> AnyBorder rep i e)
-> (m -> rep e) -> m -> AnyBorder rep i e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m -> rep e
forall v i e m j. (Indexed v i e, Indexed m j e) => m -> v
fromIndexed

instance (Bordered1 rep Int e, Split1 rep e) => Shaped (AnyBorder rep) e
  where
    reshape :: AnyBorder rep i e -> (j, j) -> AnyBorder rep j e
reshape AnyBorder rep i e
es (j, j)
bs = (j, j) -> Int
forall i. Index i => (i, i) -> Int
size (j, j)
bs Int -> AnyBorder rep i e -> Bool
forall e. Estimate e => Int -> e -> Bool
>. AnyBorder rep i e
es Bool -> AnyBorder rep j e -> AnyBorder rep j e -> AnyBorder rep j e
forall a. Bool -> a -> a -> a
? String -> AnyBorder rep j e
forall a. String -> a
expEx String
"reshape" (AnyBorder rep j e -> AnyBorder rep j e)
-> AnyBorder rep j e -> AnyBorder rep j e
forall a b. (a -> b) -> a -> b
$ (j -> j -> rep e -> AnyBorder rep j e)
-> (j, j) -> rep e -> AnyBorder rep j e
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry j -> j -> rep e -> AnyBorder rep j e
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder (j, j)
bs (AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i e
es)
    
    (AnyBorder i
l i
u rep e
rep) !! :: AnyBorder rep i e -> (i :|: j) -> AnyBorder rep j e
!! i :|: j
ij = (j -> j -> rep e -> AnyBorder rep j e)
-> (j, j) -> rep e -> AnyBorder rep j e
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry j -> j -> rep e -> AnyBorder rep j e
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder (j, j)
sub (rep e -> AnyBorder rep j e)
-> (rep e -> rep e) -> rep e -> AnyBorder rep j e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> rep e -> rep e
forall s e. Split s e => Int -> s -> s
take Int
s (rep e -> AnyBorder rep j e) -> rep e -> AnyBorder rep j e
forall a b. (a -> b) -> a -> b
$ Int -> rep e -> rep e
forall s e. Split s e => Int -> s -> s
drop Int
o rep e
rep
      where
        ((i :|: j, i :|: j)
num, (j, j)
sub) = (i, i) -> (i :|: j) -> ((i :|: j, i :|: j), (j, j))
forall i j ij.
(Index i, Sub i j, ij ~ (i :|: j), Index j) =>
(i, i) -> ij -> ((ij, ij), (j, j))
slice (i
l, i
u) i :|: j
ij
        
        o :: Int
o = (i :|: j, i :|: j) -> (i :|: j) -> Int
forall i. Index i => (i, i) -> i -> Int
offset (i :|: j, i :|: j)
num i :|: j
ij Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
s
        s :: Int
s = (j, j) -> Int
forall i. Index i => (i, i) -> Int
size (j, j)
sub
    
    slices :: AnyBorder rep i e -> [AnyBorder rep j e]
slices AnyBorder rep i e
es =
      let bnds :: (j, j)
bnds = (i -> j) -> (i, i) -> (j, j)
forall a b. (a -> b) -> (a, a) -> (b, b)
both i -> j
forall i j. Sub i j => i -> j
takeDim (AnyBorder rep i e -> (i, i)
forall b i. Bordered b i => b -> (i, i)
bounds AnyBorder rep i e
es)
      in  (j -> j -> rep e -> AnyBorder rep j e)
-> (j, j) -> rep e -> AnyBorder rep j e
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry j -> j -> rep e -> AnyBorder rep j e
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder (j, j)
bnds (rep e -> AnyBorder rep j e) -> [rep e] -> [AnyBorder rep j e]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (j, j) -> Int
forall i. Index i => (i, i) -> Int
size (j, j)
bnds Int -> rep e -> [rep e]
forall s e. Split s e => Int -> s -> [s]
`chunks` AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack AnyBorder rep i e
es
    
    unslice :: f (AnyBorder rep j e) -> AnyBorder rep i e
unslice f (AnyBorder rep j e)
ess =
      let bnds :: (i, i)
bnds = Int -> (i, i)
forall i. Index i => Int -> (i, i)
defaultBounds ((AnyBorder rep j e -> Int -> Int)
-> Int -> f (AnyBorder rep j e) -> Int
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr' (Int -> Int -> Int
forall a. Num a => a -> a -> a
(+) (Int -> Int -> Int)
-> (AnyBorder rep j e -> Int) -> AnyBorder rep j e -> Int -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep j e -> Int
forall b i. Bordered b i => b -> Int
sizeOf) Int
0 f (AnyBorder rep j e)
ess)
      in  (i -> i -> rep e -> AnyBorder rep i e)
-> (i, i) -> rep e -> AnyBorder rep i e
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry i -> i -> rep e -> AnyBorder rep i e
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder (i, i)
bnds ((AnyBorder rep j e -> rep e) -> f (AnyBorder rep j e) -> rep e
forall l e (f :: * -> *) a.
(Linear l e, Foldable f) =>
(a -> l) -> f a -> l
concatMap AnyBorder rep j e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack f (AnyBorder rep j e)
ess)

--------------------------------------------------------------------------------

{- MapM, IndexedM and SortM instances. -}

instance (Index i, MapM1 m rep Int e, LinearM1 m rep e, BorderedM1 m rep Int e) => MapM m (AnyBorder rep i e) i e
  where
    newMap :: [(i, e)] -> m (AnyBorder rep i e)
newMap [(i, e)]
ascs =
      let bnds :: (i, i)
bnds@(i
l, i
u) = [(i, e)] -> (i, i)
forall a b. Ord a => [(a, b)] -> (a, a)
ascsBounds [(i, e)]
ascs
      in  i -> i -> rep e -> AnyBorder rep i e
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder i
l i
u (rep e -> AnyBorder rep i e) -> m (rep e) -> m (AnyBorder rep i e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(Int, e)] -> m (rep e)
forall (m :: * -> *) map key e.
MapM m map key e =>
[(key, e)] -> m map
newMap [ ((i, i) -> i -> Int
forall i. Index i => (i, i) -> i -> Int
offset (i, i)
bnds i
i, e
e) | (i
i, e
e) <- [(i, e)]
ascs ]
    
    newMap' :: e -> [(i, e)] -> m (AnyBorder rep i e)
newMap' e
defvalue [(i, e)]
ascs =
      let bnds :: (i, i)
bnds@(i
l, i
u) = [(i, e)] -> (i, i)
forall a b. Ord a => [(a, b)] -> (a, a)
ascsBounds [(i, e)]
ascs
      in  i -> i -> rep e -> AnyBorder rep i e
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder i
l i
u (rep e -> AnyBorder rep i e) -> m (rep e) -> m (AnyBorder rep i e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> e -> [(Int, e)] -> m (rep e)
forall (m :: * -> *) map key e.
MapM m map key e =>
e -> [(key, e)] -> m map
newMap' e
defvalue [ ((i, i) -> i -> Int
forall i. Index i => (i, i) -> i -> Int
offset (i, i)
bnds i
i, e
e) | (i
i, e
e) <- [(i, e)]
ascs ]
    
    {-# INLINE (>!) #-}
    >! :: AnyBorder rep i e -> i -> m e
(>!) (AnyBorder i
l i
u rep e
es) = (rep e
es rep e -> Int -> m e
forall (m :: * -> *) l e. LinearM m l e => l -> Int -> m e
!#>) (Int -> m e) -> (i -> Int) -> i -> m e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (i, i) -> i -> Int
forall i. Index i => (i, i) -> i -> Int
offset (i
l, i
u)
    
    overwrite :: AnyBorder rep i e -> [(i, e)] -> m (AnyBorder rep i e)
overwrite AnyBorder rep i e
es [] = AnyBorder rep i e -> m (AnyBorder rep i e)
forall (m :: * -> *) a. Monad m => a -> m a
return AnyBorder rep i e
es
    overwrite (AnyBorder i
l i
u rep e
es) [(i, e)]
ascs =
      let ies :: [(Int, e)]
ies = [ ((i, i) -> i -> Int
forall i. Index i => (i, i) -> i -> Int
offset (i
l, i
u) i
i, e
e) | (i
i, e
e) <- [(i, e)]
ascs, (i, i) -> i -> Bool
forall i. Index i => (i, i) -> i -> Bool
inRange (i
l, i
u) i
i ]
      in  (i, i) -> Bool
forall i. Index i => (i, i) -> Bool
isEmpty (i
l, i
u) Bool
-> m (AnyBorder rep i e)
-> m (AnyBorder rep i e)
-> m (AnyBorder rep i e)
forall a. Bool -> a -> a -> a
? [(i, e)] -> m (AnyBorder rep i e)
forall (m :: * -> *) map key e.
MapM m map key e =>
[(key, e)] -> m map
newMap [(i, e)]
ascs (m (AnyBorder rep i e) -> m (AnyBorder rep i e))
-> m (AnyBorder rep i e) -> m (AnyBorder rep i e)
forall a b. (a -> b) -> a -> b
$ i -> i -> rep e -> AnyBorder rep i e
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder i
l i
u (rep e -> AnyBorder rep i e) -> m (rep e) -> m (AnyBorder rep i e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> rep e -> [(Int, e)] -> m (rep e)
forall (m :: * -> *) map key e.
MapM m map key e =>
map -> [(key, e)] -> m map
overwrite rep e
es [(Int, e)]
ies
    
    kfoldrM :: (i -> e -> acc -> m acc) -> acc -> AnyBorder rep i e -> m acc
kfoldrM i -> e -> acc -> m acc
f acc
base (AnyBorder i
l i
u rep e
es) = (Int -> e -> acc -> m acc) -> acc -> rep e -> m acc
forall (m :: * -> *) l e r.
LinearM m l e =>
(Int -> e -> r -> m r) -> r -> l -> m r
ofoldrM (i -> e -> acc -> m acc
f (i -> e -> acc -> m acc) -> (Int -> i) -> Int -> e -> acc -> m acc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (i, i) -> Int -> i
forall i. Index i => (i, i) -> Int -> i
index (i
l, i
u)) acc
base rep e
es
    kfoldlM :: (i -> acc -> e -> m acc) -> acc -> AnyBorder rep i e -> m acc
kfoldlM i -> acc -> e -> m acc
f acc
base (AnyBorder i
l i
u rep e
es) = (Int -> acc -> e -> m acc) -> acc -> rep e -> m acc
forall (m :: * -> *) l e r.
LinearM m l e =>
(Int -> r -> e -> m r) -> r -> l -> m r
ofoldlM (i -> acc -> e -> m acc
f (i -> acc -> e -> m acc) -> (Int -> i) -> Int -> acc -> e -> m acc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (i, i) -> Int -> i
forall i. Index i => (i, i) -> Int -> i
index (i
l, i
u)) acc
base rep e
es

instance (Index i, IndexedM1 m rep Int e) => IndexedM m (AnyBorder rep i e) i e
  where
    fromAssocs :: (i, i) -> [(i, e)] -> m (AnyBorder rep i e)
fromAssocs (i
l, i
u) [(i, e)]
ascs = i -> i -> rep e -> AnyBorder rep i e
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder i
l i
u (rep e -> AnyBorder rep i e) -> m (rep e) -> m (AnyBorder rep i e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int, Int) -> [(Int, e)] -> m (rep e)
forall (m :: * -> *) v i e.
IndexedM m v i e =>
(i, i) -> [(i, e)] -> m v
fromAssocs (Int, Int)
bnds [(Int, e)]
ies
      where
        ies :: [(Int, e)]
ies  = [ ((i, i) -> i -> Int
forall i. Index i => (i, i) -> i -> Int
offset (i
l, i
u) i
i, e
e) | (i
i, e
e) <- [(i, e)]
ascs, (i, i) -> i -> Bool
forall i. Index i => (i, i) -> i -> Bool
inRange (i
l, i
u) i
i ]
        bnds :: (Int, Int)
bnds = (Int
0, (i, i) -> Int
forall i. Index i => (i, i) -> Int
size  (i
l, i
u) Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
    
    fromAssocs' :: (i, i) -> e -> [(i, e)] -> m (AnyBorder rep i e)
fromAssocs' (i
l, i
u) e
defvalue [(i, e)]
ascs = i -> i -> rep e -> AnyBorder rep i e
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder i
l i
u (rep e -> AnyBorder rep i e) -> m (rep e) -> m (AnyBorder rep i e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int, Int) -> e -> [(Int, e)] -> m (rep e)
forall (m :: * -> *) v i e.
IndexedM m v i e =>
(i, i) -> e -> [(i, e)] -> m v
fromAssocs' (Int, Int)
bnds e
defvalue [(Int, e)]
ies
      where
        ies :: [(Int, e)]
ies  = [ ((i, i) -> i -> Int
forall i. Index i => (i, i) -> i -> Int
offset (i
l, i
u) i
i, e
e) | (i
i, e
e) <- [(i, e)]
ascs, (i, i) -> i -> Bool
forall i. Index i => (i, i) -> i -> Bool
inRange (i
l, i
u) i
i ]
        bnds :: (Int, Int)
bnds = (Int
0, (i, i) -> Int
forall i. Index i => (i, i) -> Int
size (i
l, i
u) Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
    
    {-# INLINE writeM' #-}
    writeM' :: AnyBorder rep i e -> i -> e -> m ()
writeM' (AnyBorder i
l i
u rep e
es) = rep e -> Int -> e -> m ()
forall (m :: * -> *) v i e. IndexedM m v i e => v -> i -> e -> m ()
writeM' rep e
es (Int -> e -> m ()) -> (i -> Int) -> i -> e -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (i, i) -> i -> Int
forall i. Index i => (i, i) -> i -> Int
offset (i
l, i
u)
    
    fromIndexed' :: v' -> m (AnyBorder rep i e)
fromIndexed' = rep e -> m (AnyBorder rep i e)
forall i (m :: * -> *) (rep :: * -> *) e.
(Index i, BorderedM1 m rep Int e) =>
rep e -> m (AnyBorder rep i e)
withBounds' (rep e -> m (AnyBorder rep i e))
-> (v' -> m (rep e)) -> v' -> m (AnyBorder rep i e)
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< v' -> m (rep e)
forall (m :: * -> *) v i e v' j.
(IndexedM m v i e, Indexed v' j e) =>
v' -> m v
fromIndexed'
    fromIndexedM :: v' -> m (AnyBorder rep i e)
fromIndexedM = rep e -> m (AnyBorder rep i e)
forall i (m :: * -> *) (rep :: * -> *) e.
(Index i, BorderedM1 m rep Int e) =>
rep e -> m (AnyBorder rep i e)
withBounds' (rep e -> m (AnyBorder rep i e))
-> (v' -> m (rep e)) -> v' -> m (AnyBorder rep i e)
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< v' -> m (rep e)
forall (m :: * -> *) v i e v' j.
(IndexedM m v i e, IndexedM m v' j e) =>
v' -> m v
fromIndexedM

instance (Index i, SortM1 m rep e) => SortM m (AnyBorder rep i e) e
  where
    sortedMBy :: (e -> e -> Bool) -> AnyBorder rep i e -> m Bool
sortedMBy e -> e -> Bool
f = (e -> e -> Bool) -> rep e -> m Bool
forall (m :: * -> *) s e.
SortM m s e =>
(e -> e -> Bool) -> s -> m Bool
sortedMBy e -> e -> Bool
f (rep e -> m Bool)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> m Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    sortMBy :: Compare e -> AnyBorder rep i e -> m ()
sortMBy   Compare e
f = Compare e -> rep e -> m ()
forall (m :: * -> *) s e. SortM m s e => Compare e -> s -> m ()
sortMBy   Compare e
f (rep e -> m ())
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack

--------------------------------------------------------------------------------

{- Freeze and Thaw instances. -}

-- Bordered (with any index) to prim.
instance {-# OVERLAPPABLE #-} (Index i, Thaw m (rep e) mut) => Thaw m (AnyBorder rep i e) mut
  where
    unsafeThaw :: AnyBorder rep i e -> m mut
unsafeThaw = rep e -> m mut
forall (m :: * -> *) v v'. Thaw m v v' => v -> m v'
unsafeThaw (rep e -> m mut)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> m mut
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    thaw :: AnyBorder rep i e -> m mut
thaw       = rep e -> m mut
forall (m :: * -> *) v v'. Thaw m v v' => v -> m v'
thaw (rep e -> m mut)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> m mut
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack

-- Prim to bordered (with any index).
instance {-# OVERLAPPABLE #-} (Index i, Thaw m imm (rep e), Bordered1 rep Int e) => Thaw m imm (AnyBorder rep i e)
  where
    unsafeThaw :: imm -> m (AnyBorder rep i e)
unsafeThaw = (rep e -> AnyBorder rep i e) -> m (rep e) -> m (AnyBorder rep i e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (m (rep e) -> m (AnyBorder rep i e))
-> (imm -> m (rep e)) -> imm -> m (AnyBorder rep i e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. imm -> m (rep e)
forall (m :: * -> *) v v'. Thaw m v v' => v -> m v'
unsafeThaw
    thaw :: imm -> m (AnyBorder rep i e)
thaw       = (rep e -> AnyBorder rep i e) -> m (rep e) -> m (AnyBorder rep i e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (m (rep e) -> m (AnyBorder rep i e))
-> (imm -> m (rep e)) -> imm -> m (AnyBorder rep i e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. imm -> m (rep e)
forall (m :: * -> *) v v'. Thaw m v v' => v -> m v'
thaw

-- Lift prim to prim on bordered on bordered (with same index).
instance {-# OVERLAPS #-} (Index i, Thaw1 m imm mut e) => Thaw m (AnyBorder imm i e) (AnyBorder mut i e)
  where
    unsafeThaw :: AnyBorder imm i e -> m (AnyBorder mut i e)
unsafeThaw (AnyBorder i
l i
u imm e
imm) = i -> i -> mut e -> AnyBorder mut i e
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder i
l i
u (mut e -> AnyBorder mut i e) -> m (mut e) -> m (AnyBorder mut i e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> imm e -> m (mut e)
forall (m :: * -> *) v v'. Thaw m v v' => v -> m v'
unsafeThaw imm e
imm
    thaw :: AnyBorder imm i e -> m (AnyBorder mut i e)
thaw       (AnyBorder i
l i
u imm e
imm) = i -> i -> mut e -> AnyBorder mut i e
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder i
l i
u (mut e -> AnyBorder mut i e) -> m (mut e) -> m (AnyBorder mut i e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> imm e -> m (mut e)
forall (m :: * -> *) v v'. Thaw m v v' => v -> m v'
thaw imm e
imm

-- Bordered (with any index) to prim.
instance {-# OVERLAPPABLE #-} (Index i, Freeze m (rep e) imm) => Freeze m (AnyBorder rep i e) imm
  where
    unsafeFreeze :: AnyBorder rep i e -> m imm
unsafeFreeze = rep e -> m imm
forall (m :: * -> *) v' v. Freeze m v' v => v' -> m v
unsafeFreeze (rep e -> m imm)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> m imm
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack
    freeze :: AnyBorder rep i e -> m imm
freeze       = rep e -> m imm
forall (m :: * -> *) v' v. Freeze m v' v => v' -> m v
freeze (rep e -> m imm)
-> (AnyBorder rep i e -> rep e) -> AnyBorder rep i e -> m imm
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnyBorder rep i e -> rep e
forall (rep :: * -> *) i e. AnyBorder rep i e -> rep e
unpack

-- Prim to bordered (with any index).
instance {-# OVERLAPPABLE #-} (Index i, Freeze m mut (rep e), Bordered1 rep Int e) => Freeze m mut (AnyBorder rep i e)
  where
    unsafeFreeze :: mut -> m (AnyBorder rep i e)
unsafeFreeze = (rep e -> AnyBorder rep i e) -> m (rep e) -> m (AnyBorder rep i e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (m (rep e) -> m (AnyBorder rep i e))
-> (mut -> m (rep e)) -> mut -> m (AnyBorder rep i e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. mut -> m (rep e)
forall (m :: * -> *) v' v. Freeze m v' v => v' -> m v
unsafeFreeze
    freeze :: mut -> m (AnyBorder rep i e)
freeze       = (rep e -> AnyBorder rep i e) -> m (rep e) -> m (AnyBorder rep i e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap rep e -> AnyBorder rep i e
forall i (rep :: * -> *) e.
(Index i, Bordered1 rep Int e) =>
rep e -> AnyBorder rep i e
withBounds (m (rep e) -> m (AnyBorder rep i e))
-> (mut -> m (rep e)) -> mut -> m (AnyBorder rep i e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. mut -> m (rep e)
forall (m :: * -> *) v' v. Freeze m v' v => v' -> m v
freeze

-- Lift prim to prim on bordered to bordered (with same index).
instance {-# OVERLAPS #-} (Index i, Freeze1 m mut imm e) => Freeze m (AnyBorder mut i e) (AnyBorder imm i e)
  where
    unsafeFreeze :: AnyBorder mut i e -> m (AnyBorder imm i e)
unsafeFreeze (AnyBorder i
l i
u mut e
mut) = i -> i -> imm e -> AnyBorder imm i e
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder i
l i
u (imm e -> AnyBorder imm i e) -> m (imm e) -> m (AnyBorder imm i e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> mut e -> m (imm e)
forall (m :: * -> *) v' v. Freeze m v' v => v' -> m v
unsafeFreeze mut e
mut
    freeze :: AnyBorder mut i e -> m (AnyBorder imm i e)
freeze       (AnyBorder i
l i
u mut e
mut) = i -> i -> imm e -> AnyBorder imm i e
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder i
l i
u (imm e -> AnyBorder imm i e) -> m (imm e) -> m (AnyBorder imm i e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> mut e -> m (imm e)
forall (m :: * -> *) v' v. Freeze m v' v => v' -> m v
freeze mut e
mut

--------------------------------------------------------------------------------

expEx :: String -> a
expEx :: String -> a
expEx =  IndexException -> a
forall a e. Exception e => e -> a
throw (IndexException -> a) -> (String -> IndexException) -> String -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> IndexException
UnacceptableExpansion (String -> IndexException) -> ShowS -> String -> IndexException
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
"in SDP.Templates.AnyBorder."

ascsBounds :: (Ord a) => [(a, b)] -> (a, a)
ascsBounds :: [(a, b)] -> (a, a)
ascsBounds =  \ ((a
x, b
_) : [(a, b)]
xs) -> ((a, b) -> (a, a) -> (a, a)) -> (a, a) -> [(a, b)] -> (a, a)
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (\ (a
e, b
_) (a
mn, a
mx) -> (a -> a -> a
forall a. Ord a => a -> a -> a
min a
mn a
e, a -> a -> a
forall a. Ord a => a -> a -> a
max a
mx a
e)) (a
x, a
x) [(a, b)]
xs

{-# INLINE unpack #-}
unpack :: AnyBorder rep i e -> rep e
unpack :: AnyBorder rep i e -> rep e
unpack =  \ (AnyBorder i
_ i
_ rep e
es) -> rep e
es

{-# INLINE withBounds #-}
withBounds :: (Index i, Bordered1 rep Int e) => rep e -> AnyBorder rep i e
withBounds :: rep e -> AnyBorder rep i e
withBounds rep e
rep = (i -> i -> rep e -> AnyBorder rep i e)
-> (i, i) -> rep e -> AnyBorder rep i e
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry i -> i -> rep e -> AnyBorder rep i e
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder (Int -> (i, i)
forall i. Index i => Int -> (i, i)
defaultBounds (Int -> (i, i)) -> Int -> (i, i)
forall a b. (a -> b) -> a -> b
$ rep e -> Int
forall b i. Bordered b i => b -> Int
sizeOf rep e
rep) rep e
rep

{-# INLINE withBounds' #-}
withBounds' :: (Index i, BorderedM1 m rep Int e) => rep e -> m (AnyBorder rep i e)
withBounds' :: rep e -> m (AnyBorder rep i e)
withBounds' rep e
rep = (\ Int
n -> (i -> i -> rep e -> AnyBorder rep i e)
-> (i, i) -> rep e -> AnyBorder rep i e
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry i -> i -> rep e -> AnyBorder rep i e
forall (rep :: * -> *) i e. i -> i -> rep e -> AnyBorder rep i e
AnyBorder (Int -> (i, i)
forall i. Index i => Int -> (i, i)
defaultBounds Int
n) rep e
rep) (Int -> AnyBorder rep i e) -> m Int -> m (AnyBorder rep i e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> rep e -> m Int
forall (m :: * -> *) b i. BorderedM m b i => b -> m Int
getSizeOf rep e
rep