module DDC.Core.Flow.Transform.Schedule.Base
( elemBindOfSeriesBind
, elemBoundOfSeriesBound
, elemTypeOfSeriesType
, resultRateTypeOfSeriesType
, procTypeOfSeriesType
, rateTypeOfRateVecType
, elemTypeOfVectorType
, bufOfVectorName)
where
import DDC.Core.Flow.Compounds
import DDC.Core.Flow.Prim
import DDC.Core.Flow.Exp
elemBindOfSeriesBind :: BindF -> Maybe BindF
elemBindOfSeriesBind bSeries
| BName nSeries tSeries' <- bSeries
, nElem <- NameVarMod nSeries "elem"
, Just tElem <- elemTypeOfSeriesType tSeries'
= Just $ BName nElem tElem
| otherwise
= Nothing
elemBoundOfSeriesBound :: BoundF -> Maybe BoundF
elemBoundOfSeriesBound uSeries
| UName nSeries <- uSeries
, nElem <- NameVarMod nSeries "elem"
= Just $ UName nElem
| otherwise
= Nothing
elemTypeOfSeriesType :: TypeF -> Maybe TypeF
elemTypeOfSeriesType tSeries'
| Just (_tcSeries, [_tP, _tK, tE]) <- takeTyConApps tSeries'
= Just tE
| otherwise
= Nothing
resultRateTypeOfSeriesType :: TypeF -> Maybe TypeF
resultRateTypeOfSeriesType tSeries'
| isSeriesType tSeries'
, Just (_tcSeries, [_tP, tK, _tE]) <- takeTyConApps tSeries'
= Just tK
| otherwise
= Nothing
procTypeOfSeriesType :: TypeF -> Maybe TypeF
procTypeOfSeriesType tSeries'
| isSeriesType tSeries'
, Just (_tcSeries, [tP, _tK, _tE]) <- takeTyConApps tSeries'
= Just tP
| otherwise
= Nothing
rateTypeOfRateVecType :: TypeF -> Maybe TypeF
rateTypeOfRateVecType tV'
| isRateVecType tV'
, Just (_tcV, [tK, _tE]) <- takeTyConApps tV'
= Just tK
| otherwise
= Nothing
elemTypeOfVectorType :: TypeF -> Maybe TypeF
elemTypeOfVectorType tVector'
| Just (_tcVector, [tE]) <- takeTyConApps tVector'
= Just tE
| otherwise
= Nothing
bufOfVectorName :: BoundF -> BoundF
bufOfVectorName (UName n) = UName $ NameVarMod n "buf"
bufOfVectorName b = error (show b)