{-# LANGUAGE TypeFamilies, TypeOperators, DefaultSignatures, ConstraintKinds #-}
{-# LANGUAGE CPP, FlexibleInstances, UndecidableInstances, Trustworthy #-}

{- |
    Module      :  SDP.Shape
    Copyright   :  (c) Andrey Mulik 2020-2021
    License     :  BSD-style
    Maintainer  :  work.a.mulik@gmail.com
    Portability :  non-portable (GHC extensions)
    
    "SDP.Shape" module provides 'Shape' - class of generalized indices.
-}
module SDP.Shape
(
  -- * Exports
  module SDP.Finite,
  module SDP.Tuple,
  
  module Data.Word,
  module Data.Int,
  
  -- * Shapes
  Shape (..), GIndex, toGBounds, fromGBounds,
  
  -- ** Rank constraints
  RANK0, RANK1, RANK2,  RANK3,  RANK4,  RANK5,  RANK6,  RANK7,
  RANK8, RANK9, RANK10, RANK11, RANK12, RANK13, RANK14, RANK15
)
where

import Prelude ()
import SDP.SafePrelude
import SDP.Finite
import SDP.Tuple

import Data.Word
import Data.Int

import GHC.Types

import Foreign.C.Types

default ()

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

-- | Type operator 'GIndex' returns generalized equivalent of index.
type family GIndex i
  where
    GIndex     E     = E
    GIndex (i' :& i) = i' :& i
    GIndex     i     = GIndex (DimInit i) :& DimLast i

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

{- |
  'Shape' is service class that constraints 'SDP.Index.Index'.
  
  Rules:
  
  > rank i == rank   (j `asTypeOf` i)
  > rank i == length (sizes (i, i))
  
  > rank (lastDim E) = 0
  > rank (lastDim i) = 1
  > rank (initDim E) = 0
  > rank (lastDim i) = rank i - 1
  
  > fromGIndex . toGIndex = id
  > toGIndex . fromGIndex = id
-}
class Shape i
  where
    -- | Type of index top dimension.
    type DimLast i :: Type
    type DimLast i =  i
    
    {- |
      The type of subspace of 'rank' @n - 1@, where @n@ is the 'rank' of the
      space specified by this 'SDP.Index.Index' type.
    -}
    type DimInit i :: Type
    type DimInit i =  E
    
    -- | Create index from generalized index.
    {-# INLINE fromGIndex #-}
    default fromGIndex :: (RANK1 i) => GIndex i -> i
    fromGIndex :: GIndex i -> i
    fromGIndex =  \ (E :& i) -> i
i
    
    -- | Create generalized index from index.
    {-# INLINE toGIndex #-}
    default toGIndex :: (RANK1 i) => i -> GIndex i
    toGIndex :: i -> GIndex i
    toGIndex =  (E
E E -> i -> E :& i
forall tail head. tail -> head -> tail :& head
:&)
    
    -- | Count of dimensions in represented space (must be finite and constant).
    {-# INLINE rank #-}
    rank :: i -> Int
    rank =  Int -> i -> Int
forall a b. a -> b -> a
const Int
1
    
    -- | Add new dimension.
    {-# INLINE consDim #-}
    default consDim :: (DimLast i ~~ i) => DimInit i -> DimLast i -> i
    consDim :: DimInit i -> DimLast i -> i
    consDim =  (i -> i) -> DimInit i -> i -> i
forall a b. a -> b -> a
const i -> i
forall k (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id
    
    {-# INLINE initDim #-}
    default initDim :: (DimInit i ~~ E) => i -> DimInit i
    initDim :: i -> DimInit i
    initDim =  E -> i -> E
forall a b. a -> b -> a
const E
E
    
    {-# INLINE lastDim #-}
    default lastDim :: (DimLast i ~~ i) => i -> DimLast i
    lastDim :: i -> DimLast i
    lastDim =  i -> DimLast i
forall k (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id
    
    {-# INLINE unconsDim #-}
    unconsDim :: i -> (DimInit i, DimLast i)
    unconsDim =  \ i
i -> (i -> DimInit i
forall i. Shape i => i -> DimInit i
initDim i
i, i -> DimLast i
forall i. Shape i => i -> DimLast i
lastDim i
i)

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

{- Rank constraints. -}

-- | A constraint corresponding to rank 0 indices ('E').
type RANK0  i = i ~~ E
-- | The restriction corresponding to rank indices 1 (сhecks 'GIndex').
type RANK1  i = GIndex i ~~ (E :& i)
-- | The restriction corresponding to rank indices 2 (сhecks 'GIndex').
type RANK2  i = GIndex i ~~ I2  i
-- | The restriction corresponding to rank indices 3 (сhecks 'GIndex').
type RANK3  i = GIndex i ~~ I3  i
-- | The restriction corresponding to rank indices 4 (сhecks 'GIndex').
type RANK4  i = GIndex i ~~ I4  i
-- | The restriction corresponding to rank indices 5 (сhecks 'GIndex').
type RANK5  i = GIndex i ~~ I5  i
-- | The restriction corresponding to rank indices 6 (сhecks 'GIndex').
type RANK6  i = GIndex i ~~ I6  i
-- | The restriction corresponding to rank indices 7 (сhecks 'GIndex').
type RANK7  i = GIndex i ~~ I7  i
-- | The restriction corresponding to rank indices 8 (сhecks 'GIndex').
type RANK8  i = GIndex i ~~ I8  i
-- | The restriction corresponding to rank indices 9 (сhecks 'GIndex').
type RANK9  i = GIndex i ~~ I9  i
-- | The restriction corresponding to rank indices 10 (сhecks 'GIndex').
type RANK10 i = GIndex i ~~ I10 i
-- | The restriction corresponding to rank indices 11 (сhecks 'GIndex').
type RANK11 i = GIndex i ~~ I11 i
-- | The restriction corresponding to rank indices 12 (сhecks 'GIndex').
type RANK12 i = GIndex i ~~ I12 i
-- | The restriction corresponding to rank indices 13 (сhecks 'GIndex').
type RANK13 i = GIndex i ~~ I13 i
-- | The restriction corresponding to rank indices 14 (сhecks 'GIndex').
type RANK14 i = GIndex i ~~ I14 i
-- | The restriction corresponding to rank indices 15 (сhecks 'GIndex').
type RANK15 i = GIndex i ~~ I15 i

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

{- Basic instances. -}

instance Shape E where rank :: E -> Int
rank = Int -> E -> Int
forall a b. a -> b -> a
const Int
0; toGIndex :: E -> GIndex E
toGIndex = E -> GIndex E
forall k (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id; fromGIndex :: GIndex E -> E
fromGIndex = GIndex E -> E
forall k (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id
instance Shape ()
instance Shape Char
instance Shape Integer

instance Shape Int
instance Shape Int8
instance Shape Int16
instance Shape Int32
instance Shape Int64

instance Shape Word
instance Shape Word8
instance Shape Word16
instance Shape Word32
instance Shape Word64

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

{- Foreign C instances. -}

instance Shape CChar
instance Shape CUChar
instance Shape CSChar
instance Shape CWchar
instance Shape CShort
instance Shape CUShort

instance Shape CInt
instance Shape CUInt
instance Shape CLong
instance Shape CLLong
instance Shape CULong
instance Shape CULLong
instance Shape CIntPtr
instance Shape CUIntPtr

instance Shape CIntMax
instance Shape CUIntMax

instance Shape CSize

#if MIN_VERSION_base(4,10,0)
-- | since @base-4.10.0.0@
instance Shape CBool
#endif

instance Shape CPtrdiff
instance Shape CSigAtomic

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

{- N-dimensional instances. -}

instance (Shape i) => Shape (E :& i)
  where
    type DimInit (E :& i) = E
    type DimLast (E :& i) = i
    
    fromGIndex :: GIndex (E :& i) -> E :& i
fromGIndex = GIndex (E :& i) -> E :& i
forall k (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id
    toGIndex :: (E :& i) -> GIndex (E :& i)
toGIndex   = (E :& i) -> GIndex (E :& i)
forall k (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id
    
    consDim :: DimInit (E :& i) -> DimLast (E :& i) -> E :& i
consDim   = DimInit (E :& i) -> DimLast (E :& i) -> E :& i
forall tail head. tail -> head -> tail :& head
(:&)
    initDim :: (E :& i) -> DimInit (E :& i)
initDim   = \ (E
is :& i
_) -> E
DimInit (E :& i)
is
    lastDim :: (E :& i) -> DimLast (E :& i)
lastDim   = \ (E
_  :& i
i) -> i
DimLast (E :& i)
i
    unconsDim :: (E :& i) -> (DimInit (E :& i), DimLast (E :& i))
unconsDim = \ (E
is :& i
i) -> (E
DimInit (E :& i)
is, i
DimLast (E :& i)
i)

instance (Shape i, Enum i, Bounded i, Shape (i' :& i)) => Shape (i' :& i :& i)
  where
    type DimInit (i' :& i :& i) = i' :& i
    type DimLast (i' :& i :& i) = i
    
    rank :: ((i' :& i) :& i) -> Int
rank = (Int -> (i' :& i) -> Int
forall a b. a -> b -> a
const (Int -> (i' :& i) -> Int) -> (i' -> Int) -> i' -> (i' :& i) -> Int
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Int -> Int
forall a. Enum a => a -> a
succ (Int -> Int) -> (i' -> Int) -> i' -> Int
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. i' -> Int
forall i. Shape i => i -> Int
rank :: Shape i' => i' -> (i' :& i) -> Int) i' :& i
forall a. HasCallStack => a
undefined
    
    fromGIndex :: GIndex ((i' :& i) :& i) -> (i' :& i) :& i
fromGIndex = GIndex ((i' :& i) :& i) -> (i' :& i) :& i
forall k (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id
    toGIndex :: ((i' :& i) :& i) -> GIndex ((i' :& i) :& i)
toGIndex   = ((i' :& i) :& i) -> GIndex ((i' :& i) :& i)
forall k (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id
    
    consDim :: DimInit ((i' :& i) :& i)
-> DimLast ((i' :& i) :& i) -> (i' :& i) :& i
consDim   = DimInit ((i' :& i) :& i)
-> DimLast ((i' :& i) :& i) -> (i' :& i) :& i
forall tail head. tail -> head -> tail :& head
(:&)
    initDim :: ((i' :& i) :& i) -> DimInit ((i' :& i) :& i)
initDim   = \ (i' :& i
is :& i
_) -> i' :& i
DimInit ((i' :& i) :& i)
is
    lastDim :: ((i' :& i) :& i) -> DimLast ((i' :& i) :& i)
lastDim   = \ (i' :& i
_  :& i
i) -> i
DimLast ((i' :& i) :& i)
i
    unconsDim :: ((i' :& i) :& i)
-> (DimInit ((i' :& i) :& i), DimLast ((i' :& i) :& i))
unconsDim = \ (i' :& i
is :& i
i) -> (i' :& i
DimInit ((i' :& i) :& i)
is, i
DimLast ((i' :& i) :& i)
i)

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

{- Tuple instances. -}

#define SHAPE_INSTANCE(Type,Last,RANK)\
instance (Shape i, Enum i, Bounded i) => Shape (Type i)\
where\
{\
type DimLast (Type i) = i;\
type DimInit (Type i) = Last i;\
rank = const RANK;\
initDim = fst . unconsDim;\
lastDim = snd . unconsDim;

SHAPE_INSTANCE(T2, I1, 2)
fromGIndex :: GIndex (T2 i) -> T2 i
fromGIndex = \ (E:&a:&b) -> (i
a,i
b);
consDim :: DimInit (T2 i) -> DimLast (T2 i) -> T2 i
consDim    = \ (E:&a) DimLast (T2 i)
b  -> (i
a,i
DimLast (T2 i)
b);
unconsDim :: T2 i -> (DimInit (T2 i), DimLast (T2 i))
unconsDim  (i
a,i
b) = (E
EE -> i -> I1 i
forall tail head. tail -> head -> tail :& head
:&i
a,i
DimLast (T2 i)
b);
toGIndex :: T2 i -> GIndex (T2 i)
toGIndex   (i
a,i
b) = E
EE -> i -> I1 i
forall tail head. tail -> head -> tail :& head
:&i
aI1 i -> i -> I1 i :& i
forall tail head. tail -> head -> tail :& head
:&i
b;
}

SHAPE_INSTANCE(T3, T2, 3)
fromGIndex :: GIndex (T3 i) -> T3 i
fromGIndex = \ (E:&a:&b:&c) -> (i
a,i
b,i
c);
toGIndex :: T3 i -> GIndex (T3 i)
toGIndex   (i
a,i
b,i
c) = E
EE -> i -> E :& i
forall tail head. tail -> head -> tail :& head
:&i
a(E :& i) -> i -> (E :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
b((E :& i) :& i) -> i -> ((E :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
c;
unconsDim :: T3 i -> (DimInit (T3 i), DimLast (T3 i))
unconsDim  (i
a,i
b,i
c) = ((i
a,i
b),i
DimLast (T3 i)
c);
consDim :: DimInit (T3 i) -> DimLast (T3 i) -> T3 i
consDim    (a,b) DimLast (T3 i)
c = (i
a,i
b,i
DimLast (T3 i)
c);
}

SHAPE_INSTANCE(T4, T3, 4)
fromGIndex :: GIndex (T4 i) -> T4 i
fromGIndex = \ (E:&a:&b:&c:&d) -> (i
a,i
b,i
c,i
d);
toGIndex :: T4 i -> GIndex (T4 i)
toGIndex   (i
a,i
b,i
c,i
d) = E
EE -> i -> E :& i
forall tail head. tail -> head -> tail :& head
:&i
a(E :& i) -> i -> (E :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
b((E :& i) :& i) -> i -> ((E :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
c(((E :& i) :& i) :& i) -> i -> (((E :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
d;
unconsDim :: T4 i -> (DimInit (T4 i), DimLast (T4 i))
unconsDim  (i
a,i
b,i
c,i
d) = ((i
a,i
b,i
c),i
DimLast (T4 i)
d);
consDim :: DimInit (T4 i) -> DimLast (T4 i) -> T4 i
consDim    (a,b,c) DimLast (T4 i)
d = (i
a,i
b,i
c,i
DimLast (T4 i)
d);
}

SHAPE_INSTANCE(T5, T4, 5)
fromGIndex :: GIndex (T5 i) -> T5 i
fromGIndex = \ (E:&a:&b:&c:&d:&e) -> (i
a,i
b,i
c,i
d,i
e);
toGIndex :: T5 i -> GIndex (T5 i)
toGIndex   (i
a,i
b,i
c,i
d,i
e) = E
EE -> i -> E :& i
forall tail head. tail -> head -> tail :& head
:&i
a(E :& i) -> i -> (E :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
b((E :& i) :& i) -> i -> ((E :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
c(((E :& i) :& i) :& i) -> i -> (((E :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
d((((E :& i) :& i) :& i) :& i)
-> i -> ((((E :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
e;
unconsDim :: T5 i -> (DimInit (T5 i), DimLast (T5 i))
unconsDim  (i
a,i
b,i
c,i
d,i
e) = ((i
a,i
b,i
c,i
d),i
DimLast (T5 i)
e);
consDim :: DimInit (T5 i) -> DimLast (T5 i) -> T5 i
consDim    (a,b,c,d) DimLast (T5 i)
e = (i
a,i
b,i
c,i
d,i
DimLast (T5 i)
e);
}

SHAPE_INSTANCE(T6, T5, 6)
fromGIndex :: GIndex (T6 i) -> T6 i
fromGIndex = \ (E:&a:&b:&c:&d:&e:&f) -> (i
a,i
b,i
c,i
d,i
e,i
f);
toGIndex :: T6 i -> GIndex (T6 i)
toGIndex   (i
a,i
b,i
c,i
d,i
e,i
f) = E
EE -> i -> E :& i
forall tail head. tail -> head -> tail :& head
:&i
a(E :& i) -> i -> (E :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
b((E :& i) :& i) -> i -> ((E :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
c(((E :& i) :& i) :& i) -> i -> (((E :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
d((((E :& i) :& i) :& i) :& i)
-> i -> ((((E :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
e(((((E :& i) :& i) :& i) :& i) :& i)
-> i -> (((((E :& i) :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
f;
unconsDim :: T6 i -> (DimInit (T6 i), DimLast (T6 i))
unconsDim  (i
a,i
b,i
c,i
d,i
e,i
f) = ((i
a,i
b,i
c,i
d,i
e),i
DimLast (T6 i)
f);
consDim :: DimInit (T6 i) -> DimLast (T6 i) -> T6 i
consDim    (a,b,c,d,e) DimLast (T6 i)
f = (i
a,i
b,i
c,i
d,i
e,i
DimLast (T6 i)
f);
}

SHAPE_INSTANCE(T7, T6, 7)
fromGIndex :: GIndex (T7 i) -> T7 i
fromGIndex = \ (E:&a:&b:&c:&d:&e:&f:&g) -> (i
a,i
b,i
c,i
d,i
e,i
f,i
g);
toGIndex :: T7 i -> GIndex (T7 i)
toGIndex   (i
a,i
b,i
c,i
d,i
e,i
f,i
g) = E
EE -> i -> E :& i
forall tail head. tail -> head -> tail :& head
:&i
a(E :& i) -> i -> (E :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
b((E :& i) :& i) -> i -> ((E :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
c(((E :& i) :& i) :& i) -> i -> (((E :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
d((((E :& i) :& i) :& i) :& i)
-> i -> ((((E :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
e(((((E :& i) :& i) :& i) :& i) :& i)
-> i -> (((((E :& i) :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
f((((((E :& i) :& i) :& i) :& i) :& i) :& i)
-> i -> ((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
g;
unconsDim :: T7 i -> (DimInit (T7 i), DimLast (T7 i))
unconsDim  (i
a,i
b,i
c,i
d,i
e,i
f,i
g) = ((i
a,i
b,i
c,i
d,i
e,i
f),i
DimLast (T7 i)
g);
consDim :: DimInit (T7 i) -> DimLast (T7 i) -> T7 i
consDim    (a,b,c,d,e,f) DimLast (T7 i)
g = (i
a,i
b,i
c,i
d,i
e,i
f,i
DimLast (T7 i)
g);
}

SHAPE_INSTANCE(T8, T7, 8)
fromGIndex :: GIndex (T8 i) -> T8 i
fromGIndex = \ (E:&a:&b:&c:&d:&e:&f:&g:&h) -> (i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h);
toGIndex :: T8 i -> GIndex (T8 i)
toGIndex   (i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h) = E
EE -> i -> E :& i
forall tail head. tail -> head -> tail :& head
:&i
a(E :& i) -> i -> (E :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
b((E :& i) :& i) -> i -> ((E :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
c(((E :& i) :& i) :& i) -> i -> (((E :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
d((((E :& i) :& i) :& i) :& i)
-> i -> ((((E :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
e(((((E :& i) :& i) :& i) :& i) :& i)
-> i -> (((((E :& i) :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
f((((((E :& i) :& i) :& i) :& i) :& i) :& i)
-> i -> ((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
g(((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i)
-> i -> (((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
h;
unconsDim :: T8 i -> (DimInit (T8 i), DimLast (T8 i))
unconsDim  (i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h) = ((i
a,i
b,i
c,i
d,i
e,i
f,i
g),i
DimLast (T8 i)
h);
consDim :: DimInit (T8 i) -> DimLast (T8 i) -> T8 i
consDim    (a,b,c,d,e,f,g) DimLast (T8 i)
h = (i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
DimLast (T8 i)
h);
}

SHAPE_INSTANCE(T9, T8, 9)
fromGIndex :: GIndex (T9 i) -> T9 i
fromGIndex = \ (E:&a:&b:&c:&d:&e:&f:&g:&h:&i) -> (i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h,i
i);
toGIndex :: T9 i -> GIndex (T9 i)
toGIndex   (i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h,i
i) = E
EE -> i -> E :& i
forall tail head. tail -> head -> tail :& head
:&i
a(E :& i) -> i -> (E :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
b((E :& i) :& i) -> i -> ((E :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
c(((E :& i) :& i) :& i) -> i -> (((E :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
d((((E :& i) :& i) :& i) :& i)
-> i -> ((((E :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
e(((((E :& i) :& i) :& i) :& i) :& i)
-> i -> (((((E :& i) :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
f((((((E :& i) :& i) :& i) :& i) :& i) :& i)
-> i -> ((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
g(((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i)
-> i -> (((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
h((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
-> i
-> ((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
i;
unconsDim :: T9 i -> (DimInit (T9 i), DimLast (T9 i))
unconsDim  (i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h,i
i) = ((i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h),i
DimLast (T9 i)
i);
consDim :: DimInit (T9 i) -> DimLast (T9 i) -> T9 i
consDim    (a,b,c,d,e,f,g,h) DimLast (T9 i)
i = (i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h,i
DimLast (T9 i)
i);
}

SHAPE_INSTANCE(T10, T9, 10)
fromGIndex :: GIndex (T10 i) -> T10 i
fromGIndex = \ (E:&a:&b:&c:&d:&e:&f:&g:&h:&i:&j) -> (i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h,i
i,i
j);
toGIndex :: T10 i -> GIndex (T10 i)
toGIndex   (i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h,i
i,i
j) = E
EE -> i -> E :& i
forall tail head. tail -> head -> tail :& head
:&i
a(E :& i) -> i -> (E :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
b((E :& i) :& i) -> i -> ((E :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
c(((E :& i) :& i) :& i) -> i -> (((E :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
d((((E :& i) :& i) :& i) :& i)
-> i -> ((((E :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
e(((((E :& i) :& i) :& i) :& i) :& i)
-> i -> (((((E :& i) :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
f((((((E :& i) :& i) :& i) :& i) :& i) :& i)
-> i -> ((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
g(((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i)
-> i -> (((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
h((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
-> i
-> ((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
i(((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
-> i
-> (((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
   :& i
forall tail head. tail -> head -> tail :& head
:&i
j;
unconsDim :: T10 i -> (DimInit (T10 i), DimLast (T10 i))
unconsDim  (i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h,i
i,i
j) = ((i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h,i
i),i
DimLast (T10 i)
j);
consDim :: DimInit (T10 i) -> DimLast (T10 i) -> T10 i
consDim    (a,b,c,d,e,f,g,h,i) DimLast (T10 i)
j = (i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h,i
i,i
DimLast (T10 i)
j);
}

SHAPE_INSTANCE(T11, T10, 11)
fromGIndex :: GIndex (T11 i) -> T11 i
fromGIndex = \ (E:&a:&b:&c:&d:&e:&f:&g:&h:&i:&j:&k) -> (i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h,i
i,i
j,i
k);
toGIndex :: T11 i -> GIndex (T11 i)
toGIndex   (i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h,i
i,i
j,i
k) = E
EE -> i -> E :& i
forall tail head. tail -> head -> tail :& head
:&i
a(E :& i) -> i -> (E :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
b((E :& i) :& i) -> i -> ((E :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
c(((E :& i) :& i) :& i) -> i -> (((E :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
d((((E :& i) :& i) :& i) :& i)
-> i -> ((((E :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
e(((((E :& i) :& i) :& i) :& i) :& i)
-> i -> (((((E :& i) :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
f((((((E :& i) :& i) :& i) :& i) :& i) :& i)
-> i -> ((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
g(((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i)
-> i -> (((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
h((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
-> i
-> ((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
i(((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
-> i
-> (((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
   :& i
forall tail head. tail -> head -> tail :& head
:&i
j((((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
 :& i)
-> i
-> ((((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
     :& i)
    :& i)
   :& i
forall tail head. tail -> head -> tail :& head
:&i
k;
unconsDim :: T11 i -> (DimInit (T11 i), DimLast (T11 i))
unconsDim  (i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h,i
i,i
j,i
k) = ((i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h,i
i,i
j),i
DimLast (T11 i)
k);
consDim :: DimInit (T11 i) -> DimLast (T11 i) -> T11 i
consDim    (a,b,c,d,e,f,g,h,i,j) DimLast (T11 i)
k = (i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h,i
i,i
j,i
DimLast (T11 i)
k);
}

SHAPE_INSTANCE(T12, T11, 12)
fromGIndex :: GIndex (T12 i) -> T12 i
fromGIndex = \ (E:&a:&b:&c:&d:&e:&f:&g:&h:&i:&j:&k:&l) -> (i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h,i
i,i
j,i
k,i
l);
toGIndex :: T12 i -> GIndex (T12 i)
toGIndex   (i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h,i
i,i
j,i
k,i
l) = E
EE -> i -> E :& i
forall tail head. tail -> head -> tail :& head
:&i
a(E :& i) -> i -> (E :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
b((E :& i) :& i) -> i -> ((E :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
c(((E :& i) :& i) :& i) -> i -> (((E :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
d((((E :& i) :& i) :& i) :& i)
-> i -> ((((E :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
e(((((E :& i) :& i) :& i) :& i) :& i)
-> i -> (((((E :& i) :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
f((((((E :& i) :& i) :& i) :& i) :& i) :& i)
-> i -> ((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
g(((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i)
-> i -> (((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
h((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
-> i
-> ((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
i(((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
-> i
-> (((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
   :& i
forall tail head. tail -> head -> tail :& head
:&i
j((((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
 :& i)
-> i
-> ((((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
     :& i)
    :& i)
   :& i
forall tail head. tail -> head -> tail :& head
:&i
k(((((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
  :& i)
 :& i)
-> i
-> (((((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
      :& i)
     :& i)
    :& i)
   :& i
forall tail head. tail -> head -> tail :& head
:&i
l;
unconsDim :: T12 i -> (DimInit (T12 i), DimLast (T12 i))
unconsDim  (i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h,i
i,i
j,i
k,i
l) = ((i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h,i
i,i
j,i
k),i
DimLast (T12 i)
l);
consDim :: DimInit (T12 i) -> DimLast (T12 i) -> T12 i
consDim    (a,b,c,d,e,f,g,h,i,j,k) DimLast (T12 i)
l = (i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h,i
i,i
j,i
k,i
DimLast (T12 i)
l);
}

SHAPE_INSTANCE(T13, T12, 13)
fromGIndex :: GIndex (T13 i) -> T13 i
fromGIndex = \ (E:&a:&b:&c:&d:&e:&f:&g:&h:&i:&j:&k:&l:&m) -> (i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h,i
i,i
j,i
k,i
l,i
m);
toGIndex :: T13 i -> GIndex (T13 i)
toGIndex   (i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h,i
i,i
j,i
k,i
l,i
m) = E
EE -> i -> E :& i
forall tail head. tail -> head -> tail :& head
:&i
a(E :& i) -> i -> (E :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
b((E :& i) :& i) -> i -> ((E :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
c(((E :& i) :& i) :& i) -> i -> (((E :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
d((((E :& i) :& i) :& i) :& i)
-> i -> ((((E :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
e(((((E :& i) :& i) :& i) :& i) :& i)
-> i -> (((((E :& i) :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
f((((((E :& i) :& i) :& i) :& i) :& i) :& i)
-> i -> ((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
g(((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i)
-> i -> (((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
h((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
-> i
-> ((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
i(((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
-> i
-> (((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
   :& i
forall tail head. tail -> head -> tail :& head
:&i
j((((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
 :& i)
-> i
-> ((((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
     :& i)
    :& i)
   :& i
forall tail head. tail -> head -> tail :& head
:&i
k(((((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
  :& i)
 :& i)
-> i
-> (((((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
      :& i)
     :& i)
    :& i)
   :& i
forall tail head. tail -> head -> tail :& head
:&i
l((((((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
   :& i)
  :& i)
 :& i)
-> i
-> ((((((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
       :& i)
      :& i)
     :& i)
    :& i)
   :& i
forall tail head. tail -> head -> tail :& head
:&i
m;
unconsDim :: T13 i -> (DimInit (T13 i), DimLast (T13 i))
unconsDim  (i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h,i
i,i
j,i
k,i
l,i
m) = ((i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h,i
i,i
j,i
k,i
l),i
DimLast (T13 i)
m);
consDim :: DimInit (T13 i) -> DimLast (T13 i) -> T13 i
consDim    (a,b,c,d,e,f,g,h,i,j,k,l) DimLast (T13 i)
m = (i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h,i
i,i
j,i
k,i
l,i
DimLast (T13 i)
m);
}

SHAPE_INSTANCE(T14, T13, 14)
fromGIndex :: GIndex (T14 i) -> T14 i
fromGIndex = \ (E:&a:&b:&c:&d:&e:&f:&g:&h:&i:&j:&k:&l:&m:&n) -> (i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h,i
i,i
j,i
k,i
l,i
m,i
n);
toGIndex :: T14 i -> GIndex (T14 i)
toGIndex   (i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h,i
i,i
j,i
k,i
l,i
m,i
n) = E
EE -> i -> E :& i
forall tail head. tail -> head -> tail :& head
:&i
a(E :& i) -> i -> (E :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
b((E :& i) :& i) -> i -> ((E :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
c(((E :& i) :& i) :& i) -> i -> (((E :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
d((((E :& i) :& i) :& i) :& i)
-> i -> ((((E :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
e(((((E :& i) :& i) :& i) :& i) :& i)
-> i -> (((((E :& i) :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
f((((((E :& i) :& i) :& i) :& i) :& i) :& i)
-> i -> ((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
g(((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i)
-> i -> (((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
h((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
-> i
-> ((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
i(((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
-> i
-> (((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
   :& i
forall tail head. tail -> head -> tail :& head
:&i
j((((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
 :& i)
-> i
-> ((((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
     :& i)
    :& i)
   :& i
forall tail head. tail -> head -> tail :& head
:&i
k(((((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
  :& i)
 :& i)
-> i
-> (((((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
      :& i)
     :& i)
    :& i)
   :& i
forall tail head. tail -> head -> tail :& head
:&i
l((((((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
   :& i)
  :& i)
 :& i)
-> i
-> ((((((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
       :& i)
      :& i)
     :& i)
    :& i)
   :& i
forall tail head. tail -> head -> tail :& head
:&i
m(((((((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
     :& i)
    :& i)
   :& i)
  :& i)
 :& i)
-> i
-> (((((((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
        :& i)
       :& i)
      :& i)
     :& i)
    :& i)
   :& i
forall tail head. tail -> head -> tail :& head
:&i
n;
unconsDim :: T14 i -> (DimInit (T14 i), DimLast (T14 i))
unconsDim  (i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h,i
i,i
j,i
k,i
l,i
m,i
n) = ((i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h,i
i,i
j,i
k,i
l,i
m),i
DimLast (T14 i)
n);
consDim :: DimInit (T14 i) -> DimLast (T14 i) -> T14 i
consDim    (a,b,c,d,e,f,g,h,i,j,k,l,m) DimLast (T14 i)
n = (i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h,i
i,i
j,i
k,i
l,i
m,i
DimLast (T14 i)
n);
}

SHAPE_INSTANCE(T15, T14, 15)
fromGIndex :: GIndex (T15 i) -> T15 i
fromGIndex = \ (E:&a:&b:&c:&d:&e:&f:&g:&h:&i:&j:&k:&l:&m:&n:&o) -> (i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h,i
i,i
j,i
k,i
l,i
m,i
n,i
o);
toGIndex :: T15 i -> GIndex (T15 i)
toGIndex   (i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h,i
i,i
j,i
k,i
l,i
m,i
n,i
o) = E
EE -> i -> E :& i
forall tail head. tail -> head -> tail :& head
:&i
a(E :& i) -> i -> (E :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
b((E :& i) :& i) -> i -> ((E :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
c(((E :& i) :& i) :& i) -> i -> (((E :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
d((((E :& i) :& i) :& i) :& i)
-> i -> ((((E :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
e(((((E :& i) :& i) :& i) :& i) :& i)
-> i -> (((((E :& i) :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
f((((((E :& i) :& i) :& i) :& i) :& i) :& i)
-> i -> ((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
g(((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i)
-> i -> (((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
h((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
-> i
-> ((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i
forall tail head. tail -> head -> tail :& head
:&i
i(((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
-> i
-> (((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
   :& i
forall tail head. tail -> head -> tail :& head
:&i
j((((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
 :& i)
-> i
-> ((((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
     :& i)
    :& i)
   :& i
forall tail head. tail -> head -> tail :& head
:&i
k(((((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
  :& i)
 :& i)
-> i
-> (((((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
      :& i)
     :& i)
    :& i)
   :& i
forall tail head. tail -> head -> tail :& head
:&i
l((((((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
   :& i)
  :& i)
 :& i)
-> i
-> ((((((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
       :& i)
      :& i)
     :& i)
    :& i)
   :& i
forall tail head. tail -> head -> tail :& head
:&i
m(((((((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
     :& i)
    :& i)
   :& i)
  :& i)
 :& i)
-> i
-> (((((((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
        :& i)
       :& i)
      :& i)
     :& i)
    :& i)
   :& i
forall tail head. tail -> head -> tail :& head
:&i
n((((((((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
      :& i)
     :& i)
    :& i)
   :& i)
  :& i)
 :& i)
-> i
-> ((((((((((((((E :& i) :& i) :& i) :& i) :& i) :& i) :& i) :& i)
         :& i)
        :& i)
       :& i)
      :& i)
     :& i)
    :& i)
   :& i
forall tail head. tail -> head -> tail :& head
:&i
o;
unconsDim :: T15 i -> (DimInit (T15 i), DimLast (T15 i))
unconsDim  (i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h,i
i,i
j,i
k,i
l,i
m,i
n,i
o) = ((i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h,i
i,i
j,i
k,i
l,i
m,i
n),i
DimLast (T15 i)
o);
consDim :: DimInit (T15 i) -> DimLast (T15 i) -> T15 i
consDim    (a,b,c,d,e,f,g,h,i,j,k,l,m,n) DimLast (T15 i)
o = (i
a,i
b,i
c,i
d,i
e,i
f,i
g,i
h,i
i,i
j,i
k,i
l,i
m,i
n,i
DimLast (T15 i)
o);
}
#undef SHAPE_INSTANCE

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

-- | Convert any index type bounds to generalized index bounds.
toGBounds :: (Shape i) => (i, i) -> (GIndex i, GIndex i)
toGBounds :: (i, i) -> (GIndex i, GIndex i)
toGBounds =  (i -> GIndex i) -> (i, i) -> (GIndex i, GIndex i)
forall a b. (a -> b) -> (a, a) -> (b, b)
both i -> GIndex i
forall i. Shape i => i -> GIndex i
toGIndex

-- | Convert generalized index bounds to any index type bounds.
fromGBounds :: (Shape i) => (GIndex i, GIndex i) -> (i, i)
fromGBounds :: (GIndex i, GIndex i) -> (i, i)
fromGBounds =  (GIndex i -> i) -> (GIndex i, GIndex i) -> (i, i)
forall a b. (a -> b) -> (a, a) -> (b, b)
both GIndex i -> i
forall i. Shape i => GIndex i -> i
fromGIndex