module ADP.Fusion.SynVar.Split.Type
( module ADP.Fusion.SynVar.Split.Type
, Proxy (..)
) where
import Data.Proxy
import Data.Strict.Tuple
import Data.Vector.Fusion.Stream.Monadic
import Data.Vector.Fusion.Util (delay_inline)
import Debug.Trace
import GHC.TypeLits
import Prelude hiding (map,mapM)
import Data.Type.Equality
import Data.PrimitiveArray hiding (map)
import ADP.Fusion.Core.Classes
import ADP.Fusion.Core.Multi
import ADP.Fusion.SynVar.Array.Type
import ADP.Fusion.SynVar.Backtrack
import ADP.Fusion.SynVar.TableWrap
data SplitType = Fragment | Final
type family CalcSplitType splitType varTy where
CalcSplitType Fragment varTy = ()
CalcSplitType Final varTy = varTy
type family ArgTy argTy where
ArgTy (z:.x) = x
newtype Split (uId :: Symbol) (splitType :: SplitType) synVar = Split { getSplit :: synVar }
split :: Proxy (uId::Symbol) -> Proxy (splitType::SplitType) -> synVar -> Split uId splitType synVar
split _ _ = Split
instance Build (Split uId splitType synVar)
instance
( Element ls i
) => Element (ls :!: Split uId splitType (TwITbl m arr c j x)) i where
data Elm (ls :!: Split uId splitType (TwITbl m arr c j x)) i = ElmSplitITbl !(Proxy uId) !(CalcSplitType splitType x) !(RunningIndex i) !(Elm ls i) !i
type Arg (ls :!: Split uId splitType (TwITbl m arr c j x)) = Arg ls :. (CalcSplitType splitType x)
type RecElm (ls :!: Split uId splitType (TwITbl m arr c j x)) i = Elm ls i
getArg (ElmSplitITbl _ x _ ls _) = getArg ls :. x
getIdx (ElmSplitITbl _ _ i _ _) = i
getElm (ElmSplitITbl _ _ _ ls _) = ls
instance
( Element ls i
) => Element (ls :!: Split uId splitType (TwITblBt arr c j x mF mB r)) i where
data Elm (ls :!: Split uId splitType (TwITblBt arr c j x mF mB r)) i = ElmSplitBtITbl !(Proxy uId) !(CalcSplitType splitType (x, [r])) !(RunningIndex i) !(Elm ls i) !i
type Arg (ls :!: Split uId splitType (TwITblBt arr c j x mF mB r)) = Arg ls :. (CalcSplitType splitType (x,[r]))
type RecElm (ls :!: Split uId splitType (TwITblBt arr c j x mF mB r)) i = Elm ls i
getArg (ElmSplitBtITbl _ xs _ ls _) = getArg ls :. xs
getIdx (ElmSplitBtITbl _ _ i _ _) = i
getElm (ElmSplitBtITbl _ _ _ ls _) = ls
collectIx
:: forall uId ls i .
( SplitIxCol uId (SameSid uId (Elm ls i)) (Elm ls i)
)
=> Proxy uId -> Elm ls i -> SplitIxTy uId (SameSid uId (Elm ls i)) (Elm ls i)
collectIx p e = splitIxCol p (Proxy :: Proxy (SameSid uId (Elm ls i))) e
type family SameSid uId elm :: Bool where
SameSid uId (Elm (ls :!: Split sId splitType synVar) i) = uId == sId
SameSid uId (Elm (ls :!: TermSymbol a b ) i) = SameSid uId (TermSymbol a b)
SameSid uId M = False
SameSid uId (TermSymbol a (Split sId splitType synVar)) = OR (uId == sId) (SameSid uId a)
SameSid uId (Elm (ls :!: l ) i) = False
type family OR a b where
OR False False = False
OR a b = True
class Zconcat x y where
type Zpp x y :: *
zconcat :: x -> y -> Zpp x y
instance Zconcat x Z where
type Zpp x Z = x
zconcat x Z = x
instance
( Zconcat x z
) => Zconcat x (z:.y) where
type Zpp x (z:.y) = Zpp x z :. y
zconcat x (z:.y) = zconcat x z :. y
class SplitIxCol (uId::Symbol) (b::Bool) e where
type SplitIxTy uId b e :: *
splitIxCol :: Proxy uId -> Proxy b -> e -> SplitIxTy uId b e
instance SplitIxCol uId b (Elm S i) where
type SplitIxTy uId b (Elm S i) = Z
splitIxCol p b (ElmS _) = Z
instance
( SplitIxCol uId (SameSid uId (Elm ls i)) (Elm ls i)
, Element (ls :!: l) i
, RecElm (ls :!: l) i ~ Elm ls i
) => SplitIxCol uId False (Elm (ls :!: l) i) where
type SplitIxTy uId False (Elm (ls :!: l) i) = SplitIxTy uId (SameSid uId (Elm ls i)) (Elm ls i)
splitIxCol p b e = collectIx p (getElm e)
instance
( SplitIxCol uId (SameSid uId (Elm ls i)) (Elm ls i)
) => SplitIxCol uId True (Elm (ls :!: Split sId splitType (TwITbl m arr c j x)) i) where
type SplitIxTy uId True (Elm (ls :!: Split sId splitType (TwITbl m arr c j x)) i) = SplitIxTy uId (SameSid uId (Elm ls i)) (Elm ls i) :. i
splitIxCol p b (ElmSplitITbl _ _ i e ix) = collectIx p e :. ix
instance
( SplitIxCol uId (SameSid uId (Elm ls i)) (Elm ls i)
) => SplitIxCol uId True (Elm (ls :!: Split sId splitType (TwITblBt arr c j x mF mB r)) i) where
type SplitIxTy uId True (Elm (ls :!: Split sId splitType (TwITblBt arr c j x mF mB r)) i) = SplitIxTy uId (SameSid uId (Elm ls i)) (Elm ls i) :. i
splitIxCol p b (ElmSplitBtITbl _ _ i e ix) = collectIx p e :. ix
instance
( SplitIxCol uId (SameSid uId (Elm ls i)) (Elm ls i)
, Zconcat (SplitIxTy uId (SameSid uId (Elm ls i)) (Elm ls i)) (SplitIxTy uId (SameSid uId (TermSymbol a b)) (TermSymbol a b))
) => SplitIxCol uId True (Elm (ls :!: TermSymbol a b) i) where
type SplitIxTy uId True (Elm (ls :!: TermSymbol a b) i) = Zpp (SplitIxTy uId (SameSid uId (Elm ls i)) (Elm ls i)) (SplitIxTy uId (SameSid uId (TermSymbol a b)) (TermSymbol a b))
splitIxCol p b (ElmTS t i e) = collectIx p e `zconcat` ((error "ElmTS / splitIxCol") :: SplitIxTy uId (SameSid uId (TermSymbol a b)) (TermSymbol a b))