{-# LANGUAGE NondecreasingIndentation #-}
module Agda.TypeChecking.Rules.Data where
import Prelude hiding (null)
import Control.Monad
import Control.Monad.Trans
import Control.Monad.Trans.Maybe
import Data.Foldable (traverse_)
import Data.Maybe (fromMaybe, catMaybes, isJust)
import Data.Set (Set)
import qualified Data.Set as Set
import qualified Agda.Syntax.Abstract as A
import qualified Agda.Syntax.Concrete.Name as C
import Agda.Syntax.Abstract.Views (deepUnscope)
import Agda.Syntax.Internal
import Agda.Syntax.Common
import Agda.Syntax.Position
import qualified Agda.Syntax.Info as Info
import Agda.Syntax.Scope.Monad
import Agda.Syntax.Fixity
import {-# SOURCE #-} Agda.TypeChecking.CompiledClause.Compile
import Agda.TypeChecking.Monad
import Agda.TypeChecking.Monad.Builtin
import Agda.TypeChecking.Conversion
import Agda.TypeChecking.Substitute
import Agda.TypeChecking.Generalize
import Agda.TypeChecking.Implicit
import Agda.TypeChecking.MetaVars
import Agda.TypeChecking.Names
import Agda.TypeChecking.Reduce
import Agda.TypeChecking.Positivity.Occurrence (Occurrence(StrictPos))
import Agda.TypeChecking.Pretty
import Agda.TypeChecking.Primitive hiding (Nat)
import Agda.TypeChecking.Free
import Agda.TypeChecking.Forcing
import Agda.TypeChecking.Irrelevance
import Agda.TypeChecking.Telescope
import {-# SOURCE #-} Agda.TypeChecking.Rules.Term ( isType_ )
import Agda.Utils.Except
import Agda.Utils.List
import Agda.Utils.Maybe
import Agda.Utils.Monad
import Agda.Utils.Null
import qualified Agda.Utils.Pretty as P
import Agda.Utils.Size
import Agda.Utils.Impossible
checkDataDef :: A.DefInfo -> QName -> UniverseCheck -> A.DataDefParams -> [A.Constructor] -> TCM ()
checkDataDef :: DefInfo
-> QName
-> UniverseCheck
-> DataDefParams
-> [Constructor]
-> TCM ()
checkDataDef DefInfo
i QName
name UniverseCheck
uc (A.DataDefParams Set Name
gpars [LamBinding]
ps) [Constructor]
cs =
Call -> TCM () -> TCM ()
forall (tcm :: * -> *) a.
(MonadTCM tcm, ReadTCState tcm, MonadDebug tcm) =>
Call -> tcm a -> tcm a
traceCall (Range -> QName -> [LamBinding] -> [Constructor] -> Call
CheckDataDef (QName -> Range
forall t. HasRange t => t -> Range
getRange QName
name) QName
name [LamBinding]
ps [Constructor]
cs) (TCM () -> TCM ()) -> TCM () -> TCM ()
forall a b. (a -> b) -> a -> b
$ do
ModuleName -> TCM ()
addSection (QName -> ModuleName
qnameToMName QName
name)
Definition
def <- Definition -> TCMT IO Definition
forall (m :: * -> *).
(Functor m, HasConstInfo m, HasOptions m, ReadTCState m,
MonadTCEnv m, MonadDebug m) =>
Definition -> m Definition
instantiateDef (Definition -> TCMT IO Definition)
-> TCMT IO Definition -> TCMT IO Definition
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< QName -> TCMT IO Definition
forall (m :: * -> *). HasConstInfo m => QName -> m Definition
getConstInfo QName
name
Type
t <- Type -> TCMT IO Type
forall a (m :: * -> *).
(InstantiateFull a, MonadReduce m) =>
a -> m a
instantiateFull (Type -> TCMT IO Type) -> Type -> TCMT IO Type
forall a b. (a -> b) -> a -> b
$ Definition -> Type
defType Definition
def
let npars :: Int
npars =
case Definition -> Defn
theDef Definition
def of
DataOrRecSig Int
n -> Int
n
Defn
_ -> Int
forall a. HasCallStack => a
__IMPOSSIBLE__
let unTelV :: TelV Type -> Type
unTelV (TelV Tele (Dom Type)
tel Type
a) = Tele (Dom Type) -> Type -> Type
telePi Tele (Dom Type)
tel Type
a
Type
t <- TelV Type -> Type
unTelV (TelV Type -> Type) -> TCMT IO (TelV Type) -> TCMT IO Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Type -> TCMT IO (TelV Type)
forall (m :: * -> *).
(MonadReduce m, MonadAddContext m) =>
Type -> m (TelV Type)
telView Type
t
[Maybe Name]
parNames <- Set Name -> QName -> TCM [Maybe Name]
getGeneralizedParameters Set Name
gpars QName
name
Int
freeVars <- TCMT IO Int
forall (m :: * -> *). (Applicative m, MonadTCEnv m) => m Int
getContextSize
Defn
dataDef <- [Maybe Name]
-> Type -> (Tele (Dom Type) -> Type -> TCM Defn) -> TCM Defn
forall a.
[Maybe Name] -> Type -> (Tele (Dom Type) -> Type -> TCM a) -> TCM a
bindGeneralizedParameters [Maybe Name]
parNames Type
t ((Tele (Dom Type) -> Type -> TCM Defn) -> TCM Defn)
-> (Tele (Dom Type) -> Type -> TCM Defn) -> TCM Defn
forall a b. (a -> b) -> a -> b
$ \ Tele (Dom Type)
gtel Type
t0 ->
Int
-> [LamBinding]
-> Type
-> (Tele (Dom Type) -> Type -> TCM Defn)
-> TCM Defn
forall a.
Int
-> [LamBinding]
-> Type
-> (Tele (Dom Type) -> Type -> TCM a)
-> TCM a
bindParameters (Int
npars Int -> Int -> Int
forall a. Num a => a -> a -> a
- [Maybe Name] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Maybe Name]
parNames) [LamBinding]
ps Type
t0 ((Tele (Dom Type) -> Type -> TCM Defn) -> TCM Defn)
-> (Tele (Dom Type) -> Type -> TCM Defn) -> TCM Defn
forall a b. (a -> b) -> a -> b
$ \ Tele (Dom Type)
ptel Type
t0 -> do
let tel :: Tele (Dom Type)
tel = Tele (Dom Type) -> Tele (Dom Type) -> Tele (Dom Type)
forall t. Abstract t => Tele (Dom Type) -> t -> t
abstract Tele (Dom Type)
gtel Tele (Dom Type)
ptel
tel' :: Tele (Dom Type)
tel' = Dom Type -> Dom Type
forall a. Dom a -> Dom a
hideAndRelParams (Dom Type -> Dom Type) -> Tele (Dom Type) -> Tele (Dom Type)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Tele (Dom Type)
tel
let TelV Tele (Dom Type)
ixTel Type
s0 = Type -> TelV Type
telView' Type
t0
nofIxs :: Int
nofIxs = Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
ixTel
Sort
s <- TCMT IO Sort -> TCMT IO Sort
forall (m :: * -> *) a.
(MonadTCEnv m, HasOptions m, MonadDebug m) =>
m a -> m a
workOnTypes (TCMT IO Sort -> TCMT IO Sort) -> TCMT IO Sort -> TCMT IO Sort
forall a b. (a -> b) -> a -> b
$ do
Sort
s <- TCMT IO Sort
newSortMetaBelowInf
TCM () -> (TCErr -> TCM ()) -> TCM ()
forall a. TCM a -> (TCErr -> TCM a) -> TCM a
catchError_ (Tele (Dom Type) -> TCM () -> TCM ()
forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
addContext Tele (Dom Type)
ixTel (TCM () -> TCM ()) -> TCM () -> TCM ()
forall a b. (a -> b) -> a -> b
$ Type -> Type -> TCM ()
forall (m :: * -> *). MonadConversion m => Type -> Type -> m ()
equalType Type
s0 (Type -> TCM ()) -> Type -> TCM ()
forall a b. (a -> b) -> a -> b
$ Int -> Type -> Type
forall t a. Subst t a => Int -> a -> a
raise Int
nofIxs (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$ Sort -> Type
sort Sort
s) ((TCErr -> TCM ()) -> TCM ()) -> (TCErr -> TCM ()) -> TCM ()
forall a b. (a -> b) -> a -> b
$ \ TCErr
err ->
if (Int -> Bool) -> [Int] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Int -> Type -> Bool
forall a. Free a => Int -> a -> Bool
`freeIn` Type
s0) [Int
0..Int
nofIxs Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1] then TypeError -> TCM ()
forall (m :: * -> *) a.
(MonadTCEnv m, ReadTCState m, MonadError TCErr m) =>
TypeError -> m a
typeError (TypeError -> TCM ()) -> (Doc -> TypeError) -> Doc -> TCM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> TypeError
GenericDocError (Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
[TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *). Monad m => [m Doc] -> m Doc
fsep [ TCMT IO Doc
"The sort of" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> QName -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM QName
name
, TCMT IO Doc
"cannot depend on its indices in the type"
, Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Type
t0
]
else TCErr -> TCM ()
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError TCErr
err
Sort -> TCMT IO Sort
forall a (m :: * -> *). (Reduce a, MonadReduce m) => a -> m a
reduce Sort
s
let s' :: Sort
s' = case Sort
s of
Prop Level' Term
l -> Level' Term -> Sort
forall t. Level' t -> Sort' t
Type Level' Term
l
Sort
_ -> Sort
s
Bool -> TCM () -> TCM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (UniverseCheck
uc UniverseCheck -> UniverseCheck -> Bool
forall a. Eq a => a -> a -> Bool
== UniverseCheck
NoUniverseCheck) (TCM () -> TCM ()) -> TCM () -> TCM ()
forall a b. (a -> b) -> a -> b
$
TCMT IO Bool -> TCM () -> TCM ()
forall (m :: * -> *). Monad m => m Bool -> m () -> m ()
whenM TCMT IO Bool
forall (m :: * -> *). HasOptions m => m Bool
withoutKOption (TCM () -> TCM ()) -> TCM () -> TCM ()
forall a b. (a -> b) -> a -> b
$ Sort -> Tele (Dom Type) -> TCM ()
checkIndexSorts Sort
s' Tele (Dom Type)
ixTel
VerboseKey -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
VerboseKey -> Int -> TCMT IO Doc -> m ()
reportSDoc VerboseKey
"tc.data.sort" Int
20 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *). Monad m => [m Doc] -> m Doc
vcat
[ TCMT IO Doc
"checking datatype" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> QName -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM QName
name
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *). Monad m => [m Doc] -> m Doc
vcat
[ TCMT IO Doc
"type (parameters instantiated): " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Type
t0
, TCMT IO Doc
"type (full): " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Type
t
, TCMT IO Doc
"sort: " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Sort -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Sort
s
, TCMT IO Doc
"indices:" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> VerboseKey -> TCMT IO Doc
forall (m :: * -> *). Monad m => VerboseKey -> m Doc
text (Int -> VerboseKey
forall a. Show a => a -> VerboseKey
show Int
nofIxs)
, TCMT IO Doc
"gparams:" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> VerboseKey -> TCMT IO Doc
forall (m :: * -> *). Monad m => VerboseKey -> m Doc
text ([Maybe Name] -> VerboseKey
forall a. Show a => a -> VerboseKey
show [Maybe Name]
parNames)
, TCMT IO Doc
"params: " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> VerboseKey -> TCMT IO Doc
forall (m :: * -> *). Monad m => VerboseKey -> m Doc
text ([LamBinding] -> VerboseKey
forall a. Show a => a -> VerboseKey
show ([LamBinding] -> VerboseKey) -> [LamBinding] -> VerboseKey
forall a b. (a -> b) -> a -> b
$ [LamBinding] -> [LamBinding]
forall a. ExprLike a => a -> a
deepUnscope [LamBinding]
ps)
]
]
let npars :: Int
npars = Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
tel
let dataDef :: Defn
dataDef = Datatype :: Int
-> Int
-> Maybe Clause
-> [QName]
-> Sort
-> Maybe [QName]
-> IsAbstract
-> [QName]
-> Defn
Datatype
{ dataPars :: Int
dataPars = Int
npars
, dataIxs :: Int
dataIxs = Int
nofIxs
, dataClause :: Maybe Clause
dataClause = Maybe Clause
forall a. Maybe a
Nothing
, dataCons :: [QName]
dataCons = []
, dataSort :: Sort
dataSort = Sort
s
, dataAbstr :: IsAbstract
dataAbstr = DefInfo -> IsAbstract
forall t. DefInfo' t -> IsAbstract
Info.defAbstract DefInfo
i
, dataMutual :: Maybe [QName]
dataMutual = Maybe [QName]
forall a. Maybe a
Nothing
, dataPathCons :: [QName]
dataPathCons = []
}
Empty -> Int -> TCM () -> TCM ()
forall (m :: * -> *) a.
MonadAddContext m =>
Empty -> Int -> m a -> m a
escapeContext Empty
forall a. HasCallStack => a
__IMPOSSIBLE__ Int
npars (TCM () -> TCM ()) -> TCM () -> TCM ()
forall a b. (a -> b) -> a -> b
$ do
QName -> Definition -> TCM ()
addConstant QName
name (Definition -> TCM ()) -> Definition -> TCM ()
forall a b. (a -> b) -> a -> b
$
ArgInfo -> QName -> Type -> Defn -> Definition
defaultDefn ArgInfo
defaultArgInfo QName
name Type
t Defn
dataDef
[Maybe QName]
pathCons <- [Constructor]
-> (Constructor -> TCMT IO (Maybe QName)) -> TCMT IO [Maybe QName]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [Constructor]
cs ((Constructor -> TCMT IO (Maybe QName)) -> TCMT IO [Maybe QName])
-> (Constructor -> TCMT IO (Maybe QName)) -> TCMT IO [Maybe QName]
forall a b. (a -> b) -> a -> b
$ \ Constructor
c -> do
IsPathCons
isPathCons <- QName
-> UniverseCheck
-> Tele (Dom Type)
-> Int
-> Sort
-> Constructor
-> TCM IsPathCons
checkConstructor QName
name UniverseCheck
uc Tele (Dom Type)
tel' Int
nofIxs Sort
s Constructor
c
Maybe QName -> TCMT IO (Maybe QName)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe QName -> TCMT IO (Maybe QName))
-> Maybe QName -> TCMT IO (Maybe QName)
forall a b. (a -> b) -> a -> b
$ if IsPathCons
isPathCons IsPathCons -> IsPathCons -> Bool
forall a. Eq a => a -> a -> Bool
== IsPathCons
PathCons then QName -> Maybe QName
forall a. a -> Maybe a
Just (Constructor -> QName
A.axiomName Constructor
c) else Maybe QName
forall a. Maybe a
Nothing
Defn -> TCM Defn
forall (m :: * -> *) a. Monad m => a -> m a
return Defn
dataDef{ dataPathCons :: [QName]
dataPathCons = [Maybe QName] -> [QName]
forall a. [Maybe a] -> [a]
catMaybes [Maybe QName]
pathCons }
let s :: Sort
s = Defn -> Sort
dataSort Defn
dataDef
cons :: [QName]
cons = (Constructor -> QName) -> [Constructor] -> [QName]
forall a b. (a -> b) -> [a] -> [b]
map Constructor -> QName
A.axiomName [Constructor]
cs
QName -> Definition -> TCM ()
addConstant QName
name (Definition -> TCM ()) -> Definition -> TCM ()
forall a b. (a -> b) -> a -> b
$
ArgInfo -> QName -> Type -> Defn -> Definition
defaultDefn ArgInfo
defaultArgInfo QName
name Type
t (Defn -> Definition) -> Defn -> Definition
forall a b. (a -> b) -> a -> b
$
Defn
dataDef{ dataCons :: [QName]
dataCons = [QName]
cons }
forceSort :: Type -> TCM Sort
forceSort :: Type -> TCMT IO Sort
forceSort Type
t = Term -> TCMT IO Term
forall a (m :: * -> *). (Reduce a, MonadReduce m) => a -> m a
reduce (Type -> Term
forall t a. Type'' t a -> a
unEl Type
t) TCMT IO Term -> (Term -> TCMT IO Sort) -> TCMT IO Sort
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Sort Sort
s -> Sort -> TCMT IO Sort
forall (m :: * -> *) a. Monad m => a -> m a
return Sort
s
Term
_ -> do
Sort
s <- TCMT IO Sort
newSortMetaBelowInf
Type -> Type -> TCM ()
forall (m :: * -> *). MonadConversion m => Type -> Type -> m ()
equalType Type
t (Sort -> Type
sort Sort
s)
Sort -> TCMT IO Sort
forall (m :: * -> *) a. Monad m => a -> m a
return Sort
s
checkConstructor
:: QName
-> UniverseCheck
-> Telescope
-> Nat
-> Sort
-> A.Constructor
-> TCM IsPathCons
checkConstructor :: QName
-> UniverseCheck
-> Tele (Dom Type)
-> Int
-> Sort
-> Constructor
-> TCM IsPathCons
checkConstructor QName
d UniverseCheck
uc Tele (Dom Type)
tel Int
nofIxs Sort
s (A.ScopedDecl ScopeInfo
scope [Constructor
con]) = do
ScopeInfo -> TCM ()
setScope ScopeInfo
scope
QName
-> UniverseCheck
-> Tele (Dom Type)
-> Int
-> Sort
-> Constructor
-> TCM IsPathCons
checkConstructor QName
d UniverseCheck
uc Tele (Dom Type)
tel Int
nofIxs Sort
s Constructor
con
checkConstructor QName
d UniverseCheck
uc Tele (Dom Type)
tel Int
nofIxs Sort
s con :: Constructor
con@(A.Axiom Axiom
_ DefInfo
i ArgInfo
ai Maybe [Occurrence]
Nothing QName
c Expr
e) =
Call -> TCM IsPathCons -> TCM IsPathCons
forall (tcm :: * -> *) a.
(MonadTCM tcm, ReadTCState tcm, MonadDebug tcm) =>
Call -> tcm a -> tcm a
traceCall (QName -> Tele (Dom Type) -> Sort -> Constructor -> Call
CheckConstructor QName
d Tele (Dom Type)
tel Sort
s Constructor
con) (TCM IsPathCons -> TCM IsPathCons)
-> TCM IsPathCons -> TCM IsPathCons
forall a b. (a -> b) -> a -> b
$ do
QName -> Expr -> TCM ()
forall (m :: * -> *) a a.
(MonadDebug m, PrettyTCM a, PrettyTCM a) =>
a -> a -> m ()
debugEnter QName
c Expr
e
case ArgInfo -> Relevance
forall a. LensRelevance a => a -> Relevance
getRelevance ArgInfo
ai of
Relevance
Relevant -> () -> TCM ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Relevance
Irrelevant -> TypeError -> TCM ()
forall (m :: * -> *) a.
(MonadTCEnv m, ReadTCState m, MonadError TCErr m) =>
TypeError -> m a
typeError (TypeError -> TCM ()) -> TypeError -> TCM ()
forall a b. (a -> b) -> a -> b
$ VerboseKey -> TypeError
GenericError (VerboseKey -> TypeError) -> VerboseKey -> TypeError
forall a b. (a -> b) -> a -> b
$ VerboseKey
"Irrelevant constructors are not supported"
Relevance
NonStrict -> TypeError -> TCM ()
forall (m :: * -> *) a.
(MonadTCEnv m, ReadTCState m, MonadError TCErr m) =>
TypeError -> m a
typeError (TypeError -> TCM ()) -> TypeError -> TCM ()
forall a b. (a -> b) -> a -> b
$ VerboseKey -> TypeError
GenericError (VerboseKey -> TypeError) -> VerboseKey -> TypeError
forall a b. (a -> b) -> a -> b
$ VerboseKey
"Shape-irrelevant constructors are not supported"
case ArgInfo -> Quantity
forall a. LensQuantity a => a -> Quantity
getQuantity ArgInfo
ai of
Quantityω{} -> () -> TCM ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Quantity0{} -> TypeError -> TCM ()
forall (m :: * -> *) a.
(MonadTCEnv m, ReadTCState m, MonadError TCErr m) =>
TypeError -> m a
typeError (TypeError -> TCM ()) -> TypeError -> TCM ()
forall a b. (a -> b) -> a -> b
$ VerboseKey -> TypeError
GenericError (VerboseKey -> TypeError) -> VerboseKey -> TypeError
forall a b. (a -> b) -> a -> b
$ VerboseKey
"Erased constructors are not supported"
Quantity1{} -> TypeError -> TCM ()
forall (m :: * -> *) a.
(MonadTCEnv m, ReadTCState m, MonadError TCErr m) =>
TypeError -> m a
typeError (TypeError -> TCM ()) -> TypeError -> TCM ()
forall a b. (a -> b) -> a -> b
$ VerboseKey -> TypeError
GenericError (VerboseKey -> TypeError) -> VerboseKey -> TypeError
forall a b. (a -> b) -> a -> b
$ VerboseKey
"Quantity-restricted constructors are not supported"
(Type
t, IsPathCons
isPathCons) <- Expr -> QName -> TCMT IO (Type, IsPathCons)
checkConstructorType Expr
e QName
d
[IsForced]
forcedArgs <- if IsPathCons
isPathCons IsPathCons -> IsPathCons -> Bool
forall a. Eq a => a -> a -> Bool
== IsPathCons
PointCons
then QName -> Type -> TCM [IsForced]
computeForcingAnnotations QName
c Type
t
else [IsForced] -> TCM [IsForced]
forall (m :: * -> *) a. Monad m => a -> m a
return []
Sort -> TCM ()
forall (m :: * -> *) a. (MonadDebug m, PrettyTCM a) => a -> m ()
debugFitsIn Sort
s
let s' :: Sort
s' = case Sort
s of
Prop Level' Term
l -> Level' Term -> Sort
forall t. Level' t -> Sort' t
Type Level' Term
l
Sort
_ -> Sort
s
Int
arity <- Call -> TCMT IO Int -> TCMT IO Int
forall (tcm :: * -> *) a.
(MonadTCM tcm, ReadTCState tcm, MonadDebug tcm) =>
Call -> tcm a -> tcm a
traceCall (QName -> Type -> Sort -> Call
CheckConstructorFitsIn QName
c Type
t Sort
s') (TCMT IO Int -> TCMT IO Int) -> TCMT IO Int -> TCMT IO Int
forall a b. (a -> b) -> a -> b
$ UniverseCheck -> [IsForced] -> Type -> Sort -> TCMT IO Int
fitsIn UniverseCheck
uc [IsForced]
forcedArgs Type
t Sort
s'
Sort
s <- Sort -> TCMT IO Sort
forall a (m :: * -> *). (Reduce a, MonadReduce m) => a -> m a
reduce Sort
s
QName -> Type -> TCM ()
forall (m :: * -> *) a a.
(MonadDebug m, PrettyTCM a, PrettyTCM a) =>
a -> a -> m ()
debugAdd QName
c Type
t
(TelV Tele (Dom Type)
fields Type
_, Boundary
boundary) <- Int -> Type -> TCMT IO (TelV Type, Boundary)
forall (m :: * -> *).
(MonadReduce m, HasBuiltins m) =>
Int -> Type -> m (TelV Type, Boundary)
telViewUpToPathBoundaryP (-Int
1) Type
t
Tele (Dom Type)
params <- TCMT IO (Tele (Dom Type))
forall (m :: * -> *).
(Applicative m, MonadTCEnv m) =>
m (Tele (Dom Type))
getContextTelescope
(ConHead
con, CompKit
comp, Maybe [QName]
projNames) <- if Int
nofIxs Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
0 Bool -> Bool -> Bool
|| (DefInfo -> IsAbstract
forall t. DefInfo' t -> IsAbstract
Info.defAbstract DefInfo
i IsAbstract -> IsAbstract -> Bool
forall a. Eq a => a -> a -> Bool
== IsAbstract
AbstractDef)
then (ConHead, CompKit, Maybe [QName])
-> TCMT IO (ConHead, CompKit, Maybe [QName])
forall (m :: * -> *) a. Monad m => a -> m a
return (QName -> Induction -> [Arg QName] -> ConHead
ConHead QName
c Induction
Inductive [], CompKit
emptyCompKit, Maybe [QName]
forall a. Maybe a
Nothing)
else do
[QName]
names <- [Int] -> (Int -> TCMT IO QName) -> TCMT IO [QName]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [Int
0 .. Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
fields Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1] ((Int -> TCMT IO QName) -> TCMT IO [QName])
-> (Int -> TCMT IO QName) -> TCMT IO [QName]
forall a b. (a -> b) -> a -> b
$ \ Int
i ->
VerboseKey -> TCMT IO QName
freshAbstractQName'_ (VerboseKey -> TCMT IO QName) -> VerboseKey -> TCMT IO QName
forall a b. (a -> b) -> a -> b
$ Name -> VerboseKey
forall a. Pretty a => a -> VerboseKey
P.prettyShow (QName -> Name
A.qnameName QName
c) VerboseKey -> VerboseKey -> VerboseKey
forall a. [a] -> [a] -> [a]
++ VerboseKey
"-" VerboseKey -> VerboseKey -> VerboseKey
forall a. [a] -> [a] -> [a]
++ Int -> VerboseKey
forall a. Show a => a -> VerboseKey
show Int
i
let dataT :: Type
dataT = Sort -> Term -> Type
forall t a. Sort' t -> a -> Type'' t a
El Sort
s (Term -> Type) -> Term -> Type
forall a b. (a -> b) -> a -> b
$ QName -> Elims -> Term
Def QName
d (Elims -> Term) -> Elims -> Term
forall a b. (a -> b) -> a -> b
$ (Arg Term -> Elim' Term) -> [Arg Term] -> Elims
forall a b. (a -> b) -> [a] -> [b]
map Arg Term -> Elim' Term
forall a. Arg a -> Elim' a
Apply ([Arg Term] -> Elims) -> [Arg Term] -> Elims
forall a b. (a -> b) -> a -> b
$ Tele (Dom Type) -> [Arg Term]
forall a t. DeBruijn a => Tele (Dom t) -> [Arg a]
teleArgs Tele (Dom Type)
params
VerboseKey -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
VerboseKey -> Int -> TCMT IO Doc -> m ()
reportSDoc VerboseKey
"tc.data.con.comp" Int
5 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc -> TCMT IO Doc
forall (tcm :: * -> *) a.
(MonadTCEnv tcm, ReadTCState tcm) =>
tcm a -> tcm a
inTopContext (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *). Monad m => [m Doc] -> m Doc
vcat ([TCMT IO Doc] -> TCMT IO Doc) -> [TCMT IO Doc] -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$
[ TCMT IO Doc
"params =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Tele (Dom Type) -> TCMT IO Doc
forall (m :: * -> *) a. (Monad m, Pretty a) => a -> m Doc
pretty Tele (Dom Type)
params
, TCMT IO Doc
"dataT =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Type -> TCMT IO Doc
forall (m :: * -> *) a. (Monad m, Pretty a) => a -> m Doc
pretty Type
dataT
, TCMT IO Doc
"fields =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Tele (Dom Type) -> TCMT IO Doc
forall (m :: * -> *) a. (Monad m, Pretty a) => a -> m Doc
pretty Tele (Dom Type)
fields
, TCMT IO Doc
"names =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> [QName] -> TCMT IO Doc
forall (m :: * -> *) a. (Monad m, Pretty a) => a -> m Doc
pretty [QName]
names
]
let con :: ConHead
con = QName -> Induction -> [Arg QName] -> ConHead
ConHead QName
c Induction
Inductive ([Arg QName] -> ConHead) -> [Arg QName] -> ConHead
forall a b. (a -> b) -> a -> b
$ (QName -> Arg (VerboseKey, Type) -> Arg QName)
-> [QName] -> [Arg (VerboseKey, Type)] -> [Arg QName]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith QName -> Arg (VerboseKey, Type) -> Arg QName
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
(<$) [QName]
names ([Arg (VerboseKey, Type)] -> [Arg QName])
-> [Arg (VerboseKey, Type)] -> [Arg QName]
forall a b. (a -> b) -> a -> b
$ (Dom' Term (VerboseKey, Type) -> Arg (VerboseKey, Type))
-> [Dom' Term (VerboseKey, Type)] -> [Arg (VerboseKey, Type)]
forall a b. (a -> b) -> [a] -> [b]
map Dom' Term (VerboseKey, Type) -> Arg (VerboseKey, Type)
forall t a. Dom' t a -> Arg a
argFromDom ([Dom' Term (VerboseKey, Type)] -> [Arg (VerboseKey, Type)])
-> [Dom' Term (VerboseKey, Type)] -> [Arg (VerboseKey, Type)]
forall a b. (a -> b) -> a -> b
$ Tele (Dom Type) -> [Dom' Term (VerboseKey, Type)]
forall t. Tele (Dom t) -> [Dom (VerboseKey, t)]
telToList Tele (Dom Type)
fields
QName
-> ConHead
-> Tele (Dom Type)
-> [QName]
-> Tele (Dom Type)
-> Type
-> TCM ()
defineProjections QName
d ConHead
con Tele (Dom Type)
params [QName]
names Tele (Dom Type)
fields Type
dataT
CompKit
comp <- TCMT IO CompKit -> TCMT IO CompKit
forall (tcm :: * -> *) a.
(MonadTCEnv tcm, ReadTCState tcm) =>
tcm a -> tcm a
inTopContext (TCMT IO CompKit -> TCMT IO CompKit)
-> TCMT IO CompKit -> TCMT IO CompKit
forall a b. (a -> b) -> a -> b
$ QName
-> ConHead
-> Tele (Dom Type)
-> [QName]
-> Tele (Dom Type)
-> Type
-> Boundary
-> TCMT IO CompKit
defineCompData QName
d ConHead
con Tele (Dom Type)
params [QName]
names Tele (Dom Type)
fields Type
dataT Boundary
boundary
(ConHead, CompKit, Maybe [QName])
-> TCMT IO (ConHead, CompKit, Maybe [QName])
forall (m :: * -> *) a. Monad m => a -> m a
return (ConHead
con, CompKit
comp, [QName] -> Maybe [QName]
forall a. a -> Maybe a
Just [QName]
names)
Empty -> Int -> TCM () -> TCM ()
forall (m :: * -> *) a.
MonadAddContext m =>
Empty -> Int -> m a -> m a
escapeContext Empty
forall a. HasCallStack => a
__IMPOSSIBLE__ (Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
tel) (TCM () -> TCM ()) -> TCM () -> TCM ()
forall a b. (a -> b) -> a -> b
$ do
QName -> Definition -> TCM ()
addConstant QName
c (Definition -> TCM ()) -> Definition -> TCM ()
forall a b. (a -> b) -> a -> b
$
ArgInfo -> QName -> Type -> Defn -> Definition
defaultDefn ArgInfo
defaultArgInfo QName
c (Tele (Dom Type) -> Type -> Type
telePi Tele (Dom Type)
tel Type
t) (Defn -> Definition) -> Defn -> Definition
forall a b. (a -> b) -> a -> b
$ Constructor :: Int
-> Int
-> ConHead
-> QName
-> IsAbstract
-> Induction
-> CompKit
-> Maybe [QName]
-> [IsForced]
-> Maybe [Bool]
-> Defn
Constructor
{ conPars :: Int
conPars = Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
tel
, conArity :: Int
conArity = Int
arity
, conSrcCon :: ConHead
conSrcCon = ConHead
con
, conData :: QName
conData = QName
d
, conAbstr :: IsAbstract
conAbstr = DefInfo -> IsAbstract
forall t. DefInfo' t -> IsAbstract
Info.defAbstract DefInfo
i
, conInd :: Induction
conInd = Induction
Inductive
, conComp :: CompKit
conComp = CompKit
comp
, conProj :: Maybe [QName]
conProj = Maybe [QName]
projNames
, conForced :: [IsForced]
conForced = [IsForced]
forcedArgs
, conErased :: Maybe [Bool]
conErased = Maybe [Bool]
forall a. Maybe a
Nothing
}
case DefInfo -> IsInstance
forall t. DefInfo' t -> IsInstance
Info.defInstance DefInfo
i of
InstanceDef Range
_r -> QName -> TCM () -> TCM ()
forall (tcm :: * -> *) x a.
(MonadTCM tcm, ReadTCState tcm, MonadDebug tcm, HasRange x) =>
x -> tcm a -> tcm a
setCurrentRange QName
c (TCM () -> TCM ()) -> TCM () -> TCM ()
forall a b. (a -> b) -> a -> b
$ do
QName -> Type -> TCM ()
addTypedInstance QName
c Type
t
IsInstance
NotInstanceDef -> () -> TCM ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
IsPathCons -> TCM IsPathCons
forall (m :: * -> *) a. Monad m => a -> m a
return IsPathCons
isPathCons
where
checkConstructorType :: Expr -> QName -> TCMT IO (Type, IsPathCons)
checkConstructorType (A.ScopedExpr ScopeInfo
s Expr
e) QName
d = ScopeInfo
-> TCMT IO (Type, IsPathCons) -> TCMT IO (Type, IsPathCons)
forall (m :: * -> *) a. ReadTCState m => ScopeInfo -> m a -> m a
withScope_ ScopeInfo
s (TCMT IO (Type, IsPathCons) -> TCMT IO (Type, IsPathCons))
-> TCMT IO (Type, IsPathCons) -> TCMT IO (Type, IsPathCons)
forall a b. (a -> b) -> a -> b
$ Expr -> QName -> TCMT IO (Type, IsPathCons)
checkConstructorType Expr
e QName
d
checkConstructorType Expr
e QName
d = do
let check :: Int -> Expr -> TCMT IO (Type, IsPathCons)
check Int
k Expr
e = do
Type
t <- TCMT IO Type -> TCMT IO Type
forall (m :: * -> *) a.
(MonadTCEnv m, HasOptions m, MonadDebug m) =>
m a -> m a
workOnTypes (TCMT IO Type -> TCMT IO Type) -> TCMT IO Type -> TCMT IO Type
forall a b. (a -> b) -> a -> b
$ Expr -> TCMT IO Type
isType_ Expr
e
Int
n <- TCMT IO Int
forall (m :: * -> *). (Applicative m, MonadTCEnv m) => m Int
getContextSize
Type -> QName -> Int -> TCM ()
forall (m :: * -> *) a a a.
(MonadDebug m, PrettyTCM a, PrettyTCM a, Show a) =>
a -> a -> a -> m ()
debugEndsIn Type
t QName
d (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
k)
IsPathCons
isPathCons <- Int -> Int -> Type -> QName -> TCM IsPathCons
constructs (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
k) Int
k Type
t QName
d
(Type, IsPathCons) -> TCMT IO (Type, IsPathCons)
forall (m :: * -> *) a. Monad m => a -> m a
return (Type
t, IsPathCons
isPathCons)
case Expr
e of
A.Generalized Set QName
s Expr
e -> do
([Maybe QName]
_, Type
t, IsPathCons
isPathCons) <- Set QName
-> TCMT IO (Type, IsPathCons)
-> TCM ([Maybe QName], Type, IsPathCons)
forall a.
Set QName -> TCM (Type, a) -> TCM ([Maybe QName], Type, a)
generalizeType' Set QName
s (Int -> Expr -> TCMT IO (Type, IsPathCons)
check Int
1 Expr
e)
(Type, IsPathCons) -> TCMT IO (Type, IsPathCons)
forall (m :: * -> *) a. Monad m => a -> m a
return (Type
t, IsPathCons
isPathCons)
Expr
_ -> Int -> Expr -> TCMT IO (Type, IsPathCons)
check Int
0 Expr
e
debugEnter :: a -> a -> m ()
debugEnter a
c a
e =
VerboseKey -> Int -> TCMT IO Doc -> m ()
forall (m :: * -> *).
MonadDebug m =>
VerboseKey -> Int -> TCMT IO Doc -> m ()
reportSDoc VerboseKey
"tc.data.con" Int
5 (TCMT IO Doc -> m ()) -> TCMT IO Doc -> m ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *). Monad m => [m Doc] -> m Doc
vcat
[ TCMT IO Doc
"checking constructor" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> a -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM a
c TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCMT IO Doc
":" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> a -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM a
e
]
debugEndsIn :: a -> a -> a -> m ()
debugEndsIn a
t a
d a
n =
VerboseKey -> Int -> TCMT IO Doc -> m ()
forall (m :: * -> *).
MonadDebug m =>
VerboseKey -> Int -> TCMT IO Doc -> m ()
reportSDoc VerboseKey
"tc.data.con" Int
15 (TCMT IO Doc -> m ()) -> TCMT IO Doc -> m ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *). Monad m => [m Doc] -> m Doc
vcat
[ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *). Monad m => [m Doc] -> m Doc
sep [ TCMT IO Doc
"checking that"
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ a -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM a
t
, TCMT IO Doc
"ends in" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> a -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM a
d
]
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"nofPars =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> VerboseKey -> TCMT IO Doc
forall (m :: * -> *). Monad m => VerboseKey -> m Doc
text (a -> VerboseKey
forall a. Show a => a -> VerboseKey
show a
n)
]
debugFitsIn :: a -> m ()
debugFitsIn a
s =
VerboseKey -> Int -> TCMT IO Doc -> m ()
forall (m :: * -> *).
MonadDebug m =>
VerboseKey -> Int -> TCMT IO Doc -> m ()
reportSDoc VerboseKey
"tc.data.con" Int
15 (TCMT IO Doc -> m ()) -> TCMT IO Doc -> m ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *). Monad m => [m Doc] -> m Doc
sep
[ TCMT IO Doc
"checking that the type fits in"
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ a -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM a
s
]
debugAdd :: a -> a -> m ()
debugAdd a
c a
t =
VerboseKey -> Int -> TCMT IO Doc -> m ()
forall (m :: * -> *).
MonadDebug m =>
VerboseKey -> Int -> TCMT IO Doc -> m ()
reportSDoc VerboseKey
"tc.data.con" Int
5 (TCMT IO Doc -> m ()) -> TCMT IO Doc -> m ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *). Monad m => [m Doc] -> m Doc
vcat
[ TCMT IO Doc
"adding constructor" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> a -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM a
c TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCMT IO Doc
":" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> a -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM a
t
]
checkConstructor QName
_ UniverseCheck
_ Tele (Dom Type)
_ Int
_ Sort
_ Constructor
_ = TCM IsPathCons
forall a. HasCallStack => a
__IMPOSSIBLE__
defineCompData :: QName
-> ConHead
-> Telescope
-> [QName]
-> Telescope
-> Type
-> Boundary
-> TCM CompKit
defineCompData :: QName
-> ConHead
-> Tele (Dom Type)
-> [QName]
-> Tele (Dom Type)
-> Type
-> Boundary
-> TCMT IO CompKit
defineCompData QName
d ConHead
con Tele (Dom Type)
params [QName]
names Tele (Dom Type)
fsT Type
t Boundary
boundary = do
[Maybe Term]
required <- (VerboseKey -> TCMT IO (Maybe Term))
-> [VerboseKey] -> TCMT IO [Maybe Term]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM VerboseKey -> TCMT IO (Maybe Term)
forall (m :: * -> *). HasBuiltins m => VerboseKey -> m (Maybe Term)
getTerm'
[ VerboseKey
builtinInterval
, VerboseKey
builtinIZero
, VerboseKey
builtinIOne
, VerboseKey
builtinIMin
, VerboseKey
builtinIMax
, VerboseKey
builtinINeg
, VerboseKey
builtinPOr
, VerboseKey
builtinItIsOne
]
if Bool -> Bool
not ((Maybe Term -> Bool) -> [Maybe Term] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Maybe Term -> Bool
forall a. Maybe a -> Bool
isJust [Maybe Term]
required) then CompKit -> TCMT IO CompKit
forall (m :: * -> *) a. Monad m => a -> m a
return (CompKit -> TCMT IO CompKit) -> CompKit -> TCMT IO CompKit
forall a b. (a -> b) -> a -> b
$ CompKit
emptyCompKit else do
Maybe QName
hcomp <- Bool
-> [VerboseKey] -> TCMT IO (Maybe QName) -> TCMT IO (Maybe QName)
forall (m :: * -> *) (t :: * -> *) a.
(Traversable t, HasBuiltins m) =>
Bool -> t VerboseKey -> m (Maybe a) -> m (Maybe a)
whenDefined (Boundary -> Bool
forall a. Null a => a -> Bool
null Boundary
boundary) [VerboseKey
builtinHComp,VerboseKey
builtinTrans] (TranspOrHComp
-> QName
-> ConHead
-> Tele (Dom Type)
-> [QName]
-> Tele (Dom Type)
-> Type
-> Boundary
-> TCMT IO (Maybe QName)
defineTranspOrHCompD TranspOrHComp
DoHComp QName
d ConHead
con Tele (Dom Type)
params [QName]
names Tele (Dom Type)
fsT Type
t Boundary
boundary)
Maybe QName
transp <- Bool
-> [VerboseKey] -> TCMT IO (Maybe QName) -> TCMT IO (Maybe QName)
forall (m :: * -> *) (t :: * -> *) a.
(Traversable t, HasBuiltins m) =>
Bool -> t VerboseKey -> m (Maybe a) -> m (Maybe a)
whenDefined Bool
True [VerboseKey
builtinTrans] (TranspOrHComp
-> QName
-> ConHead
-> Tele (Dom Type)
-> [QName]
-> Tele (Dom Type)
-> Type
-> Boundary
-> TCMT IO (Maybe QName)
defineTranspOrHCompD TranspOrHComp
DoTransp QName
d ConHead
con Tele (Dom Type)
params [QName]
names Tele (Dom Type)
fsT Type
t Boundary
boundary)
CompKit -> TCMT IO CompKit
forall (m :: * -> *) a. Monad m => a -> m a
return (CompKit -> TCMT IO CompKit) -> CompKit -> TCMT IO CompKit
forall a b. (a -> b) -> a -> b
$ CompKit :: Maybe QName -> Maybe QName -> CompKit
CompKit
{ nameOfTransp :: Maybe QName
nameOfTransp = Maybe QName
transp
, nameOfHComp :: Maybe QName
nameOfHComp = Maybe QName
hcomp
}
where
sub :: a -> Substitution' Term
sub a
tel = [Term] -> Substitution' Term
forall a. DeBruijn a => [a] -> Substitution' a
parallelS [ Int -> Term
var Int
n Term -> [Arg Term] -> Term
forall t. Apply t => t -> [Arg Term] -> t
`apply` [ArgInfo -> Term -> Arg Term
forall e. ArgInfo -> e -> Arg e
Arg ArgInfo
defaultArgInfo (Term -> Arg Term) -> Term -> Arg Term
forall a b. (a -> b) -> a -> b
$ Int -> Term
var Int
0] | Int
n <- [Int
1..a -> Int
forall a. Sized a => a -> Int
size a
tel] ]
withArgInfo :: Tele (Dom t) -> [e] -> [Arg e]
withArgInfo Tele (Dom t)
tel = (ArgInfo -> e -> Arg e) -> [ArgInfo] -> [e] -> [Arg e]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith ArgInfo -> e -> Arg e
forall e. ArgInfo -> e -> Arg e
Arg ((Dom' Term (VerboseKey, t) -> ArgInfo)
-> [Dom' Term (VerboseKey, t)] -> [ArgInfo]
forall a b. (a -> b) -> [a] -> [b]
map Dom' Term (VerboseKey, t) -> ArgInfo
forall t e. Dom' t e -> ArgInfo
domInfo ([Dom' Term (VerboseKey, t)] -> [ArgInfo])
-> (Tele (Dom t) -> [Dom' Term (VerboseKey, t)])
-> Tele (Dom t)
-> [ArgInfo]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tele (Dom t) -> [Dom' Term (VerboseKey, t)]
forall t. Tele (Dom t) -> [Dom (VerboseKey, t)]
telToList (Tele (Dom t) -> [ArgInfo]) -> Tele (Dom t) -> [ArgInfo]
forall a b. (a -> b) -> a -> b
$ Tele (Dom t)
tel)
defineTranspOrHCompD :: TranspOrHComp
-> QName
-> ConHead
-> Tele (Dom Type)
-> [QName]
-> Tele (Dom Type)
-> Type
-> Boundary
-> TCMT IO (Maybe QName)
defineTranspOrHCompD TranspOrHComp
cmd QName
d ConHead
con Tele (Dom Type)
params [QName]
names Tele (Dom Type)
fsT Type
t Boundary
boundary = do
let project :: Term -> QName -> Term
project = (\ Term
t QName
p -> Term -> [Arg Term] -> Term
forall t. Apply t => t -> [Arg Term] -> t
apply (QName -> Elims -> Term
Def QName
p []) [Term -> Arg Term
forall e. e -> Arg e
argN Term
t])
Maybe
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
stuff <- TranspOrHComp
-> Maybe Term
-> (Term -> QName -> Term)
-> QName
-> Tele (Dom Type)
-> Tele (Dom Type)
-> [Arg QName]
-> Type
-> TCM
(Maybe
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term))
defineTranspOrHCompForFields TranspOrHComp
cmd
(Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ Boundary -> Bool
forall a. Null a => a -> Bool
null Boundary
boundary) Maybe () -> Maybe Term -> Maybe Term
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (Term -> Maybe Term
forall a. a -> Maybe a
Just (Term -> Maybe Term) -> Term -> Maybe Term
forall a b. (a -> b) -> a -> b
$ ConHead -> ConInfo -> Elims -> Term
Con ConHead
con ConInfo
ConOSystem (Elims -> Term) -> Elims -> Term
forall a b. (a -> b) -> a -> b
$ Tele (Dom Type) -> Boundary -> Elims
forall a.
DeBruijn a =>
Tele (Dom Type) -> Boundary' (a, a) -> [Elim' a]
teleElims Tele (Dom Type)
fsT Boundary
boundary))
Term -> QName -> Term
project QName
d Tele (Dom Type)
params Tele (Dom Type)
fsT ((QName -> Arg QName) -> [QName] -> [Arg QName]
forall a b. (a -> b) -> [a] -> [b]
map QName -> Arg QName
forall e. e -> Arg e
argN [QName]
names) Type
t
Maybe
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
-> TCMT IO (Maybe QName)
-> (((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
-> TCMT IO (Maybe QName))
-> TCMT IO (Maybe QName)
forall a b. Maybe a -> b -> (a -> b) -> b
caseMaybe Maybe
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
stuff (Maybe QName -> TCMT IO (Maybe QName)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe QName
forall a. Maybe a
Nothing) ((((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
-> TCMT IO (Maybe QName))
-> TCMT IO (Maybe QName))
-> (((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
-> TCMT IO (Maybe QName))
-> TCMT IO (Maybe QName)
forall a b. (a -> b) -> a -> b
$ \ ((QName
theName, Tele (Dom Type)
gamma , Type
ty, [Dom Type]
_cl_types , [Term]
bodies), Substitution' Term
theSub) -> do
Term
iz <- TCMT IO Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primIZero
Term
body <- do
case TranspOrHComp
cmd of
TranspOrHComp
DoHComp -> Term -> TCMT IO Term
forall (m :: * -> *) a. Monad m => a -> m a
return (Term -> TCMT IO Term) -> Term -> TCMT IO Term
forall a b. (a -> b) -> a -> b
$ ConHead -> ConInfo -> Elims -> Term
Con ConHead
con ConInfo
ConOSystem ((Arg Term -> Elim' Term) -> [Arg Term] -> Elims
forall a b. (a -> b) -> [a] -> [b]
map Arg Term -> Elim' Term
forall a. Arg a -> Elim' a
Apply ([Arg Term] -> Elims) -> [Arg Term] -> Elims
forall a b. (a -> b) -> a -> b
$ Tele (Dom Type) -> [Term] -> [Arg Term]
forall t e. Tele (Dom t) -> [e] -> [Arg e]
withArgInfo Tele (Dom Type)
fsT [Term]
bodies)
TranspOrHComp
DoTransp | Boundary -> Bool
forall a. Null a => a -> Bool
null Boundary
boundary -> Term -> TCMT IO Term
forall (m :: * -> *) a. Monad m => a -> m a
return (Term -> TCMT IO Term) -> Term -> TCMT IO Term
forall a b. (a -> b) -> a -> b
$ ConHead -> ConInfo -> Elims -> Term
Con ConHead
con ConInfo
ConOSystem ((Arg Term -> Elim' Term) -> [Arg Term] -> Elims
forall a b. (a -> b) -> [a] -> [b]
map Arg Term -> Elim' Term
forall a. Arg a -> Elim' a
Apply ([Arg Term] -> Elims) -> [Arg Term] -> Elims
forall a b. (a -> b) -> a -> b
$ Tele (Dom Type) -> [Term] -> [Arg Term]
forall t e. Tele (Dom t) -> [e] -> [Arg e]
withArgInfo Tele (Dom Type)
fsT [Term]
bodies)
| Bool
otherwise -> do
Term
io <- TCMT IO Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primIOne
Term
tIMax <- TCMT IO Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primIMax
Term
tIMin <- TCMT IO Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primIMin
Term
tINeg <- TCMT IO Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primINeg
Term
tPOr <- Term -> Maybe Term -> Term
forall a. a -> Maybe a -> a
fromMaybe Term
forall a. HasCallStack => a
__IMPOSSIBLE__ (Maybe Term -> Term) -> TCMT IO (Maybe Term) -> TCMT IO Term
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> VerboseKey -> TCMT IO (Maybe Term)
forall (m :: * -> *). HasBuiltins m => VerboseKey -> m (Maybe Term)
getTerm' VerboseKey
builtinPOr
Term
tHComp <- TCMT IO Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primHComp
let
u :: Term
u = ConHead -> ConInfo -> Elims -> Term
Con ConHead
con ConInfo
ConOSystem (Elims -> Term) -> Elims -> Term
forall a b. (a -> b) -> a -> b
$ Tele (Dom Type) -> Boundary -> Elims
forall a.
DeBruijn a =>
Tele (Dom Type) -> Boundary' (a, a) -> [Elim' a]
teleElims Tele (Dom Type)
fsT Boundary
boundary
the_u :: Term
the_u = Int -> Substitution' Term -> Substitution' Term
forall a. Int -> Substitution' a -> Substitution' a
liftS (Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
fsT) Substitution' Term
d0 Substitution' Term -> Term -> Term
forall t a. Subst t a => Substitution' t -> a -> a
`applySubst` Term
u
where
d0 :: Substitution
d0 :: Substitution' Term
d0 = Int -> Substitution' Term -> Substitution' Term
forall a. Int -> Substitution' a -> Substitution' a
wkS Int
1
(Term -> Substitution' Term -> Substitution' Term
forall a. DeBruijn a => a -> Substitution' a -> Substitution' a
consS Term
iz Substitution' Term
forall a. Substitution' a
IdS Substitution' Term -> Substitution' Term -> Substitution' Term
forall a.
Subst a a =>
Substitution' a -> Substitution' a -> Substitution' a
`composeS` Tele (Dom Type) -> Substitution' Term
forall a. Sized a => a -> Substitution' Term
sub Tele (Dom Type)
params)
the_phi :: Term
the_phi = Int -> Term -> Term
forall t a. Subst t a => Int -> a -> a
raise (Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
fsT) (Term -> Term) -> Term -> Term
forall a b. (a -> b) -> a -> b
$ Int -> Term
var Int
0
sigma :: Substitution' Term
sigma = [Term] -> [Term]
forall a. [a] -> [a]
reverse [Term]
bodies [Term] -> Substitution' Term -> Substitution' Term
forall a. DeBruijn a => [a] -> Substitution' a -> Substitution' a
++# Substitution' Term
d1
where
d1 :: Substitution
d1 :: Substitution' Term
d1 = Int -> Substitution' Term -> Substitution' Term
forall a. Int -> Substitution' a -> Substitution' a
wkS (Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
gamma Int -> Int -> Int
forall a. Num a => a -> a -> a
- Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
params)
(Term -> Substitution' Term -> Substitution' Term
forall a. DeBruijn a => a -> Substitution' a -> Substitution' a
consS Term
io Substitution' Term
forall a. Substitution' a
IdS Substitution' Term -> Substitution' Term -> Substitution' Term
forall a.
Subst a a =>
Substitution' a -> Substitution' a -> Substitution' a
`composeS` Tele (Dom Type) -> Substitution' Term
forall a. Sized a => a -> Substitution' Term
sub Tele (Dom Type)
params)
bs :: Boundary
bs = Tele (Dom Type) -> Boundary -> Boundary
fullBoundary Tele (Dom Type)
fsT Boundary
boundary
w1' :: Term
w1' = ConHead -> ConInfo -> Elims -> Term
Con ConHead
con ConInfo
ConOSystem (Elims -> Term) -> Elims -> Term
forall a b. (a -> b) -> a -> b
$ Substitution' Term
sigma Substitution' Term -> Elims -> Elims
forall t a. Subst t a => Substitution' t -> a -> a
`applySubst` Tele (Dom Type) -> Boundary -> Elims
forall a.
DeBruijn a =>
Tele (Dom Type) -> Boundary' (a, a) -> [Elim' a]
teleElims Tele (Dom Type)
fsT Boundary
boundary
imax :: tcm Term -> tcm Term -> tcm Term
imax tcm Term
x tcm Term
y = Term -> tcm Term
forall (f :: * -> *) a. Applicative f => a -> f a
pure Term
tIMax tcm Term -> tcm Term -> tcm Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> tcm Term
x tcm Term -> tcm Term -> tcm Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> tcm Term
y
ineg :: tcm Term -> tcm Term
ineg tcm Term
r = Term -> tcm Term
forall (f :: * -> *) a. Applicative f => a -> f a
pure Term
tINeg tcm Term -> tcm Term -> tcm Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> tcm Term
r
lvlOfType :: Type -> Term
lvlOfType = (\ (Type Level' Term
l) -> Level' Term -> Term
Level Level' Term
l) (Sort -> Term) -> (Type -> Sort) -> Type -> Term
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Type -> Sort
forall a. LensSort a => a -> Sort
getSort
pOr :: NamesT m Type
-> NamesT m Term
-> NamesT m Term
-> NamesT m Term
-> NamesT m Term
-> NamesT m Term
pOr NamesT m Type
la NamesT m Term
i NamesT m Term
j NamesT m Term
u0 NamesT m Term
u1 = Term -> NamesT m Term
forall (f :: * -> *) a. Applicative f => a -> f a
pure Term
tPOr NamesT m Term -> NamesT m Term -> NamesT m Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<#> (Type -> Term
lvlOfType (Type -> Term) -> NamesT m Type -> NamesT m Term
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NamesT m Type
la) NamesT m Term -> NamesT m Term -> NamesT m Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> NamesT m Term
i NamesT m Term -> NamesT m Term -> NamesT m Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> NamesT m Term
j
NamesT m Term -> NamesT m Term -> NamesT m Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<#> (VerboseKey -> (NamesT m Term -> NamesT m Term) -> NamesT m Term
forall (m :: * -> *).
MonadFail m =>
VerboseKey -> (NamesT m Term -> NamesT m Term) -> NamesT m Term
ilam VerboseKey
"o" ((NamesT m Term -> NamesT m Term) -> NamesT m Term)
-> (NamesT m Term -> NamesT m Term) -> NamesT m Term
forall a b. (a -> b) -> a -> b
$ \ NamesT m Term
_ -> Type -> Term
forall t a. Type'' t a -> a
unEl (Type -> Term) -> NamesT m Type -> NamesT m Term
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NamesT m Type
la) NamesT m Term -> NamesT m Term -> NamesT m Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> NamesT m Term
u0 NamesT m Term -> NamesT m Term -> NamesT m Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> NamesT m Term
u1
absAp :: m (Abs r) -> m t -> m r
absAp m (Abs r)
x m t
y = (Abs r -> t -> r) -> m (Abs r) -> m t -> m r
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 Abs r -> t -> r
forall t a. Subst t a => Abs a -> t -> a
absApp m (Abs r)
x m t
y
mkFace :: (Term, (Term, Term)) -> m (Abs (Term, Term))
mkFace (Term
r,(Term
u1,Term
u2)) = [VerboseKey] -> NamesT m (Abs (Term, Term)) -> m (Abs (Term, Term))
forall (m :: * -> *) a. [VerboseKey] -> NamesT m a -> m a
runNamesT [] (NamesT m (Abs (Term, Term)) -> m (Abs (Term, Term)))
-> NamesT m (Abs (Term, Term)) -> m (Abs (Term, Term))
forall a b. (a -> b) -> a -> b
$ do
NamesT m Term
phi <- Term -> NamesT m (NamesT m Term)
forall (m :: * -> *) t a.
(MonadFail m, Subst t a) =>
a -> NamesT m (NamesT m a)
open Term
the_phi
NamesT m (Abs Type)
ty <- Abs Type -> NamesT m (NamesT m (Abs Type))
forall (m :: * -> *) t a.
(MonadFail m, Subst t a) =>
a -> NamesT m (NamesT m a)
open (VerboseKey -> Type -> Abs Type
forall a. VerboseKey -> a -> Abs a
Abs VerboseKey
"i" (Type -> Abs Type) -> Type -> Abs Type
forall a b. (a -> b) -> a -> b
$ (Int -> Substitution' Term -> Substitution' Term
forall a. Int -> Substitution' a -> Substitution' a
liftS Int
1 (Int -> Substitution' Term
forall a. Int -> Substitution' a
raiseS (Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
gamma Int -> Int -> Int
forall a. Num a => a -> a -> a
- Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
params)) Substitution' Term -> Substitution' Term -> Substitution' Term
forall a.
Subst a a =>
Substitution' a -> Substitution' a -> Substitution' a
`composeS` Tele (Dom Type) -> Substitution' Term
forall a. Sized a => a -> Substitution' Term
sub Tele (Dom Type)
params) Substitution' Term -> Type -> Type
forall t a. Subst t a => Substitution' t -> a -> a
`applySubst` Type
t)
VerboseKey
-> (NamesT m Term -> NamesT m (Term, Term))
-> NamesT m (Abs (Term, Term))
forall (m :: * -> *) t' b t a.
(MonadFail m, Subst t' b, DeBruijn b, Subst t a, Free a) =>
VerboseKey -> (NamesT m b -> NamesT m a) -> NamesT m (Abs a)
bind VerboseKey
"i" ((NamesT m Term -> NamesT m (Term, Term))
-> NamesT m (Abs (Term, Term)))
-> (NamesT m Term -> NamesT m (Term, Term))
-> NamesT m (Abs (Term, Term))
forall a b. (a -> b) -> a -> b
$ \ NamesT m Term
i -> do
[NamesT m Term
r,NamesT m Term
u1,NamesT m Term
u2] <- (Term -> NamesT m (NamesT m Term))
-> [Term] -> NamesT m [NamesT m Term]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Term -> NamesT m (NamesT m Term)
forall (m :: * -> *) t a.
(MonadFail m, Subst t a) =>
a -> NamesT m (NamesT m a)
open (Term -> NamesT m (NamesT m Term))
-> (Term -> Term) -> Term -> NamesT m (NamesT m Term)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Substitution' Term -> Term -> Term
forall t a. Subst t a => Substitution' t -> a -> a
applySubst Substitution' Term
theSub) [Term
r,Term
u1,Term
u2]
Term
psi <- NamesT m Term -> NamesT m Term -> NamesT m Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
imax NamesT m Term
r (NamesT m Term -> NamesT m Term
forall (tcm :: * -> *). Monad tcm => tcm Term -> tcm Term
ineg NamesT m Term
r)
let
squeeze :: NamesT m Term -> NamesT m Term
squeeze NamesT m Term
u = m Term -> NamesT m Term
forall (m :: * -> *) a. Monad m => m a -> NamesT m a
cl m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primTrans
NamesT m Term -> NamesT m Term -> NamesT m Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<#> (VerboseKey -> (NamesT m Term -> NamesT m Term) -> NamesT m Term
forall (m :: * -> *).
MonadFail m =>
VerboseKey -> (NamesT m Term -> NamesT m Term) -> NamesT m Term
lam VerboseKey
"j" ((NamesT m Term -> NamesT m Term) -> NamesT m Term)
-> (NamesT m Term -> NamesT m Term) -> NamesT m Term
forall a b. (a -> b) -> a -> b
$ \ NamesT m Term
j -> Type -> Term
lvlOfType (Type -> Term) -> NamesT m Type -> NamesT m Term
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NamesT m (Abs Type)
ty NamesT m (Abs Type) -> NamesT m Term -> NamesT m Type
forall (m :: * -> *) t r.
(Monad m, Subst t r) =>
m (Abs r) -> m t -> m r
`absAp` (NamesT m Term -> NamesT m Term -> NamesT m Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
imax NamesT m Term
i NamesT m Term
j))
NamesT m Term -> NamesT m Term -> NamesT m Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> (VerboseKey -> (NamesT m Term -> NamesT m Term) -> NamesT m Term
forall (m :: * -> *).
MonadFail m =>
VerboseKey -> (NamesT m Term -> NamesT m Term) -> NamesT m Term
lam VerboseKey
"j" ((NamesT m Term -> NamesT m Term) -> NamesT m Term)
-> (NamesT m Term -> NamesT m Term) -> NamesT m Term
forall a b. (a -> b) -> a -> b
$ \ NamesT m Term
j -> Type -> Term
forall t a. Type'' t a -> a
unEl (Type -> Term) -> NamesT m Type -> NamesT m Term
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NamesT m (Abs Type)
ty NamesT m (Abs Type) -> NamesT m Term -> NamesT m Type
forall (m :: * -> *) t r.
(Monad m, Subst t r) =>
m (Abs r) -> m t -> m r
`absAp` (NamesT m Term -> NamesT m Term -> NamesT m Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
imax NamesT m Term
i NamesT m Term
j))
NamesT m Term -> NamesT m Term -> NamesT m Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> (NamesT m Term
phi NamesT m Term -> NamesT m Term -> NamesT m Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
`imax` NamesT m Term
i)
NamesT m Term -> NamesT m Term -> NamesT m Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> NamesT m Term
u
Term
alpha <- NamesT m Type
-> NamesT m Term
-> NamesT m Term
-> NamesT m Term
-> NamesT m Term
-> NamesT m Term
forall (m :: * -> *).
MonadFail m =>
NamesT m Type
-> NamesT m Term
-> NamesT m Term
-> NamesT m Term
-> NamesT m Term
-> NamesT m Term
pOr (NamesT m (Abs Type)
ty NamesT m (Abs Type) -> NamesT m Term -> NamesT m Type
forall (m :: * -> *) t r.
(Monad m, Subst t r) =>
m (Abs r) -> m t -> m r
`absAp` NamesT m Term
i)
(NamesT m Term -> NamesT m Term
forall (tcm :: * -> *). Monad tcm => tcm Term -> tcm Term
ineg NamesT m Term
r)
NamesT m Term
r
(VerboseKey -> (NamesT m Term -> NamesT m Term) -> NamesT m Term
forall (m :: * -> *).
MonadFail m =>
VerboseKey -> (NamesT m Term -> NamesT m Term) -> NamesT m Term
ilam VerboseKey
"o" ((NamesT m Term -> NamesT m Term) -> NamesT m Term)
-> (NamesT m Term -> NamesT m Term) -> NamesT m Term
forall a b. (a -> b) -> a -> b
$ \ NamesT m Term
_ -> NamesT m Term -> NamesT m Term
squeeze NamesT m Term
u1) (VerboseKey -> (NamesT m Term -> NamesT m Term) -> NamesT m Term
forall (m :: * -> *).
MonadFail m =>
VerboseKey -> (NamesT m Term -> NamesT m Term) -> NamesT m Term
ilam VerboseKey
"o" ((NamesT m Term -> NamesT m Term) -> NamesT m Term)
-> (NamesT m Term -> NamesT m Term) -> NamesT m Term
forall a b. (a -> b) -> a -> b
$ \ NamesT m Term
_ -> NamesT m Term -> NamesT m Term
squeeze NamesT m Term
u2)
(Term, Term) -> NamesT m (Term, Term)
forall (m :: * -> *) a. Monad m => a -> m a
return ((Term, Term) -> NamesT m (Term, Term))
-> (Term, Term) -> NamesT m (Term, Term)
forall a b. (a -> b) -> a -> b
$ (Term
psi, Term
alpha)
[Abs (Term, Term)]
faces <- ((Term, (Term, Term)) -> TCMT IO (Abs (Term, Term)))
-> Boundary -> TCMT IO [Abs (Term, Term)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Term, (Term, Term)) -> TCMT IO (Abs (Term, Term))
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
(Term, (Term, Term)) -> m (Abs (Term, Term))
mkFace Boundary
bs
[VerboseKey] -> NamesT (TCMT IO) Term -> TCMT IO Term
forall (m :: * -> *) a. [VerboseKey] -> NamesT m a -> m a
runNamesT [] (NamesT (TCMT IO) Term -> TCMT IO Term)
-> NamesT (TCMT IO) Term -> TCMT IO Term
forall a b. (a -> b) -> a -> b
$ do
NamesT (TCMT IO) Term
w1' <- Term -> NamesT (TCMT IO) (NamesT (TCMT IO) Term)
forall (m :: * -> *) t a.
(MonadFail m, Subst t a) =>
a -> NamesT m (NamesT m a)
open Term
w1'
NamesT (TCMT IO) Term
phi <- Term -> NamesT (TCMT IO) (NamesT (TCMT IO) Term)
forall (m :: * -> *) t a.
(MonadFail m, Subst t a) =>
a -> NamesT m (NamesT m a)
open Term
the_phi
NamesT (TCMT IO) Term
u <- Term -> NamesT (TCMT IO) (NamesT (TCMT IO) Term)
forall (m :: * -> *) t a.
(MonadFail m, Subst t a) =>
a -> NamesT m (NamesT m a)
open Term
the_u
NamesT (TCMT IO) Type
ty <- Type -> NamesT (TCMT IO) (NamesT (TCMT IO) Type)
forall (m :: * -> *) t a.
(MonadFail m, Subst t a) =>
a -> NamesT m (NamesT m a)
open Type
ty
[(NamesT (TCMT IO) Term, NamesT (TCMT IO) (Abs Term))]
faces <- (Abs (Term, Term)
-> NamesT
(TCMT IO) (NamesT (TCMT IO) Term, NamesT (TCMT IO) (Abs Term)))
-> [Abs (Term, Term)]
-> NamesT
(TCMT IO) [(NamesT (TCMT IO) Term, NamesT (TCMT IO) (Abs Term))]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (\ Abs (Term, Term)
x -> (NamesT (TCMT IO) Term
-> NamesT (TCMT IO) (Abs Term)
-> (NamesT (TCMT IO) Term, NamesT (TCMT IO) (Abs Term)))
-> NamesT (TCMT IO) (NamesT (TCMT IO) Term)
-> NamesT (TCMT IO) (NamesT (TCMT IO) (Abs Term))
-> NamesT
(TCMT IO) (NamesT (TCMT IO) Term, NamesT (TCMT IO) (Abs Term))
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 (,) (Term -> NamesT (TCMT IO) (NamesT (TCMT IO) Term)
forall (m :: * -> *) t a.
(MonadFail m, Subst t a) =>
a -> NamesT m (NamesT m a)
open (Term -> NamesT (TCMT IO) (NamesT (TCMT IO) Term))
-> (Abs Term -> Term)
-> Abs Term
-> NamesT (TCMT IO) (NamesT (TCMT IO) Term)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Empty -> Abs Term -> Term
forall t a. Subst t a => Empty -> Abs a -> a
noabsApp Empty
forall a. HasCallStack => a
__IMPOSSIBLE__ (Abs Term -> NamesT (TCMT IO) (NamesT (TCMT IO) Term))
-> Abs Term -> NamesT (TCMT IO) (NamesT (TCMT IO) Term)
forall a b. (a -> b) -> a -> b
$ ((Term, Term) -> Term) -> Abs (Term, Term) -> Abs Term
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Term, Term) -> Term
forall a b. (a, b) -> a
fst Abs (Term, Term)
x) (Abs Term -> NamesT (TCMT IO) (NamesT (TCMT IO) (Abs Term))
forall (m :: * -> *) t a.
(MonadFail m, Subst t a) =>
a -> NamesT m (NamesT m a)
open (Abs Term -> NamesT (TCMT IO) (NamesT (TCMT IO) (Abs Term)))
-> Abs Term -> NamesT (TCMT IO) (NamesT (TCMT IO) (Abs Term))
forall a b. (a -> b) -> a -> b
$ ((Term, Term) -> Term) -> Abs (Term, Term) -> Abs Term
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Term, Term) -> Term
forall a b. (a, b) -> b
snd Abs (Term, Term)
x)) [Abs (Term, Term)]
faces
let
thePsi :: NamesT (TCMT IO) Term
thePsi = (NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term)
-> [NamesT (TCMT IO) Term] -> NamesT (TCMT IO) Term
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldl1 NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
imax (((NamesT (TCMT IO) Term, NamesT (TCMT IO) (Abs Term))
-> NamesT (TCMT IO) Term)
-> [(NamesT (TCMT IO) Term, NamesT (TCMT IO) (Abs Term))]
-> [NamesT (TCMT IO) Term]
forall a b. (a -> b) -> [a] -> [b]
map (NamesT (TCMT IO) Term, NamesT (TCMT IO) (Abs Term))
-> NamesT (TCMT IO) Term
forall a b. (a, b) -> a
fst [(NamesT (TCMT IO) Term, NamesT (TCMT IO) (Abs Term))]
faces)
hcomp :: tcm Type -> tcm Term -> tcm Term -> tcm Term -> tcm Term
hcomp tcm Type
ty tcm Term
phi tcm Term
sys tcm Term
a0 = Term -> tcm Term
forall (f :: * -> *) a. Applicative f => a -> f a
pure Term
tHComp tcm Term -> tcm Term -> tcm Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<#> (Type -> Term
lvlOfType (Type -> Term) -> tcm Type -> tcm Term
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> tcm Type
ty)
tcm Term -> tcm Term -> tcm Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<#> (Type -> Term
forall t a. Type'' t a -> a
unEl (Type -> Term) -> tcm Type -> tcm Term
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> tcm Type
ty)
tcm Term -> tcm Term -> tcm Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<#> tcm Term
phi
tcm Term -> tcm Term -> tcm Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> tcm Term
sys
tcm Term -> tcm Term -> tcm Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> tcm Term
a0
let
sys :: NamesT (TCMT IO) Term
sys = VerboseKey
-> (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term)
-> NamesT (TCMT IO) Term
forall (m :: * -> *).
MonadFail m =>
VerboseKey -> (NamesT m Term -> NamesT m Term) -> NamesT m Term
lam VerboseKey
"i" ((NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term)
-> NamesT (TCMT IO) Term)
-> (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term)
-> NamesT (TCMT IO) Term
forall a b. (a -> b) -> a -> b
$ \ NamesT (TCMT IO) Term
i -> do
let
recurse :: [(NamesT (TCMT IO) Term, NamesT (TCMT IO) (Abs Term))]
-> NamesT (TCMT IO) Term
recurse [(NamesT (TCMT IO) Term
psi,NamesT (TCMT IO) (Abs Term)
alpha)] = NamesT (TCMT IO) (Abs Term)
alpha NamesT (TCMT IO) (Abs Term)
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *) t r.
(Monad m, Subst t r) =>
m (Abs r) -> m t -> m r
`absAp` (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (tcm :: * -> *). Monad tcm => tcm Term -> tcm Term
ineg NamesT (TCMT IO) Term
i)
recurse ((NamesT (TCMT IO) Term
psi,NamesT (TCMT IO) (Abs Term)
alpha):[(NamesT (TCMT IO) Term, NamesT (TCMT IO) (Abs Term))]
xs) = NamesT (TCMT IO) Type
-> NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term
forall (m :: * -> *).
MonadFail m =>
NamesT m Type
-> NamesT m Term
-> NamesT m Term
-> NamesT m Term
-> NamesT m Term
-> NamesT m Term
pOr NamesT (TCMT IO) Type
ty
NamesT (TCMT IO) Term
psi NamesT (TCMT IO) Term
theOr
(NamesT (TCMT IO) (Abs Term)
alpha NamesT (TCMT IO) (Abs Term)
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *) t r.
(Monad m, Subst t r) =>
m (Abs r) -> m t -> m r
`absAp` (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (tcm :: * -> *). Monad tcm => tcm Term -> tcm Term
ineg NamesT (TCMT IO) Term
i)) ([(NamesT (TCMT IO) Term, NamesT (TCMT IO) (Abs Term))]
-> NamesT (TCMT IO) Term
recurse [(NamesT (TCMT IO) Term, NamesT (TCMT IO) (Abs Term))]
xs)
where
theOr :: NamesT (TCMT IO) Term
theOr = (NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term)
-> [NamesT (TCMT IO) Term] -> NamesT (TCMT IO) Term
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldl1 NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
imax (((NamesT (TCMT IO) Term, NamesT (TCMT IO) (Abs Term))
-> NamesT (TCMT IO) Term)
-> [(NamesT (TCMT IO) Term, NamesT (TCMT IO) (Abs Term))]
-> [NamesT (TCMT IO) Term]
forall a b. (a -> b) -> [a] -> [b]
map (NamesT (TCMT IO) Term, NamesT (TCMT IO) (Abs Term))
-> NamesT (TCMT IO) Term
forall a b. (a, b) -> a
fst [(NamesT (TCMT IO) Term, NamesT (TCMT IO) (Abs Term))]
xs)
recurse [] = NamesT (TCMT IO) Term
forall a. HasCallStack => a
__IMPOSSIBLE__
sys_alpha :: NamesT (TCMT IO) Term
sys_alpha = [(NamesT (TCMT IO) Term, NamesT (TCMT IO) (Abs Term))]
-> NamesT (TCMT IO) Term
recurse [(NamesT (TCMT IO) Term, NamesT (TCMT IO) (Abs Term))]
faces
NamesT (TCMT IO) Type
-> NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term
forall (m :: * -> *).
MonadFail m =>
NamesT m Type
-> NamesT m Term
-> NamesT m Term
-> NamesT m Term
-> NamesT m Term
-> NamesT m Term
pOr NamesT (TCMT IO) Type
ty
NamesT (TCMT IO) Term
thePsi NamesT (TCMT IO) Term
phi
NamesT (TCMT IO) Term
sys_alpha (VerboseKey
-> (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term)
-> NamesT (TCMT IO) Term
forall (m :: * -> *).
MonadFail m =>
VerboseKey -> (NamesT m Term -> NamesT m Term) -> NamesT m Term
ilam VerboseKey
"o" ((NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term)
-> NamesT (TCMT IO) Term)
-> (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term)
-> NamesT (TCMT IO) Term
forall a b. (a -> b) -> a -> b
$ \ NamesT (TCMT IO) Term
_ -> NamesT (TCMT IO) Term
u)
NamesT (TCMT IO) Type
-> NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Type -> tcm Term -> tcm Term -> tcm Term -> tcm Term
hcomp NamesT (TCMT IO) Type
ty (NamesT (TCMT IO) Term
thePsi NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
`imax` NamesT (TCMT IO) Term
phi) NamesT (TCMT IO) Term
sys NamesT (TCMT IO) Term
w1'
let
d0 :: Substitution
d0 :: Substitution' Term
d0 = Int -> Substitution' Term -> Substitution' Term
forall a. Int -> Substitution' a -> Substitution' a
wkS Int
1
(Term -> Substitution' Term -> Substitution' Term
forall a. DeBruijn a => a -> Substitution' a -> Substitution' a
consS Term
iz Substitution' Term
forall a. Substitution' a
IdS Substitution' Term -> Substitution' Term -> Substitution' Term
forall a.
Subst a a =>
Substitution' a -> Substitution' a -> Substitution' a
`composeS` Tele (Dom Type) -> Substitution' Term
forall a. Sized a => a -> Substitution' Term
sub Tele (Dom Type)
params)
up :: Pattern' DBPatVar
up = ConHead
-> ConPatternInfo
-> [NamedArg (Pattern' DBPatVar)]
-> Pattern' DBPatVar
forall x.
ConHead -> ConPatternInfo -> [NamedArg (Pattern' x)] -> Pattern' x
ConP ConHead
con (PatternInfo
-> Bool -> Bool -> Maybe (Arg Type) -> Bool -> ConPatternInfo
ConPatternInfo PatternInfo
defaultPatternInfo Bool
False Bool
False Maybe (Arg Type)
forall a. Maybe a
Nothing Bool
False) ([NamedArg (Pattern' DBPatVar)] -> Pattern' DBPatVar)
-> [NamedArg (Pattern' DBPatVar)] -> Pattern' DBPatVar
forall a b. (a -> b) -> a -> b
$
Tele (Dom Type) -> Boundary -> [NamedArg (Pattern' DBPatVar)]
forall a.
DeBruijn a =>
Tele (Dom Type) -> Boundary -> [NamedArg (Pattern' a)]
telePatterns (Substitution' Term
d0 Substitution' Term -> Tele (Dom Type) -> Tele (Dom Type)
forall t a. Subst t a => Substitution' t -> a -> a
`applySubst` Tele (Dom Type)
fsT) (Int -> Substitution' Term -> Substitution' Term
forall a. Int -> Substitution' a -> Substitution' a
liftS (Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
fsT) Substitution' Term
d0 Substitution' Term -> Boundary -> Boundary
forall t a. Subst t a => Substitution' t -> a -> a
`applySubst` Boundary
boundary)
let
pats :: [NamedArg (Pattern' DBPatVar)]
pats | Boundary -> Bool
forall a. Null a => a -> Bool
null Boundary
boundary = Tele (Dom Type) -> [NamedArg (Pattern' DBPatVar)]
forall a. DeBruijn a => Tele (Dom Type) -> [NamedArg a]
teleNamedArgs Tele (Dom Type)
gamma
| Bool
otherwise = Int
-> [NamedArg (Pattern' DBPatVar)] -> [NamedArg (Pattern' DBPatVar)]
forall a. Int -> [a] -> [a]
take (Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
gamma Int -> Int -> Int
forall a. Num a => a -> a -> a
- Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
fsT) (Tele (Dom Type) -> [NamedArg (Pattern' DBPatVar)]
forall a. DeBruijn a => Tele (Dom Type) -> [NamedArg a]
teleNamedArgs Tele (Dom Type)
gamma) [NamedArg (Pattern' DBPatVar)]
-> [NamedArg (Pattern' DBPatVar)] -> [NamedArg (Pattern' DBPatVar)]
forall a. [a] -> [a] -> [a]
++ [Named NamedName (Pattern' DBPatVar) -> NamedArg (Pattern' DBPatVar)
forall e. e -> Arg e
argN (Named NamedName (Pattern' DBPatVar)
-> NamedArg (Pattern' DBPatVar))
-> Named NamedName (Pattern' DBPatVar)
-> NamedArg (Pattern' DBPatVar)
forall a b. (a -> b) -> a -> b
$ Pattern' DBPatVar -> Named NamedName (Pattern' DBPatVar)
forall a name. a -> Named name a
unnamed (Pattern' DBPatVar -> Named NamedName (Pattern' DBPatVar))
-> Pattern' DBPatVar -> Named NamedName (Pattern' DBPatVar)
forall a b. (a -> b) -> a -> b
$ Pattern' DBPatVar
up]
clause :: Clause
clause = Clause :: Range
-> Range
-> Tele (Dom Type)
-> [NamedArg (Pattern' DBPatVar)]
-> Maybe Term
-> Maybe (Arg Type)
-> Bool
-> Maybe Bool
-> Maybe Bool
-> ExpandedEllipsis
-> Clause
Clause
{ clauseTel :: Tele (Dom Type)
clauseTel = Tele (Dom Type)
gamma
, clauseType :: Maybe (Arg Type)
clauseType = Arg Type -> Maybe (Arg Type)
forall a. a -> Maybe a
Just (Arg Type -> Maybe (Arg Type))
-> (Type -> Arg Type) -> Type -> Maybe (Arg Type)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Type -> Arg Type
forall e. e -> Arg e
argN (Type -> Maybe (Arg Type)) -> Type -> Maybe (Arg Type)
forall a b. (a -> b) -> a -> b
$ Type
ty
, namedClausePats :: [NamedArg (Pattern' DBPatVar)]
namedClausePats = [NamedArg (Pattern' DBPatVar)]
pats
, clauseFullRange :: Range
clauseFullRange = Range
forall a. Range' a
noRange
, clauseLHSRange :: Range
clauseLHSRange = Range
forall a. Range' a
noRange
, clauseCatchall :: Bool
clauseCatchall = Bool
False
, clauseBody :: Maybe Term
clauseBody = Term -> Maybe Term
forall a. a -> Maybe a
Just (Term -> Maybe Term) -> Term -> Maybe Term
forall a b. (a -> b) -> a -> b
$ Term
body
, clauseRecursive :: Maybe Bool
clauseRecursive = Maybe Bool
forall a. Maybe a
Nothing
, clauseUnreachable :: Maybe Bool
clauseUnreachable = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False
, clauseEllipsis :: ExpandedEllipsis
clauseEllipsis = ExpandedEllipsis
NoEllipsis
}
cs :: [Clause]
cs = [Clause
clause]
QName -> [Clause] -> TCM ()
addClauses QName
theName [Clause]
cs
(Maybe SplitTree
mst, Bool
_, CompiledClauses
cc) <- TCMT IO (Maybe SplitTree, Bool, CompiledClauses)
-> TCMT IO (Maybe SplitTree, Bool, CompiledClauses)
forall (tcm :: * -> *) a.
(MonadTCEnv tcm, ReadTCState tcm) =>
tcm a -> tcm a
inTopContext (Maybe (QName, Type)
-> [Clause] -> TCMT IO (Maybe SplitTree, Bool, CompiledClauses)
compileClauses Maybe (QName, Type)
forall a. Maybe a
Nothing [Clause]
cs)
Maybe SplitTree -> (SplitTree -> TCM ()) -> TCM ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe SplitTree
mst ((SplitTree -> TCM ()) -> TCM ())
-> (SplitTree -> TCM ()) -> TCM ()
forall a b. (a -> b) -> a -> b
$ QName -> SplitTree -> TCM ()
setSplitTree QName
theName
QName -> CompiledClauses -> TCM ()
setCompiledClauses QName
theName CompiledClauses
cc
QName -> Bool -> TCM ()
setTerminates QName
theName Bool
True
Maybe QName -> TCMT IO (Maybe QName)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe QName -> TCMT IO (Maybe QName))
-> Maybe QName -> TCMT IO (Maybe QName)
forall a b. (a -> b) -> a -> b
$ QName -> Maybe QName
forall a. a -> Maybe a
Just QName
theName
whenDefined :: Bool -> t VerboseKey -> m (Maybe a) -> m (Maybe a)
whenDefined Bool
False t VerboseKey
_ m (Maybe a)
_ = Maybe a -> m (Maybe a)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe a
forall a. Maybe a
Nothing
whenDefined Bool
True t VerboseKey
xs m (Maybe a)
m = do
t (Maybe Term)
xs <- (VerboseKey -> m (Maybe Term))
-> t VerboseKey -> m (t (Maybe Term))
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM VerboseKey -> m (Maybe Term)
forall (m :: * -> *). HasBuiltins m => VerboseKey -> m (Maybe Term)
getTerm' t VerboseKey
xs
if (Maybe Term -> Bool) -> t (Maybe Term) -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Maybe Term -> Bool
forall a. Maybe a -> Bool
isJust t (Maybe Term)
xs then m (Maybe a)
m else Maybe a -> m (Maybe a)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe a
forall a. Maybe a
Nothing
defineProjections :: QName
-> ConHead
-> Telescope
-> [QName]
-> Telescope
-> Type
-> TCM ()
defineProjections :: QName
-> ConHead
-> Tele (Dom Type)
-> [QName]
-> Tele (Dom Type)
-> Type
-> TCM ()
defineProjections QName
dataName ConHead
con Tele (Dom Type)
params [QName]
names Tele (Dom Type)
fsT Type
t = do
let
fieldTypes :: [Dom Type]
fieldTypes = ([ QName -> Elims -> Term
Def QName
f [] Term -> [Arg Term] -> Term
forall t. Apply t => t -> [Arg Term] -> t
`apply` [Term -> Arg Term
forall e. e -> Arg e
argN (Term -> Arg Term) -> Term -> Arg Term
forall a b. (a -> b) -> a -> b
$ Int -> Term
var Int
0] | QName
f <- [QName] -> [QName]
forall a. [a] -> [a]
reverse [QName]
names ] [Term] -> Substitution' Term -> Substitution' Term
forall a. DeBruijn a => [a] -> Substitution' a -> Substitution' a
++# Int -> Substitution' Term
forall a. Int -> Substitution' a
raiseS Int
1) Substitution' Term -> [Dom Type] -> [Dom Type]
forall t a. Subst t a => Substitution' t -> a -> a
`applySubst`
Tele (Dom Type) -> [Dom Type]
forall a. Subst Term a => Tele (Dom a) -> [Dom a]
flattenTel Tele (Dom Type)
fsT
projTel :: Tele (Dom Type)
projTel = Tele (Dom Type) -> Tele (Dom Type) -> Tele (Dom Type)
forall t. Abstract t => Tele (Dom Type) -> t -> t
abstract Tele (Dom Type)
params (Dom Type -> Abs (Tele (Dom Type)) -> Tele (Dom Type)
forall a. a -> Abs (Tele a) -> Tele a
ExtendTel (Type -> Dom Type
forall a. a -> Dom a
defaultDom Type
t) (VerboseKey -> Tele (Dom Type) -> Abs (Tele (Dom Type))
forall a. VerboseKey -> a -> Abs a
Abs VerboseKey
"d" Tele (Dom Type)
forall a. Tele a
EmptyTel))
np :: Int
np = Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
params
[(Int, QName, Dom Type)]
-> ((Int, QName, Dom Type) -> TCM ()) -> TCM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ ([Int] -> [QName] -> [Dom Type] -> [(Int, QName, Dom Type)]
forall a b c. [a] -> [b] -> [c] -> [(a, b, c)]
zip3 (Int -> [Int]
forall a. Integral a => a -> [a]
downFrom ([Dom Type] -> Int
forall a. Sized a => a -> Int
size [Dom Type]
fieldTypes)) [QName]
names [Dom Type]
fieldTypes) (((Int, QName, Dom Type) -> TCM ()) -> TCM ())
-> ((Int, QName, Dom Type) -> TCM ()) -> TCM ()
forall a b. (a -> b) -> a -> b
$ \ (Int
i,QName
projName,Dom Type
ty) -> do
let
projType :: Dom Type
projType = Tele (Dom Type) -> Type -> Type
forall t. Abstract t => Tele (Dom Type) -> t -> t
abstract Tele (Dom Type)
projTel (Type -> Type) -> Dom Type -> Dom Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Dom Type
ty
cpi :: ConPatternInfo
cpi = PatternInfo
-> Bool -> Bool -> Maybe (Arg Type) -> Bool -> ConPatternInfo
ConPatternInfo PatternInfo
defaultPatternInfo Bool
False Bool
False (Arg Type -> Maybe (Arg Type)
forall a. a -> Maybe a
Just (Arg Type -> Maybe (Arg Type)) -> Arg Type -> Maybe (Arg Type)
forall a b. (a -> b) -> a -> b
$ Type -> Arg Type
forall e. e -> Arg e
argN (Type -> Arg Type) -> Type -> Arg Type
forall a b. (a -> b) -> a -> b
$ Int -> Type -> Type
forall t a. Subst t a => Int -> a -> a
raise (Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
fsT) Type
t) Bool
False
conp :: NamedArg (Pattern' DBPatVar)
conp = Pattern' DBPatVar -> NamedArg (Pattern' DBPatVar)
forall a. a -> NamedArg a
defaultNamedArg (Pattern' DBPatVar -> NamedArg (Pattern' DBPatVar))
-> Pattern' DBPatVar -> NamedArg (Pattern' DBPatVar)
forall a b. (a -> b) -> a -> b
$ ConHead
-> ConPatternInfo
-> [NamedArg (Pattern' DBPatVar)]
-> Pattern' DBPatVar
forall x.
ConHead -> ConPatternInfo -> [NamedArg (Pattern' x)] -> Pattern' x
ConP ConHead
con ConPatternInfo
cpi ([NamedArg (Pattern' DBPatVar)] -> Pattern' DBPatVar)
-> [NamedArg (Pattern' DBPatVar)] -> Pattern' DBPatVar
forall a b. (a -> b) -> a -> b
$ Tele (Dom Type) -> [NamedArg (Pattern' DBPatVar)]
forall a. DeBruijn a => Tele (Dom Type) -> [NamedArg a]
teleNamedArgs Tele (Dom Type)
fsT
sigma :: Substitution' Term
sigma = ConHead -> ConInfo -> Elims -> Term
Con ConHead
con ConInfo
ConOSystem ((Arg Term -> Elim' Term) -> [Arg Term] -> Elims
forall a b. (a -> b) -> [a] -> [b]
map Arg Term -> Elim' Term
forall a. Arg a -> Elim' a
Apply ([Arg Term] -> Elims) -> [Arg Term] -> Elims
forall a b. (a -> b) -> a -> b
$ Tele (Dom Type) -> [Arg Term]
forall a t. DeBruijn a => Tele (Dom t) -> [Arg a]
teleArgs Tele (Dom Type)
fsT) Term -> Substitution' Term -> Substitution' Term
forall a. DeBruijn a => a -> Substitution' a -> Substitution' a
`consS` Int -> Substitution' Term
forall a. Int -> Substitution' a
raiseS (Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
fsT)
clause :: Clause
clause = Clause
forall a. Null a => a
empty
{ clauseTel :: Tele (Dom Type)
clauseTel = Tele (Dom Type) -> Tele (Dom Type) -> Tele (Dom Type)
forall t. Abstract t => Tele (Dom Type) -> t -> t
abstract Tele (Dom Type)
params Tele (Dom Type)
fsT
, namedClausePats :: [NamedArg (Pattern' DBPatVar)]
namedClausePats = [ NamedArg (Pattern' DBPatVar)
conp ]
, clauseBody :: Maybe Term
clauseBody = Term -> Maybe Term
forall a. a -> Maybe a
Just (Term -> Maybe Term) -> Term -> Maybe Term
forall a b. (a -> b) -> a -> b
$ Int -> Term
var Int
i
, clauseType :: Maybe (Arg Type)
clauseType = Arg Type -> Maybe (Arg Type)
forall a. a -> Maybe a
Just (Arg Type -> Maybe (Arg Type)) -> Arg Type -> Maybe (Arg Type)
forall a b. (a -> b) -> a -> b
$ Type -> Arg Type
forall e. e -> Arg e
argN (Type -> Arg Type) -> Type -> Arg Type
forall a b. (a -> b) -> a -> b
$ Substitution' Term -> Type -> Type
forall t a. Subst t a => Substitution' t -> a -> a
applySubst Substitution' Term
sigma (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$ Dom Type -> Type
forall t e. Dom' t e -> e
unDom Dom Type
ty
, clauseRecursive :: Maybe Bool
clauseRecursive = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False
, clauseUnreachable :: Maybe Bool
clauseUnreachable = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False
}
VerboseKey -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
VerboseKey -> Int -> TCMT IO Doc -> m ()
reportSDoc VerboseKey
"tc.data.proj" Int
20 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc -> TCMT IO Doc
forall (tcm :: * -> *) a.
(MonadTCEnv tcm, ReadTCState tcm) =>
tcm a -> tcm a
inTopContext (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *). Monad m => [m Doc] -> m Doc
sep
[ TCMT IO Doc
"proj" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> (Int, Dom Type) -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM (Int
i,Dom Type
ty)
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *). Monad m => [m Doc] -> m Doc
sep [ QName -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM QName
projName, TCMT IO Doc
":", Dom Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Dom Type
projType ]
]
TCM () -> TCM ()
forall a. TCM a -> TCM a
noMutualBlock (TCM () -> TCM ()) -> TCM () -> TCM ()
forall a b. (a -> b) -> a -> b
$ do
let cs :: [Clause]
cs = [ Clause
clause ]
(Maybe SplitTree
mst, Bool
_, CompiledClauses
cc) <- Maybe (QName, Type)
-> [Clause] -> TCMT IO (Maybe SplitTree, Bool, CompiledClauses)
compileClauses Maybe (QName, Type)
forall a. Maybe a
Nothing [Clause]
cs
let fun :: Defn
fun = Defn
emptyFunction
{ funClauses :: [Clause]
funClauses = [Clause]
cs
, funCompiled :: Maybe CompiledClauses
funCompiled = CompiledClauses -> Maybe CompiledClauses
forall a. a -> Maybe a
Just CompiledClauses
cc
, funSplitTree :: Maybe SplitTree
funSplitTree = Maybe SplitTree
mst
, funProjection :: Maybe Projection
funProjection = Projection -> Maybe Projection
forall a. a -> Maybe a
Just (Projection -> Maybe Projection) -> Projection -> Maybe Projection
forall a b. (a -> b) -> a -> b
$ Projection :: Maybe QName -> QName -> Arg QName -> Int -> ProjLams -> Projection
Projection
{ projProper :: Maybe QName
projProper = Maybe QName
forall a. Maybe a
Nothing
, projOrig :: QName
projOrig = QName
projName
, projFromType :: Arg QName
projFromType = ArgInfo -> QName -> Arg QName
forall e. ArgInfo -> e -> Arg e
Arg (Dom Type -> ArgInfo
forall a. LensArgInfo a => a -> ArgInfo
getArgInfo Dom Type
ty) QName
dataName
, projIndex :: Int
projIndex = Int
np Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
, projLams :: ProjLams
projLams = [Arg VerboseKey] -> ProjLams
ProjLams ([Arg VerboseKey] -> ProjLams) -> [Arg VerboseKey] -> ProjLams
forall a b. (a -> b) -> a -> b
$ (Dom' Term (VerboseKey, Type) -> Arg VerboseKey)
-> [Dom' Term (VerboseKey, Type)] -> [Arg VerboseKey]
forall a b. (a -> b) -> [a] -> [b]
map (Dom' Term VerboseKey -> Arg VerboseKey
forall t a. Dom' t a -> Arg a
argFromDom (Dom' Term VerboseKey -> Arg VerboseKey)
-> (Dom' Term (VerboseKey, Type) -> Dom' Term VerboseKey)
-> Dom' Term (VerboseKey, Type)
-> Arg VerboseKey
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((VerboseKey, Type) -> VerboseKey)
-> Dom' Term (VerboseKey, Type) -> Dom' Term VerboseKey
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (VerboseKey, Type) -> VerboseKey
forall a b. (a, b) -> a
fst) ([Dom' Term (VerboseKey, Type)] -> [Arg VerboseKey])
-> [Dom' Term (VerboseKey, Type)] -> [Arg VerboseKey]
forall a b. (a -> b) -> a -> b
$ Tele (Dom Type) -> [Dom' Term (VerboseKey, Type)]
forall t. Tele (Dom t) -> [Dom (VerboseKey, t)]
telToList Tele (Dom Type)
projTel
}
, funMutual :: Maybe [QName]
funMutual = [QName] -> Maybe [QName]
forall a. a -> Maybe a
Just []
, funTerminates :: Maybe Bool
funTerminates = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True
}
TCM () -> TCM ()
forall (tcm :: * -> *) a.
(MonadTCEnv tcm, ReadTCState tcm) =>
tcm a -> tcm a
inTopContext (TCM () -> TCM ()) -> TCM () -> TCM ()
forall a b. (a -> b) -> a -> b
$ QName -> Definition -> TCM ()
addConstant QName
projName (Definition -> TCM ()) -> Definition -> TCM ()
forall a b. (a -> b) -> a -> b
$
(ArgInfo -> QName -> Type -> Defn -> Definition
defaultDefn ArgInfo
defaultArgInfo QName
projName (Dom Type -> Type
forall t e. Dom' t e -> e
unDom Dom Type
projType) Defn
fun)
{ defNoCompilation :: Bool
defNoCompilation = Bool
True
, defArgOccurrences :: [Occurrence]
defArgOccurrences = [Occurrence
StrictPos]
}
VerboseKey -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
VerboseKey -> Int -> TCMT IO Doc -> m ()
reportSDoc VerboseKey
"tc.data.proj.fun" Int
60 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc -> TCMT IO Doc
forall (tcm :: * -> *) a.
(MonadTCEnv tcm, ReadTCState tcm) =>
tcm a -> tcm a
inTopContext (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *). Monad m => [m Doc] -> m Doc
vcat
[ TCMT IO Doc
"proj" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Int -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Int
i
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ Defn -> TCMT IO Doc
forall (m :: * -> *) a. (Monad m, Pretty a) => a -> m Doc
pretty Defn
fun
]
freshAbstractQName'_ :: String -> TCM QName
freshAbstractQName'_ :: VerboseKey -> TCMT IO QName
freshAbstractQName'_ VerboseKey
s = Fixity' -> Name -> TCMT IO QName
freshAbstractQName Fixity'
noFixity' (Range -> NameInScope -> [NamePart] -> Name
C.Name Range
forall a. Range' a
noRange NameInScope
C.InScope [VerboseKey -> NamePart
C.Id (VerboseKey -> NamePart) -> VerboseKey -> NamePart
forall a b. (a -> b) -> a -> b
$ VerboseKey
s])
data LType = LEl Level Term deriving (LType -> LType -> Bool
(LType -> LType -> Bool) -> (LType -> LType -> Bool) -> Eq LType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LType -> LType -> Bool
$c/= :: LType -> LType -> Bool
== :: LType -> LType -> Bool
$c== :: LType -> LType -> Bool
Eq,Int -> LType -> VerboseKey -> VerboseKey
[LType] -> VerboseKey -> VerboseKey
LType -> VerboseKey
(Int -> LType -> VerboseKey -> VerboseKey)
-> (LType -> VerboseKey)
-> ([LType] -> VerboseKey -> VerboseKey)
-> Show LType
forall a.
(Int -> a -> VerboseKey -> VerboseKey)
-> (a -> VerboseKey) -> ([a] -> VerboseKey -> VerboseKey) -> Show a
showList :: [LType] -> VerboseKey -> VerboseKey
$cshowList :: [LType] -> VerboseKey -> VerboseKey
show :: LType -> VerboseKey
$cshow :: LType -> VerboseKey
showsPrec :: Int -> LType -> VerboseKey -> VerboseKey
$cshowsPrec :: Int -> LType -> VerboseKey -> VerboseKey
Show)
fromLType :: LType -> Type
fromLType :: LType -> Type
fromLType (LEl Level' Term
l Term
t) = Sort -> Term -> Type
forall t a. Sort' t -> a -> Type'' t a
El (Level' Term -> Sort
forall t. Level' t -> Sort' t
Type Level' Term
l) Term
t
lTypeLevel :: LType -> Level
lTypeLevel :: LType -> Level' Term
lTypeLevel (LEl Level' Term
l Term
t) = Level' Term
l
toLType :: MonadReduce m => Type -> m (Maybe LType)
toLType :: Type -> m (Maybe LType)
toLType Type
ty = do
Sort
sort <- Sort -> m Sort
forall a (m :: * -> *). (Reduce a, MonadReduce m) => a -> m a
reduce (Sort -> m Sort) -> Sort -> m Sort
forall a b. (a -> b) -> a -> b
$ Type -> Sort
forall a. LensSort a => a -> Sort
getSort Type
ty
case Sort
sort of
Type Level' Term
l -> Maybe LType -> m (Maybe LType)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe LType -> m (Maybe LType)) -> Maybe LType -> m (Maybe LType)
forall a b. (a -> b) -> a -> b
$ LType -> Maybe LType
forall a. a -> Maybe a
Just (LType -> Maybe LType) -> LType -> Maybe LType
forall a b. (a -> b) -> a -> b
$ Level' Term -> Term -> LType
LEl Level' Term
l (Type -> Term
forall t a. Type'' t a -> a
unEl Type
ty)
Sort
_ -> Maybe LType -> m (Maybe LType)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe LType -> m (Maybe LType)) -> Maybe LType -> m (Maybe LType)
forall a b. (a -> b) -> a -> b
$ Maybe LType
forall a. Maybe a
Nothing
instance Subst Term LType where
applySubst :: Substitution' Term -> LType -> LType
applySubst Substitution' Term
rho (LEl Level' Term
l Term
t) = Level' Term -> Term -> LType
LEl (Substitution' Term -> Level' Term -> Level' Term
forall t a. Subst t a => Substitution' t -> a -> a
applySubst Substitution' Term
rho Level' Term
l) (Substitution' Term -> Term -> Term
forall t a. Subst t a => Substitution' t -> a -> a
applySubst Substitution' Term
rho Term
t)
data CType = ClosedType QName | LType LType deriving (CType -> CType -> Bool
(CType -> CType -> Bool) -> (CType -> CType -> Bool) -> Eq CType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CType -> CType -> Bool
$c/= :: CType -> CType -> Bool
== :: CType -> CType -> Bool
$c== :: CType -> CType -> Bool
Eq,Int -> CType -> VerboseKey -> VerboseKey
[CType] -> VerboseKey -> VerboseKey
CType -> VerboseKey
(Int -> CType -> VerboseKey -> VerboseKey)
-> (CType -> VerboseKey)
-> ([CType] -> VerboseKey -> VerboseKey)
-> Show CType
forall a.
(Int -> a -> VerboseKey -> VerboseKey)
-> (a -> VerboseKey) -> ([a] -> VerboseKey -> VerboseKey) -> Show a
showList :: [CType] -> VerboseKey -> VerboseKey
$cshowList :: [CType] -> VerboseKey -> VerboseKey
show :: CType -> VerboseKey
$cshow :: CType -> VerboseKey
showsPrec :: Int -> CType -> VerboseKey -> VerboseKey
$cshowsPrec :: Int -> CType -> VerboseKey -> VerboseKey
Show)
fromCType :: CType -> Type
fromCType :: CType -> Type
fromCType (ClosedType QName
q) = Sort -> Term -> Type
forall t a. Sort' t -> a -> Type'' t a
El Sort
forall t. Sort' t
Inf (QName -> Elims -> Term
Def QName
q [])
fromCType (LType LType
t) = LType -> Type
fromLType LType
t
toCType :: MonadReduce m => Type -> m (Maybe CType)
toCType :: Type -> m (Maybe CType)
toCType Type
ty = do
Sort
sort <- Sort -> m Sort
forall a (m :: * -> *). (Reduce a, MonadReduce m) => a -> m a
reduce (Sort -> m Sort) -> Sort -> m Sort
forall a b. (a -> b) -> a -> b
$ Type -> Sort
forall a. LensSort a => a -> Sort
getSort Type
ty
case Sort
sort of
Type Level' Term
l -> Maybe CType -> m (Maybe CType)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe CType -> m (Maybe CType)) -> Maybe CType -> m (Maybe CType)
forall a b. (a -> b) -> a -> b
$ CType -> Maybe CType
forall a. a -> Maybe a
Just (CType -> Maybe CType) -> CType -> Maybe CType
forall a b. (a -> b) -> a -> b
$ LType -> CType
LType (Level' Term -> Term -> LType
LEl Level' Term
l (Type -> Term
forall t a. Type'' t a -> a
unEl Type
ty))
Sort
Inf -> do
Term
t <- Term -> m Term
forall a (m :: * -> *). (Reduce a, MonadReduce m) => a -> m a
reduce (Type -> Term
forall t a. Type'' t a -> a
unEl Type
ty)
case Term
t of
Def QName
q [] -> Maybe CType -> m (Maybe CType)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe CType -> m (Maybe CType)) -> Maybe CType -> m (Maybe CType)
forall a b. (a -> b) -> a -> b
$ CType -> Maybe CType
forall a. a -> Maybe a
Just (CType -> Maybe CType) -> CType -> Maybe CType
forall a b. (a -> b) -> a -> b
$ QName -> CType
ClosedType QName
q
Term
_ -> Maybe CType -> m (Maybe CType)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe CType -> m (Maybe CType)) -> Maybe CType -> m (Maybe CType)
forall a b. (a -> b) -> a -> b
$ Maybe CType
forall a. Maybe a
Nothing
Sort
_ -> Maybe CType -> m (Maybe CType)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe CType -> m (Maybe CType)) -> Maybe CType -> m (Maybe CType)
forall a b. (a -> b) -> a -> b
$ Maybe CType
forall a. Maybe a
Nothing
instance Subst Term CType where
applySubst :: Substitution' Term -> CType -> CType
applySubst Substitution' Term
rho t :: CType
t@ClosedType{} = CType
t
applySubst Substitution' Term
rho (LType LType
t) = LType -> CType
LType (LType -> CType) -> LType -> CType
forall a b. (a -> b) -> a -> b
$ Substitution' Term -> LType -> LType
forall t a. Subst t a => Substitution' t -> a -> a
applySubst Substitution' Term
rho LType
t
defineTranspOrHCompForFields
:: TranspOrHComp
-> (Maybe Term)
-> (Term -> QName -> Term)
-> QName
-> Telescope
-> Telescope
-> [Arg QName]
-> Type
-> TCM (Maybe ((QName, Telescope, Type, [Dom Type], [Term]), Substitution))
defineTranspOrHCompForFields :: TranspOrHComp
-> Maybe Term
-> (Term -> QName -> Term)
-> QName
-> Tele (Dom Type)
-> Tele (Dom Type)
-> [Arg QName]
-> Type
-> TCM
(Maybe
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term))
defineTranspOrHCompForFields TranspOrHComp
cmd Maybe Term
pathCons Term -> QName -> Term
project QName
name Tele (Dom Type)
params Tele (Dom Type)
fsT [Arg QName]
fns Type
rect =
case TranspOrHComp
cmd of
TranspOrHComp
DoTransp -> MaybeT
(TCMT IO)
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
-> TCM
(Maybe
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term))
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT (MaybeT
(TCMT IO)
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
-> TCM
(Maybe
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)))
-> MaybeT
(TCMT IO)
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
-> TCM
(Maybe
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term))
forall a b. (a -> b) -> a -> b
$ do
Tele (Dom' Term CType)
fsT' <- (Dom Type -> MaybeT (TCMT IO) (Dom' Term CType))
-> Tele (Dom Type) -> MaybeT (TCMT IO) (Tele (Dom' Term CType))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((Type -> MaybeT (TCMT IO) CType)
-> Dom Type -> MaybeT (TCMT IO) (Dom' Term CType)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (TCMT IO (Maybe CType) -> MaybeT (TCMT IO) CType
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT (TCMT IO (Maybe CType) -> MaybeT (TCMT IO) CType)
-> (Type -> TCMT IO (Maybe CType))
-> Type
-> MaybeT (TCMT IO) CType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Type -> TCMT IO (Maybe CType)
forall (m :: * -> *). MonadReduce m => Type -> m (Maybe CType)
toCType)) Tele (Dom Type)
fsT
TCMT
IO
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
-> MaybeT
(TCMT IO)
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCMT
IO
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
-> MaybeT
(TCMT IO)
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term))
-> TCMT
IO
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
-> MaybeT
(TCMT IO)
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
forall a b. (a -> b) -> a -> b
$ Maybe Term
-> (Term -> QName -> Term)
-> QName
-> Tele (Dom Type)
-> Tele (Dom' Term CType)
-> [Arg QName]
-> Type
-> TCMT
IO
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
defineTranspForFields Maybe Term
pathCons Term -> QName -> Term
project QName
name Tele (Dom Type)
params Tele (Dom' Term CType)
fsT' [Arg QName]
fns Type
rect
TranspOrHComp
DoHComp -> MaybeT
(TCMT IO)
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
-> TCM
(Maybe
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term))
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT (MaybeT
(TCMT IO)
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
-> TCM
(Maybe
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)))
-> MaybeT
(TCMT IO)
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
-> TCM
(Maybe
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term))
forall a b. (a -> b) -> a -> b
$ do
Tele (Dom' Term LType)
fsT' <- (Dom Type -> MaybeT (TCMT IO) (Dom' Term LType))
-> Tele (Dom Type) -> MaybeT (TCMT IO) (Tele (Dom' Term LType))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((Type -> MaybeT (TCMT IO) LType)
-> Dom Type -> MaybeT (TCMT IO) (Dom' Term LType)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (TCMT IO (Maybe LType) -> MaybeT (TCMT IO) LType
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT (TCMT IO (Maybe LType) -> MaybeT (TCMT IO) LType)
-> (Type -> TCMT IO (Maybe LType))
-> Type
-> MaybeT (TCMT IO) LType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Type -> TCMT IO (Maybe LType)
forall (m :: * -> *). MonadReduce m => Type -> m (Maybe LType)
toLType)) Tele (Dom Type)
fsT
LType
rect' <- TCMT IO (Maybe LType) -> MaybeT (TCMT IO) LType
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT (TCMT IO (Maybe LType) -> MaybeT (TCMT IO) LType)
-> TCMT IO (Maybe LType) -> MaybeT (TCMT IO) LType
forall a b. (a -> b) -> a -> b
$ Type -> TCMT IO (Maybe LType)
forall (m :: * -> *). MonadReduce m => Type -> m (Maybe LType)
toLType Type
rect
TCMT
IO
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
-> MaybeT
(TCMT IO)
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCMT
IO
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
-> MaybeT
(TCMT IO)
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term))
-> TCMT
IO
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
-> MaybeT
(TCMT IO)
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
forall a b. (a -> b) -> a -> b
$ (Term -> QName -> Term)
-> QName
-> Tele (Dom Type)
-> Tele (Dom' Term LType)
-> [Arg QName]
-> LType
-> TCMT
IO
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
defineHCompForFields Term -> QName -> Term
project QName
name Tele (Dom Type)
params Tele (Dom' Term LType)
fsT' [Arg QName]
fns LType
rect'
defineTranspForFields
:: (Maybe Term)
-> (Term -> QName -> Term)
-> QName
-> Telescope
-> Tele (Dom CType)
-> [Arg QName]
-> Type
-> TCM ((QName, Telescope, Type, [Dom Type], [Term]), Substitution)
defineTranspForFields :: Maybe Term
-> (Term -> QName -> Term)
-> QName
-> Tele (Dom Type)
-> Tele (Dom' Term CType)
-> [Arg QName]
-> Type
-> TCMT
IO
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
defineTranspForFields Maybe Term
pathCons Term -> QName -> Term
applyProj QName
name Tele (Dom Type)
params Tele (Dom' Term CType)
fsT [Arg QName]
fns Type
rect = do
Type
interval <- TCMT IO Term -> TCMT IO Type
forall (m :: * -> *). Functor m => m Term -> m Type
elInf TCMT IO Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primInterval
let deltaI :: Tele (Dom Type)
deltaI = Type -> Tele (Dom Type) -> Tele (Dom Type)
expTelescope Type
interval Tele (Dom Type)
params
Term
iz <- TCMT IO Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primIZero
Term
io <- TCMT IO Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primIOne
Term
imin <- VerboseKey -> TCMT IO Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
VerboseKey -> m Term
getPrimitiveTerm VerboseKey
"primIMin"
Term
imax <- VerboseKey -> TCMT IO Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
VerboseKey -> m Term
getPrimitiveTerm VerboseKey
"primIMax"
Term
ineg <- VerboseKey -> TCMT IO Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
VerboseKey -> m Term
getPrimitiveTerm VerboseKey
"primINeg"
Term
transp <- VerboseKey -> TCMT IO Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
VerboseKey -> m Term
getPrimitiveTerm VerboseKey
builtinTrans
Term
por <- VerboseKey -> TCMT IO Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
VerboseKey -> m Term
getPrimitiveTerm VerboseKey
"primPOr"
Term
one <- TCMT IO Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primItIsOne
VerboseKey -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
VerboseKey -> Int -> TCMT IO Doc -> m ()
reportSDoc VerboseKey
"trans.rec" Int
20 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
forall a b. (a -> b) -> a -> b
$ VerboseKey -> TCMT IO Doc
forall (m :: * -> *). Monad m => VerboseKey -> m Doc
text (VerboseKey -> TCMT IO Doc) -> VerboseKey -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ Tele (Dom Type) -> VerboseKey
forall a. Show a => a -> VerboseKey
show Tele (Dom Type)
params
VerboseKey -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
VerboseKey -> Int -> TCMT IO Doc -> m ()
reportSDoc VerboseKey
"trans.rec" Int
20 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
forall a b. (a -> b) -> a -> b
$ VerboseKey -> TCMT IO Doc
forall (m :: * -> *). Monad m => VerboseKey -> m Doc
text (VerboseKey -> TCMT IO Doc) -> VerboseKey -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ Tele (Dom Type) -> VerboseKey
forall a. Show a => a -> VerboseKey
show Tele (Dom Type)
deltaI
VerboseKey -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
VerboseKey -> Int -> TCMT IO Doc -> m ()
reportSDoc VerboseKey
"trans.rec" Int
10 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
forall a b. (a -> b) -> a -> b
$ VerboseKey -> TCMT IO Doc
forall (m :: * -> *). Monad m => VerboseKey -> m Doc
text (VerboseKey -> TCMT IO Doc) -> VerboseKey -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ Tele (Dom' Term CType) -> VerboseKey
forall a. Show a => a -> VerboseKey
show Tele (Dom' Term CType)
fsT
let thePrefix :: VerboseKey
thePrefix = VerboseKey
"transp-"
QName
theName <- VerboseKey -> TCMT IO QName
freshAbstractQName'_ (VerboseKey -> TCMT IO QName) -> VerboseKey -> TCMT IO QName
forall a b. (a -> b) -> a -> b
$ VerboseKey
thePrefix VerboseKey -> VerboseKey -> VerboseKey
forall a. [a] -> [a] -> [a]
++ Name -> VerboseKey
forall a. Pretty a => a -> VerboseKey
P.prettyShow (QName -> Name
A.qnameName QName
name)
VerboseKey -> Int -> VerboseKey -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
VerboseKey -> Int -> VerboseKey -> m ()
reportSLn VerboseKey
"trans.rec" Int
5 (VerboseKey -> TCM ()) -> VerboseKey -> TCM ()
forall a b. (a -> b) -> a -> b
$ (VerboseKey
"Generated name: " VerboseKey -> VerboseKey -> VerboseKey
forall a. [a] -> [a] -> [a]
++ QName -> VerboseKey
forall a. Show a => a -> VerboseKey
show QName
theName VerboseKey -> VerboseKey -> VerboseKey
forall a. [a] -> [a] -> [a]
++ VerboseKey
" " VerboseKey -> VerboseKey -> VerboseKey
forall a. [a] -> [a] -> [a]
++ QName -> VerboseKey
showQNameId QName
theName)
Type
theType <- (Tele (Dom Type) -> Type -> Type
forall t. Abstract t => Tele (Dom Type) -> t -> t
abstract Tele (Dom Type)
deltaI (Type -> Type) -> TCMT IO Type -> TCMT IO Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>) (TCMT IO Type -> TCMT IO Type) -> TCMT IO Type -> TCMT IO Type
forall a b. (a -> b) -> a -> b
$ [VerboseKey] -> NamesT (TCMT IO) Type -> TCMT IO Type
forall (m :: * -> *) a. [VerboseKey] -> NamesT m a -> m a
runNamesT [] (NamesT (TCMT IO) Type -> TCMT IO Type)
-> NamesT (TCMT IO) Type -> TCMT IO Type
forall a b. (a -> b) -> a -> b
$ do
NamesT (TCMT IO) (Abs Type)
rect' <- Abs Type -> NamesT (TCMT IO) (NamesT (TCMT IO) (Abs Type))
forall (m :: * -> *) t a.
(MonadFail m, Subst t a) =>
a -> NamesT m (NamesT m a)
open ([VerboseKey] -> NamesT Fail (Abs Type) -> Abs Type
forall a. [VerboseKey] -> NamesT Fail a -> a
runNames [] (NamesT Fail (Abs Type) -> Abs Type)
-> NamesT Fail (Abs Type) -> Abs Type
forall a b. (a -> b) -> a -> b
$ VerboseKey
-> (NamesT Fail Term -> NamesT Fail Type) -> NamesT Fail (Abs Type)
forall (m :: * -> *) t' b t a.
(MonadFail m, Subst t' b, DeBruijn b, Subst t a, Free a) =>
VerboseKey -> (NamesT m b -> NamesT m a) -> NamesT m (Abs a)
bind VerboseKey
"i" ((NamesT Fail Term -> NamesT Fail Type) -> NamesT Fail (Abs Type))
-> (NamesT Fail Term -> NamesT Fail Type) -> NamesT Fail (Abs Type)
forall a b. (a -> b) -> a -> b
$ \ NamesT Fail Term
x -> let NamesT Fail Term
_ = NamesT Fail Term
x NamesT Fail Term -> NamesT Fail Term -> NamesT Fail Term
forall a. a -> a -> a
`asTypeOf` Term -> NamesT Fail Term
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Term
forall a. HasCallStack => a
undefined :: Term) in
Type -> NamesT Fail Type
forall (f :: * -> *) a. Applicative f => a -> f a
pure Type
rect')
VerboseKey
-> NamesT (TCMT IO) Type
-> (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type)
-> NamesT (TCMT IO) Type
forall (m :: * -> *).
(MonadFail m, MonadAddContext m, MonadDebug m) =>
VerboseKey
-> NamesT m Type
-> (NamesT m Term -> NamesT m Type)
-> NamesT m Type
nPi' VerboseKey
"phi" (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type
forall (m :: * -> *). Functor m => m Term -> m Type
elInf (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type)
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type
forall a b. (a -> b) -> a -> b
$ TCMT IO Term -> NamesT (TCMT IO) Term
forall (m :: * -> *) a. Monad m => m a -> NamesT m a
cl TCMT IO Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primInterval) ((NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type)
-> NamesT (TCMT IO) Type)
-> (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type)
-> NamesT (TCMT IO) Type
forall a b. (a -> b) -> a -> b
$ \ NamesT (TCMT IO) Term
phi ->
(Abs Type -> Term -> Type
forall t a. Subst t a => Abs a -> t -> a
absApp (Abs Type -> Term -> Type)
-> NamesT (TCMT IO) (Abs Type) -> NamesT (TCMT IO) (Term -> Type)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NamesT (TCMT IO) (Abs Type)
rect' NamesT (TCMT IO) (Term -> Type)
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Term -> NamesT (TCMT IO) Term
forall (f :: * -> *) a. Applicative f => a -> f a
pure Term
iz) NamesT (TCMT IO) Type
-> NamesT (TCMT IO) Type -> NamesT (TCMT IO) Type
forall (tcm :: * -> *).
Monad tcm =>
tcm Type -> tcm Type -> tcm Type
--> (Abs Type -> Term -> Type
forall t a. Subst t a => Abs a -> t -> a
absApp (Abs Type -> Term -> Type)
-> NamesT (TCMT IO) (Abs Type) -> NamesT (TCMT IO) (Term -> Type)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NamesT (TCMT IO) (Abs Type)
rect' NamesT (TCMT IO) (Term -> Type)
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Term -> NamesT (TCMT IO) Term
forall (f :: * -> *) a. Applicative f => a -> f a
pure Term
io)
VerboseKey -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
VerboseKey -> Int -> TCMT IO Doc -> m ()
reportSDoc VerboseKey
"trans.rec" Int
20 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
forall a b. (a -> b) -> a -> b
$ Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Type
theType
VerboseKey -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
VerboseKey -> Int -> TCMT IO Doc -> m ()
reportSDoc VerboseKey
"trans.rec" Int
60 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
forall a b. (a -> b) -> a -> b
$ VerboseKey -> TCMT IO Doc
forall (m :: * -> *). Monad m => VerboseKey -> m Doc
text (VerboseKey -> TCMT IO Doc) -> VerboseKey -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ VerboseKey
"sort = " VerboseKey -> VerboseKey -> VerboseKey
forall a. [a] -> [a] -> [a]
++ Sort -> VerboseKey
forall a. Show a => a -> VerboseKey
show (Type -> Sort
forall a. LensSort a => a -> Sort
getSort Type
rect')
TCM () -> TCM ()
forall a. TCM a -> TCM a
noMutualBlock (TCM () -> TCM ()) -> TCM () -> TCM ()
forall a b. (a -> b) -> a -> b
$ QName -> Definition -> TCM ()
addConstant QName
theName (Definition -> TCM ()) -> Definition -> TCM ()
forall a b. (a -> b) -> a -> b
$ (ArgInfo -> QName -> Type -> Defn -> Definition
defaultDefn ArgInfo
defaultArgInfo QName
theName Type
theType
(Defn
emptyFunction { funTerminates :: Maybe Bool
funTerminates = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True }))
{ defNoCompilation :: Bool
defNoCompilation = Bool
True }
TelV Tele (Dom Type)
gamma Type
rtype <- Type -> TCMT IO (TelV Type)
forall (m :: * -> *).
(MonadReduce m, MonadAddContext m) =>
Type -> m (TelV Type)
telView Type
theType
let
theTerm :: Term
theTerm = QName -> Elims -> Term
Def QName
theName [] Term -> [Arg Term] -> Term
forall t. Apply t => t -> [Arg Term] -> t
`apply` Tele (Dom Type) -> [Arg Term]
forall a t. DeBruijn a => Tele (Dom t) -> [Arg a]
teleArgs Tele (Dom Type)
gamma
clause_types :: [Dom' Term CType]
clause_types = [Term] -> Substitution' Term
forall a. DeBruijn a => [a] -> Substitution' a
parallelS [Term
theTerm Term -> QName -> Term
`applyProj` (Arg QName -> QName
forall e. Arg e -> e
unArg Arg QName
fn)
| Arg QName
fn <- [Arg QName] -> [Arg QName]
forall a. [a] -> [a]
reverse [Arg QName]
fns] Substitution' Term -> [Dom' Term CType] -> [Dom' Term CType]
forall t a. Subst t a => Substitution' t -> a -> a
`applySubst`
Tele (Dom' Term CType) -> [Dom' Term CType]
forall a. Subst Term a => Tele (Dom a) -> [Dom a]
flattenTel (Int -> Term -> Substitution' Term
forall a. DeBruijn a => Int -> a -> Substitution' a
singletonS Int
0 Term
io Substitution' Term
-> Tele (Dom' Term CType) -> Tele (Dom' Term CType)
forall t a. Subst t a => Substitution' t -> a -> a
`applySubst` Tele (Dom' Term CType)
fsT')
delta_i :: Substitution' Term
delta_i = (Int -> Substitution' Term -> Substitution' Term
forall a. Int -> Substitution' a -> Substitution' a
liftS Int
1 (Int -> Substitution' Term
forall a. Int -> Substitution' a
raiseS (Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
gamma Int -> Int -> Int
forall a. Num a => a -> a -> a
- Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
deltaI)) Substitution' Term -> Substitution' Term -> Substitution' Term
forall a.
Subst a a =>
Substitution' a -> Substitution' a -> Substitution' a
`composeS` Tele (Dom Type) -> Substitution' Term
forall a. Sized a => a -> Substitution' Term
sub Tele (Dom Type)
params)
fsT' :: Tele (Dom' Term CType)
fsT' = (Int -> Substitution' Term -> Substitution' Term
forall a. Int -> Substitution' a -> Substitution' a
liftS Int
1 (Int -> Substitution' Term
forall a. Int -> Substitution' a
raiseS (Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
gamma Int -> Int -> Int
forall a. Num a => a -> a -> a
- Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
deltaI)) Substitution' Term -> Substitution' Term -> Substitution' Term
forall a.
Subst a a =>
Substitution' a -> Substitution' a -> Substitution' a
`composeS` Tele (Dom Type) -> Substitution' Term
forall a. Sized a => a -> Substitution' Term
sub Tele (Dom Type)
params) Substitution' Term
-> Tele (Dom' Term CType) -> Tele (Dom' Term CType)
forall t a. Subst t a => Substitution' t -> a -> a
`applySubst`
Tele (Dom' Term CType)
fsT
lam_i :: Term -> Term
lam_i = ArgInfo -> Abs Term -> Term
Lam ArgInfo
defaultArgInfo (Abs Term -> Term) -> (Term -> Abs Term) -> Term -> Term
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VerboseKey -> Term -> Abs Term
forall a. VerboseKey -> a -> Abs a
Abs VerboseKey
"i"
gamma' :: Tele (Dom Type)
gamma' = [Dom' Term (VerboseKey, Type)] -> Tele (Dom Type)
telFromList ([Dom' Term (VerboseKey, Type)] -> Tele (Dom Type))
-> [Dom' Term (VerboseKey, Type)] -> Tele (Dom Type)
forall a b. (a -> b) -> a -> b
$ Int
-> [Dom' Term (VerboseKey, Type)] -> [Dom' Term (VerboseKey, Type)]
forall a. Int -> [a] -> [a]
take (Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
gamma Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ([Dom' Term (VerboseKey, Type)] -> [Dom' Term (VerboseKey, Type)])
-> [Dom' Term (VerboseKey, Type)] -> [Dom' Term (VerboseKey, Type)]
forall a b. (a -> b) -> a -> b
$ Tele (Dom Type) -> [Dom' Term (VerboseKey, Type)]
forall t. Tele (Dom t) -> [Dom (VerboseKey, t)]
telToList Tele (Dom Type)
gamma
d0 :: Substitution
d0 :: Substitution' Term
d0 = Int -> Substitution' Term -> Substitution' Term
forall a. Int -> Substitution' a -> Substitution' a
wkS Int
1
(Term -> Substitution' Term -> Substitution' Term
forall a. DeBruijn a => a -> Substitution' a -> Substitution' a
consS Term
iz Substitution' Term
forall a. Substitution' a
IdS Substitution' Term -> Substitution' Term -> Substitution' Term
forall a.
Subst a a =>
Substitution' a -> Substitution' a -> Substitution' a
`composeS` Tele (Dom Type) -> Substitution' Term
forall a. Sized a => a -> Substitution' Term
sub Tele (Dom Type)
params)
(Tele (Dom Type)
tel,Substitution' Term
theta,Term
the_phi,Term
the_u0, [Term]
the_fields) =
case Maybe Term
pathCons of
Just Term
u -> (Tele (Dom Type) -> Tele (Dom Type) -> Tele (Dom Type)
forall t. Abstract t => Tele (Dom Type) -> t -> t
abstract Tele (Dom Type)
gamma' (Substitution' Term
d0 Substitution' Term -> Tele (Dom Type) -> Tele (Dom Type)
forall t a. Subst t a => Substitution' t -> a -> a
`applySubst` (Dom' Term CType -> Dom Type)
-> Tele (Dom' Term CType) -> Tele (Dom Type)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((CType -> Type) -> Dom' Term CType -> Dom Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap CType -> Type
fromCType) Tele (Dom' Term CType)
fsT)
, (Int -> Substitution' Term -> Substitution' Term
forall a. Int -> Substitution' a -> Substitution' a
liftS (Tele (Dom' Term CType) -> Int
forall a. Sized a => a -> Int
size Tele (Dom' Term CType)
fsT) Substitution' Term
d0 Substitution' Term -> Term -> Term
forall t a. Subst t a => Substitution' t -> a -> a
`applySubst` Term
u) Term -> Substitution' Term -> Substitution' Term
forall a. DeBruijn a => a -> Substitution' a -> Substitution' a
`consS` Int -> Substitution' Term
forall a. Int -> Substitution' a
raiseS (Tele (Dom' Term CType) -> Int
forall a. Sized a => a -> Int
size Tele (Dom' Term CType)
fsT)
, Int -> Term -> Term
forall t a. Subst t a => Int -> a -> a
raise (Tele (Dom' Term CType) -> Int
forall a. Sized a => a -> Int
size Tele (Dom' Term CType)
fsT) (Int -> Term
var Int
0)
, (Int -> Substitution' Term -> Substitution' Term
forall a. Int -> Substitution' a -> Substitution' a
liftS (Tele (Dom' Term CType) -> Int
forall a. Sized a => a -> Int
size Tele (Dom' Term CType)
fsT) Substitution' Term
d0 Substitution' Term -> Term -> Term
forall t a. Subst t a => Substitution' t -> a -> a
`applySubst` Term
u)
, Int -> [Term] -> [Term]
forall a. Int -> [a] -> [a]
drop (Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
gamma') ([Term] -> [Term]) -> [Term] -> [Term]
forall a b. (a -> b) -> a -> b
$ (Arg Term -> Term) -> [Arg Term] -> [Term]
forall a b. (a -> b) -> [a] -> [b]
map Arg Term -> Term
forall e. Arg e -> e
unArg ([Arg Term] -> [Term]) -> [Arg Term] -> [Term]
forall a b. (a -> b) -> a -> b
$ Tele (Dom Type) -> [Arg Term]
forall a t. DeBruijn a => Tele (Dom t) -> [Arg a]
teleArgs Tele (Dom Type)
tel)
Maybe Term
Nothing -> (Tele (Dom Type)
gamma, Substitution' Term
forall a. Substitution' a
IdS, Int -> Term
var Int
1, Int -> Term
var Int
0, (Arg QName -> Term) -> [Arg QName] -> [Term]
forall a b. (a -> b) -> [a] -> [b]
map (\ Arg QName
fname -> Int -> Term
var Int
0 Term -> QName -> Term
`applyProj` Arg QName -> QName
forall e. Arg e -> e
unArg Arg QName
fname) [Arg QName]
fns )
fsT_tel :: Tele (Dom' Term CType)
fsT_tel = (Int -> Substitution' Term -> Substitution' Term
forall a. Int -> Substitution' a -> Substitution' a
liftS Int
1 (Int -> Substitution' Term
forall a. Int -> Substitution' a
raiseS (Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
tel Int -> Int -> Int
forall a. Num a => a -> a -> a
- Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
deltaI)) Substitution' Term -> Substitution' Term -> Substitution' Term
forall a.
Subst a a =>
Substitution' a -> Substitution' a -> Substitution' a
`composeS` Tele (Dom Type) -> Substitution' Term
forall a. Sized a => a -> Substitution' Term
sub Tele (Dom Type)
params) Substitution' Term
-> Tele (Dom' Term CType) -> Tele (Dom' Term CType)
forall t a. Subst t a => Substitution' t -> a -> a
`applySubst` Tele (Dom' Term CType)
fsT
iMin :: Term -> Term -> Term
iMin Term
x Term
y = Term
imin Term -> [Arg Term] -> Term
forall t. Apply t => t -> [Arg Term] -> t
`apply` [Term -> Arg Term
forall e. e -> Arg e
argN Term
x, Term -> Arg Term
forall e. e -> Arg e
argN Term
y]
iMax :: Term -> Term -> Term
iMax Term
x Term
y = Term
imax Term -> [Arg Term] -> Term
forall t. Apply t => t -> [Arg Term] -> t
`apply` [Term -> Arg Term
forall e. e -> Arg e
argN Term
x, Term -> Arg Term
forall e. e -> Arg e
argN Term
y]
iNeg :: Term -> Term
iNeg Term
x = Term
ineg Term -> [Arg Term] -> Term
forall t. Apply t => t -> [Arg Term] -> t
`apply` [Term -> Arg Term
forall e. e -> Arg e
argN Term
x]
mkBody :: (Term, Dom' t CType) -> m Term
mkBody (Term
field, Dom' t CType
filled_ty') = do
let
filled_ty :: Term
filled_ty = Term -> Term
lam_i (Term -> Term) -> Term -> Term
forall a b. (a -> b) -> a -> b
$ (Type -> Term
forall t a. Type'' t a -> a
unEl (Type -> Term) -> (Dom' t CType -> Type) -> Dom' t CType -> Term
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CType -> Type
fromCType (CType -> Type) -> (Dom' t CType -> CType) -> Dom' t CType -> Type
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dom' t CType -> CType
forall t e. Dom' t e -> e
unDom) Dom' t CType
filled_ty'
case Dom' t CType -> CType
forall t e. Dom' t e -> e
unDom Dom' t CType
filled_ty' of
LType (LEl Level' Term
l Term
_) -> do
let lvl :: Term
lvl = Term -> Term
lam_i (Term -> Term) -> Term -> Term
forall a b. (a -> b) -> a -> b
$ Level' Term -> Term
Level Level' Term
l
Term -> m Term
forall (m :: * -> *) a. Monad m => a -> m a
return (Term -> m Term) -> Term -> m Term
forall a b. (a -> b) -> a -> b
$ [VerboseKey] -> NamesT Fail Term -> Term
forall a. [VerboseKey] -> NamesT Fail a -> a
runNames [] (NamesT Fail Term -> Term) -> NamesT Fail Term -> Term
forall a b. (a -> b) -> a -> b
$ do
NamesT Fail Term
lvl <- Term -> NamesT Fail (NamesT Fail Term)
forall (m :: * -> *) t a.
(MonadFail m, Subst t a) =>
a -> NamesT m (NamesT m a)
open Term
lvl
[NamesT Fail Term
phi,NamesT Fail Term
field] <- (Term -> NamesT Fail (NamesT Fail Term))
-> [Term] -> NamesT Fail [NamesT Fail Term]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Term -> NamesT Fail (NamesT Fail Term)
forall (m :: * -> *) t a.
(MonadFail m, Subst t a) =>
a -> NamesT m (NamesT m a)
open [Term
the_phi,Term
field]
Term -> NamesT Fail Term
forall (f :: * -> *) a. Applicative f => a -> f a
pure Term
transp NamesT Fail Term -> NamesT Fail Term -> NamesT Fail Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<#> NamesT Fail Term
lvl NamesT Fail Term -> NamesT Fail Term -> NamesT Fail Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> Term -> NamesT Fail Term
forall (f :: * -> *) a. Applicative f => a -> f a
pure Term
filled_ty
NamesT Fail Term -> NamesT Fail Term -> NamesT Fail Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> NamesT Fail Term
phi
NamesT Fail Term -> NamesT Fail Term -> NamesT Fail Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> NamesT Fail Term
field
ClosedType{} ->
Term -> m Term
forall (m :: * -> *) a. Monad m => a -> m a
return (Term -> m Term) -> Term -> m Term
forall a b. (a -> b) -> a -> b
$ [VerboseKey] -> NamesT Fail Term -> Term
forall a. [VerboseKey] -> NamesT Fail a -> a
runNames [] (NamesT Fail Term -> Term) -> NamesT Fail Term -> Term
forall a b. (a -> b) -> a -> b
$ do
[NamesT Fail Term
field] <- (Term -> NamesT Fail (NamesT Fail Term))
-> [Term] -> NamesT Fail [NamesT Fail Term]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Term -> NamesT Fail (NamesT Fail Term)
forall (m :: * -> *) t a.
(MonadFail m, Subst t a) =>
a -> NamesT m (NamesT m a)
open [Term
field]
NamesT Fail Term
field
let
tau :: Substitution' Term
tau = [Term] -> Substitution' Term
forall a. DeBruijn a => [a] -> Substitution' a
parallelS ([Term] -> Substitution' Term) -> [Term] -> Substitution' Term
forall a b. (a -> b) -> a -> b
$ [Term]
us [Term] -> [Term] -> [Term]
forall a. [a] -> [a] -> [a]
++ (Term
phi Term -> Term -> Term
`iMax` Term -> Term
iNeg (Int -> Term
var Int
0))
Term -> [Term] -> [Term]
forall a. a -> [a] -> [a]
: (Term -> Term) -> [Term] -> [Term]
forall a b. (a -> b) -> [a] -> [b]
map (\ Term
d -> ArgInfo -> Abs Term -> Term
Lam ArgInfo
defaultArgInfo (Abs Term -> Term) -> Abs Term -> Term
forall a b. (a -> b) -> a -> b
$ VerboseKey -> Term -> Abs Term
forall a. VerboseKey -> a -> Abs a
Abs VerboseKey
"i" (Term -> Abs Term) -> Term -> Abs Term
forall a b. (a -> b) -> a -> b
$ Int -> Term -> Term
forall t a. Subst t a => Int -> a -> a
raise Int
1 Term
d Term -> [Arg Term] -> Term
forall t. Apply t => t -> [Arg Term] -> t
`apply` [Term -> Arg Term
forall e. e -> Arg e
argN (Term -> Arg Term) -> Term -> Arg Term
forall a b. (a -> b) -> a -> b
$ (Term -> Term -> Term
iMin (Int -> Term
var Int
0) (Int -> Term
var Int
1))]) [Term]
ds
where
([Term]
us, Term
phi:[Term]
ds) = Int -> [Term] -> ([Term], [Term])
forall a. Int -> [a] -> ([a], [a])
splitAt (Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
tel Int -> Int -> Int
forall a. Num a => a -> a -> a
- Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
gamma') ([Term] -> ([Term], [Term])) -> [Term] -> ([Term], [Term])
forall a b. (a -> b) -> a -> b
$ [Term] -> [Term]
forall a. [a] -> [a]
reverse (Int -> [Term] -> [Term]
forall t a. Subst t a => Int -> a -> a
raise Int
1 ((Arg Term -> Term) -> [Arg Term] -> [Term]
forall a b. (a -> b) -> [a] -> [b]
map Arg Term -> Term
forall e. Arg e -> e
unArg (Tele (Dom Type) -> [Arg Term]
forall a t. DeBruijn a => Tele (Dom t) -> [Arg a]
teleArgs Tele (Dom Type)
tel)))
let
go :: [Term] -> [(Term, Dom' t CType)] -> m [Term]
go [Term]
acc [] = [Term] -> m [Term]
forall (m :: * -> *) a. Monad m => a -> m a
return []
go [Term]
acc ((Term
fname,Dom' t CType
field_ty) : [(Term, Dom' t CType)]
ps) = do
let
filled_ty :: Dom' t CType
filled_ty = [Term] -> Substitution' Term
forall a. DeBruijn a => [a] -> Substitution' a
parallelS (Substitution' Term
tau Substitution' Term -> [Term] -> [Term]
forall t a. Subst t a => Substitution' t -> a -> a
`applySubst` [Term]
acc) Substitution' Term -> Dom' t CType -> Dom' t CType
forall t a. Subst t a => Substitution' t -> a -> a
`applySubst` Dom' t CType
field_ty
Term
b <- (Term, Dom' t CType) -> m Term
forall (m :: * -> *) t. Monad m => (Term, Dom' t CType) -> m Term
mkBody (Term
fname,Dom' t CType
filled_ty)
[Term]
bs <- [Term] -> [(Term, Dom' t CType)] -> m [Term]
go (Term
b Term -> [Term] -> [Term]
forall a. a -> [a] -> [a]
: [Term]
acc) [(Term, Dom' t CType)]
ps
[Term] -> m [Term]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Term] -> m [Term]) -> [Term] -> m [Term]
forall a b. (a -> b) -> a -> b
$ Term
b Term -> [Term] -> [Term]
forall a. a -> [a] -> [a]
: [Term]
bs
[Term]
bodys <- [Term] -> [(Term, Dom' Term CType)] -> TCMT IO [Term]
forall (m :: * -> *) t.
(Monad m, Subst Term t) =>
[Term] -> [(Term, Dom' t CType)] -> m [Term]
go [] ([Term] -> [Dom' Term CType] -> [(Term, Dom' Term CType)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Term]
the_fields ((Dom' Term (VerboseKey, CType) -> Dom' Term CType)
-> [Dom' Term (VerboseKey, CType)] -> [Dom' Term CType]
forall a b. (a -> b) -> [a] -> [b]
map (((VerboseKey, CType) -> CType)
-> Dom' Term (VerboseKey, CType) -> Dom' Term CType
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (VerboseKey, CType) -> CType
forall a b. (a, b) -> b
snd) ([Dom' Term (VerboseKey, CType)] -> [Dom' Term CType])
-> [Dom' Term (VerboseKey, CType)] -> [Dom' Term CType]
forall a b. (a -> b) -> a -> b
$ Tele (Dom' Term CType) -> [Dom' Term (VerboseKey, CType)]
forall t. Tele (Dom t) -> [Dom (VerboseKey, t)]
telToList Tele (Dom' Term CType)
fsT_tel))
let
theSubst :: Substitution' Term
theSubst = [Term] -> [Term]
forall a. [a] -> [a]
reverse (Substitution' Term
tau Substitution' Term -> [Term] -> [Term]
forall t a. Subst t a => Substitution' t -> a -> a
`applySubst` [Term]
bodys) [Term] -> Substitution' Term -> Substitution' Term
forall a. DeBruijn a => [a] -> Substitution' a -> Substitution' a
++# (Int -> Substitution' Term -> Substitution' Term
forall a. Int -> Substitution' a -> Substitution' a
liftS Int
1 (Int -> Substitution' Term
forall a. Int -> Substitution' a
raiseS (Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
tel Int -> Int -> Int
forall a. Num a => a -> a -> a
- Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
deltaI)) Substitution' Term -> Substitution' Term -> Substitution' Term
forall a.
Subst a a =>
Substitution' a -> Substitution' a -> Substitution' a
`composeS` Tele (Dom Type) -> Substitution' Term
forall a. Sized a => a -> Substitution' Term
sub Tele (Dom Type)
params)
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
-> TCMT
IO
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
forall (m :: * -> *) a. Monad m => a -> m a
return (((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
-> TCMT
IO
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term))
-> ((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
-> TCMT
IO
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
forall a b. (a -> b) -> a -> b
$ ((QName
theName, Tele (Dom Type)
tel, Substitution' Term
theta Substitution' Term -> Type -> Type
forall t a. Subst t a => Substitution' t -> a -> a
`applySubst` Type
rtype, (Dom' Term CType -> Dom Type) -> [Dom' Term CType] -> [Dom Type]
forall a b. (a -> b) -> [a] -> [b]
map ((CType -> Type) -> Dom' Term CType -> Dom Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap CType -> Type
fromCType) [Dom' Term CType]
clause_types, [Term]
bodys), Substitution' Term
theSubst)
where
rect' :: Type
rect' = Tele (Dom Type) -> Substitution' Term
forall a. Sized a => a -> Substitution' Term
sub Tele (Dom Type)
params Substitution' Term -> Type -> Type
forall t a. Subst t a => Substitution' t -> a -> a
`applySubst` Type
rect
sub :: a -> Substitution' Term
sub a
tel = [Term] -> Substitution' Term
forall a. DeBruijn a => [a] -> Substitution' a
parallelS [ Int -> Term
var Int
n Term -> [Arg Term] -> Term
forall t. Apply t => t -> [Arg Term] -> t
`apply` [ArgInfo -> Term -> Arg Term
forall e. ArgInfo -> e -> Arg e
Arg ArgInfo
defaultArgInfo (Term -> Arg Term) -> Term -> Arg Term
forall a b. (a -> b) -> a -> b
$ Int -> Term
var Int
0] | Int
n <- [Int
1..a -> Int
forall a. Sized a => a -> Int
size a
tel] ]
expTelescope :: Type -> Telescope -> Telescope
expTelescope :: Type -> Tele (Dom Type) -> Tele (Dom Type)
expTelescope Type
int Tele (Dom Type)
tel = [VerboseKey] -> [Dom Type] -> Tele (Dom Type)
unflattenTel [VerboseKey]
names [Dom Type]
ys
where
xs :: [Dom Type]
xs = Tele (Dom Type) -> [Dom Type]
forall a. Subst Term a => Tele (Dom a) -> [Dom a]
flattenTel Tele (Dom Type)
tel
names :: [VerboseKey]
names = Tele (Dom Type) -> [VerboseKey]
teleNames Tele (Dom Type)
tel
t :: Tele (Dom Type)
t = Dom Type -> Abs (Tele (Dom Type)) -> Tele (Dom Type)
forall a. a -> Abs (Tele a) -> Tele a
ExtendTel (Type -> Dom Type
forall a. a -> Dom a
defaultDom (Type -> Dom Type) -> Type -> Dom Type
forall a b. (a -> b) -> a -> b
$ Int -> Type -> Type
forall t a. Subst t a => Int -> a -> a
raise (Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
tel) Type
int) (VerboseKey -> Tele (Dom Type) -> Abs (Tele (Dom Type))
forall a. VerboseKey -> a -> Abs a
Abs VerboseKey
"i" Tele (Dom Type)
forall a. Tele a
EmptyTel)
s :: Substitution' Term
s = Tele (Dom Type) -> Substitution' Term
forall a. Sized a => a -> Substitution' Term
sub Tele (Dom Type)
tel
ys :: [Dom Type]
ys = (Dom Type -> Dom Type) -> [Dom Type] -> [Dom Type]
forall a b. (a -> b) -> [a] -> [b]
map ((Type -> Type) -> Dom Type -> Dom Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Tele (Dom Type) -> Type -> Type
forall t. Abstract t => Tele (Dom Type) -> t -> t
abstract Tele (Dom Type)
t) (Dom Type -> Dom Type)
-> (Dom Type -> Dom Type) -> Dom Type -> Dom Type
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Substitution' Term -> Dom Type -> Dom Type
forall t a. Subst t a => Substitution' t -> a -> a
applySubst Substitution' Term
s) [Dom Type]
xs
defineHCompForFields
:: (Term -> QName -> Term)
-> QName
-> Telescope
-> Tele (Dom LType)
-> [Arg QName]
-> LType
-> TCM ((QName, Telescope, Type, [Dom Type], [Term]),Substitution)
defineHCompForFields :: (Term -> QName -> Term)
-> QName
-> Tele (Dom Type)
-> Tele (Dom' Term LType)
-> [Arg QName]
-> LType
-> TCMT
IO
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
defineHCompForFields Term -> QName -> Term
applyProj QName
name Tele (Dom Type)
params Tele (Dom' Term LType)
fsT [Arg QName]
fns LType
rect = do
Type
interval <- TCMT IO Term -> TCMT IO Type
forall (m :: * -> *). Functor m => m Term -> m Type
elInf TCMT IO Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primInterval
let delta :: Tele (Dom Type)
delta = Tele (Dom Type)
params
Term
iz <- TCMT IO Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primIZero
Term
io <- TCMT IO Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primIOne
Term
imin <- VerboseKey -> TCMT IO Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
VerboseKey -> m Term
getPrimitiveTerm VerboseKey
"primIMin"
Term
imax <- VerboseKey -> TCMT IO Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
VerboseKey -> m Term
getPrimitiveTerm VerboseKey
"primIMax"
Term
tIMax <- VerboseKey -> TCMT IO Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
VerboseKey -> m Term
getPrimitiveTerm VerboseKey
"primIMax"
Term
ineg <- VerboseKey -> TCMT IO Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
VerboseKey -> m Term
getPrimitiveTerm VerboseKey
"primINeg"
Term
hcomp <- VerboseKey -> TCMT IO Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
VerboseKey -> m Term
getPrimitiveTerm VerboseKey
builtinHComp
Term
transp <- VerboseKey -> TCMT IO Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
VerboseKey -> m Term
getPrimitiveTerm VerboseKey
builtinTrans
Term
por <- VerboseKey -> TCMT IO Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
VerboseKey -> m Term
getPrimitiveTerm VerboseKey
"primPOr"
Term
one <- TCMT IO Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primItIsOne
VerboseKey -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
VerboseKey -> Int -> TCMT IO Doc -> m ()
reportSDoc VerboseKey
"comp.rec" Int
20 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
forall a b. (a -> b) -> a -> b
$ VerboseKey -> TCMT IO Doc
forall (m :: * -> *). Monad m => VerboseKey -> m Doc
text (VerboseKey -> TCMT IO Doc) -> VerboseKey -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ Tele (Dom Type) -> VerboseKey
forall a. Show a => a -> VerboseKey
show Tele (Dom Type)
params
VerboseKey -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
VerboseKey -> Int -> TCMT IO Doc -> m ()
reportSDoc VerboseKey
"comp.rec" Int
20 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
forall a b. (a -> b) -> a -> b
$ VerboseKey -> TCMT IO Doc
forall (m :: * -> *). Monad m => VerboseKey -> m Doc
text (VerboseKey -> TCMT IO Doc) -> VerboseKey -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ Tele (Dom Type) -> VerboseKey
forall a. Show a => a -> VerboseKey
show Tele (Dom Type)
delta
VerboseKey -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
VerboseKey -> Int -> TCMT IO Doc -> m ()
reportSDoc VerboseKey
"comp.rec" Int
10 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
forall a b. (a -> b) -> a -> b
$ VerboseKey -> TCMT IO Doc
forall (m :: * -> *). Monad m => VerboseKey -> m Doc
text (VerboseKey -> TCMT IO Doc) -> VerboseKey -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ Tele (Dom' Term LType) -> VerboseKey
forall a. Show a => a -> VerboseKey
show Tele (Dom' Term LType)
fsT
let thePrefix :: VerboseKey
thePrefix = VerboseKey
"hcomp-"
QName
theName <- VerboseKey -> TCMT IO QName
freshAbstractQName'_ (VerboseKey -> TCMT IO QName) -> VerboseKey -> TCMT IO QName
forall a b. (a -> b) -> a -> b
$ VerboseKey
thePrefix VerboseKey -> VerboseKey -> VerboseKey
forall a. [a] -> [a] -> [a]
++ Name -> VerboseKey
forall a. Pretty a => a -> VerboseKey
P.prettyShow (QName -> Name
A.qnameName QName
name)
VerboseKey -> Int -> VerboseKey -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
VerboseKey -> Int -> VerboseKey -> m ()
reportSLn VerboseKey
"hcomp.rec" Int
5 (VerboseKey -> TCM ()) -> VerboseKey -> TCM ()
forall a b. (a -> b) -> a -> b
$ (VerboseKey
"Generated name: " VerboseKey -> VerboseKey -> VerboseKey
forall a. [a] -> [a] -> [a]
++ QName -> VerboseKey
forall a. Show a => a -> VerboseKey
show QName
theName VerboseKey -> VerboseKey -> VerboseKey
forall a. [a] -> [a] -> [a]
++ VerboseKey
" " VerboseKey -> VerboseKey -> VerboseKey
forall a. [a] -> [a] -> [a]
++ QName -> VerboseKey
showQNameId QName
theName)
Type
theType <- (Tele (Dom Type) -> Type -> Type
forall t. Abstract t => Tele (Dom Type) -> t -> t
abstract Tele (Dom Type)
delta (Type -> Type) -> TCMT IO Type -> TCMT IO Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>) (TCMT IO Type -> TCMT IO Type) -> TCMT IO Type -> TCMT IO Type
forall a b. (a -> b) -> a -> b
$ [VerboseKey] -> NamesT (TCMT IO) Type -> TCMT IO Type
forall (m :: * -> *) a. [VerboseKey] -> NamesT m a -> m a
runNamesT [] (NamesT (TCMT IO) Type -> TCMT IO Type)
-> NamesT (TCMT IO) Type -> TCMT IO Type
forall a b. (a -> b) -> a -> b
$ do
NamesT (TCMT IO) Type
rect <- Type -> NamesT (TCMT IO) (NamesT (TCMT IO) Type)
forall (m :: * -> *) t a.
(MonadFail m, Subst t a) =>
a -> NamesT m (NamesT m a)
open (Type -> NamesT (TCMT IO) (NamesT (TCMT IO) Type))
-> Type -> NamesT (TCMT IO) (NamesT (TCMT IO) Type)
forall a b. (a -> b) -> a -> b
$ LType -> Type
fromLType LType
rect
VerboseKey
-> NamesT (TCMT IO) Type
-> (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type)
-> NamesT (TCMT IO) Type
forall (m :: * -> *).
(MonadFail m, MonadAddContext m, MonadDebug m) =>
VerboseKey
-> NamesT m Type
-> (NamesT m Term -> NamesT m Type)
-> NamesT m Type
nPi' VerboseKey
"phi" (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type
forall (m :: * -> *). Functor m => m Term -> m Type
elInf (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type)
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type
forall a b. (a -> b) -> a -> b
$ TCMT IO Term -> NamesT (TCMT IO) Term
forall (m :: * -> *) a. Monad m => m a -> NamesT m a
cl TCMT IO Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primInterval) ((NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type)
-> NamesT (TCMT IO) Type)
-> (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type)
-> NamesT (TCMT IO) Type
forall a b. (a -> b) -> a -> b
$ \ NamesT (TCMT IO) Term
phi ->
(VerboseKey
-> NamesT (TCMT IO) Type
-> (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type)
-> NamesT (TCMT IO) Type
forall (m :: * -> *).
(MonadFail m, MonadAddContext m, MonadDebug m) =>
VerboseKey
-> NamesT m Type
-> (NamesT m Term -> NamesT m Type)
-> NamesT m Type
nPi' VerboseKey
"i" (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type
forall (m :: * -> *). Functor m => m Term -> m Type
elInf (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type)
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type
forall a b. (a -> b) -> a -> b
$ TCMT IO Term -> NamesT (TCMT IO) Term
forall (m :: * -> *) a. Monad m => m a -> NamesT m a
cl TCMT IO Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primInterval) ((NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type)
-> NamesT (TCMT IO) Type)
-> (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type)
-> NamesT (TCMT IO) Type
forall a b. (a -> b) -> a -> b
$ \ NamesT (TCMT IO) Term
i ->
VerboseKey
-> NamesT (TCMT IO) Term
-> (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type)
-> NamesT (TCMT IO) Type
forall (m :: * -> *).
(MonadAddContext m, HasBuiltins m, MonadDebug m) =>
VerboseKey
-> NamesT m Term
-> (NamesT m Term -> NamesT m Type)
-> NamesT m Type
pPi' VerboseKey
"o" NamesT (TCMT IO) Term
phi ((NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type)
-> NamesT (TCMT IO) Type)
-> (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type)
-> NamesT (TCMT IO) Type
forall a b. (a -> b) -> a -> b
$ \ NamesT (TCMT IO) Term
_ -> NamesT (TCMT IO) Type
rect) NamesT (TCMT IO) Type
-> NamesT (TCMT IO) Type -> NamesT (TCMT IO) Type
forall (tcm :: * -> *).
Monad tcm =>
tcm Type -> tcm Type -> tcm Type
-->
NamesT (TCMT IO) Type
rect NamesT (TCMT IO) Type
-> NamesT (TCMT IO) Type -> NamesT (TCMT IO) Type
forall (tcm :: * -> *).
Monad tcm =>
tcm Type -> tcm Type -> tcm Type
--> NamesT (TCMT IO) Type
rect
VerboseKey -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
VerboseKey -> Int -> TCMT IO Doc -> m ()
reportSDoc VerboseKey
"hcomp.rec" Int
20 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
forall a b. (a -> b) -> a -> b
$ Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Type
theType
VerboseKey -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
VerboseKey -> Int -> TCMT IO Doc -> m ()
reportSDoc VerboseKey
"hcomp.rec" Int
60 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
forall a b. (a -> b) -> a -> b
$ VerboseKey -> TCMT IO Doc
forall (m :: * -> *). Monad m => VerboseKey -> m Doc
text (VerboseKey -> TCMT IO Doc) -> VerboseKey -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ VerboseKey
"sort = " VerboseKey -> VerboseKey -> VerboseKey
forall a. [a] -> [a] -> [a]
++ Level' Term -> VerboseKey
forall a. Show a => a -> VerboseKey
show (LType -> Level' Term
lTypeLevel LType
rect)
TCM () -> TCM ()
forall a. TCM a -> TCM a
noMutualBlock (TCM () -> TCM ()) -> TCM () -> TCM ()
forall a b. (a -> b) -> a -> b
$ QName -> Definition -> TCM ()
addConstant QName
theName (Definition -> TCM ()) -> Definition -> TCM ()
forall a b. (a -> b) -> a -> b
$ (ArgInfo -> QName -> Type -> Defn -> Definition
defaultDefn ArgInfo
defaultArgInfo QName
theName Type
theType
(Defn
emptyFunction { funTerminates :: Maybe Bool
funTerminates = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True }))
{ defNoCompilation :: Bool
defNoCompilation = Bool
True }
TelV Tele (Dom Type)
gamma Type
rtype <- Type -> TCMT IO (TelV Type)
forall (m :: * -> *).
(MonadReduce m, MonadAddContext m) =>
Type -> m (TelV Type)
telView Type
theType
let
drect_gamma :: LType
drect_gamma = Int -> Substitution' Term
forall a. Int -> Substitution' a
raiseS (Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
gamma Int -> Int -> Int
forall a. Num a => a -> a -> a
- Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
delta) Substitution' Term -> LType -> LType
forall t a. Subst t a => Substitution' t -> a -> a
`applySubst` LType
rect
VerboseKey -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
VerboseKey -> Int -> TCMT IO Doc -> m ()
reportSDoc VerboseKey
"hcomp.rec" Int
60 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
forall a b. (a -> b) -> a -> b
$ VerboseKey -> TCMT IO Doc
forall (m :: * -> *). Monad m => VerboseKey -> m Doc
text (VerboseKey -> TCMT IO Doc) -> VerboseKey -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ VerboseKey
"sort = " VerboseKey -> VerboseKey -> VerboseKey
forall a. [a] -> [a] -> [a]
++ Level' Term -> VerboseKey
forall a. Show a => a -> VerboseKey
show (LType -> Level' Term
lTypeLevel LType
drect_gamma)
let
compTerm :: Term
compTerm = QName -> Elims -> Term
Def QName
theName [] Term -> [Arg Term] -> Term
forall t. Apply t => t -> [Arg Term] -> t
`apply` Tele (Dom Type) -> [Arg Term]
forall a t. DeBruijn a => Tele (Dom t) -> [Arg a]
teleArgs Tele (Dom Type)
gamma
the_phi :: Term
the_phi = Int -> Term
var Int
2
the_u :: Term
the_u = Int -> Term
var Int
1
the_u0 :: Term
the_u0 = Int -> Term
var Int
0
fillTerm :: Term
fillTerm = [VerboseKey] -> NamesT Fail Term -> Term
forall a. [VerboseKey] -> NamesT Fail a -> a
runNames [] (NamesT Fail Term -> Term) -> NamesT Fail Term -> Term
forall a b. (a -> b) -> a -> b
$ do
NamesT Fail Term
rect <- Term -> NamesT Fail (NamesT Fail Term)
forall (m :: * -> *) t a.
(MonadFail m, Subst t a) =>
a -> NamesT m (NamesT m a)
open (Term -> NamesT Fail (NamesT Fail Term))
-> (LType -> Term) -> LType -> NamesT Fail (NamesT Fail Term)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Type -> Term
forall t a. Type'' t a -> a
unEl (Type -> Term) -> (LType -> Type) -> LType -> Term
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LType -> Type
fromLType (LType -> NamesT Fail (NamesT Fail Term))
-> LType -> NamesT Fail (NamesT Fail Term)
forall a b. (a -> b) -> a -> b
$ LType
drect_gamma
NamesT Fail Term
lvl <- Term -> NamesT Fail (NamesT Fail Term)
forall (m :: * -> *) t a.
(MonadFail m, Subst t a) =>
a -> NamesT m (NamesT m a)
open (Term -> NamesT Fail (NamesT Fail Term))
-> (LType -> Term) -> LType -> NamesT Fail (NamesT Fail Term)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Level' Term -> Term
Level (Level' Term -> Term) -> (LType -> Level' Term) -> LType -> Term
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LType -> Level' Term
lTypeLevel (LType -> NamesT Fail (NamesT Fail Term))
-> LType -> NamesT Fail (NamesT Fail Term)
forall a b. (a -> b) -> a -> b
$ LType
drect_gamma
[NamesT Fail (Arg Term)]
params <- (Arg Term -> NamesT Fail (NamesT Fail (Arg Term)))
-> [Arg Term] -> NamesT Fail [NamesT Fail (Arg Term)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Arg Term -> NamesT Fail (NamesT Fail (Arg Term))
forall (m :: * -> *) t a.
(MonadFail m, Subst t a) =>
a -> NamesT m (NamesT m a)
open ([Arg Term] -> NamesT Fail [NamesT Fail (Arg Term)])
-> [Arg Term] -> NamesT Fail [NamesT Fail (Arg Term)]
forall a b. (a -> b) -> a -> b
$ Int -> [Arg Term] -> [Arg Term]
forall a. Int -> [a] -> [a]
take (Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
delta) ([Arg Term] -> [Arg Term]) -> [Arg Term] -> [Arg Term]
forall a b. (a -> b) -> a -> b
$ Tele (Dom Type) -> [Arg Term]
forall a t. DeBruijn a => Tele (Dom t) -> [Arg a]
teleArgs Tele (Dom Type)
gamma
[NamesT Fail Term
phi,NamesT Fail Term
w,NamesT Fail Term
w0] <- (Term -> NamesT Fail (NamesT Fail Term))
-> [Term] -> NamesT Fail [NamesT Fail Term]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Term -> NamesT Fail (NamesT Fail Term)
forall (m :: * -> *) t a.
(MonadFail m, Subst t a) =>
a -> NamesT m (NamesT m a)
open [Term
the_phi,Term
the_u,Term
the_u0]
VerboseKey
-> (NamesT Fail Term -> NamesT Fail Term) -> NamesT Fail Term
forall (m :: * -> *).
MonadFail m =>
VerboseKey -> (NamesT m Term -> NamesT m Term) -> NamesT m Term
lam VerboseKey
"i" ((NamesT Fail Term -> NamesT Fail Term) -> NamesT Fail Term)
-> (NamesT Fail Term -> NamesT Fail Term) -> NamesT Fail Term
forall a b. (a -> b) -> a -> b
$ \ NamesT Fail Term
i -> do
[Arg Term]
args <- [NamesT Fail (Arg Term)] -> NamesT Fail [Arg Term]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [NamesT Fail (Arg Term)]
params
Term
psi <- Term -> NamesT Fail Term
forall (f :: * -> *) a. Applicative f => a -> f a
pure Term
imax NamesT Fail Term -> NamesT Fail Term -> NamesT Fail Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> NamesT Fail Term
phi NamesT Fail Term -> NamesT Fail Term -> NamesT Fail Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> (Term -> NamesT Fail Term
forall (f :: * -> *) a. Applicative f => a -> f a
pure Term
ineg NamesT Fail Term -> NamesT Fail Term -> NamesT Fail Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> NamesT Fail Term
i)
Term
u <- VerboseKey
-> (NamesT Fail Term -> NamesT Fail Term) -> NamesT Fail Term
forall (m :: * -> *).
MonadFail m =>
VerboseKey -> (NamesT m Term -> NamesT m Term) -> NamesT m Term
lam VerboseKey
"j" (\ NamesT Fail Term
j -> Term -> NamesT Fail Term
forall (f :: * -> *) a. Applicative f => a -> f a
pure Term
por NamesT Fail Term -> NamesT Fail Term -> NamesT Fail Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<#> NamesT Fail Term
lvl
NamesT Fail Term -> NamesT Fail Term -> NamesT Fail Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> NamesT Fail Term
phi
NamesT Fail Term -> NamesT Fail Term -> NamesT Fail Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> (Term -> NamesT Fail Term
forall (f :: * -> *) a. Applicative f => a -> f a
pure Term
ineg NamesT Fail Term -> NamesT Fail Term -> NamesT Fail Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> NamesT Fail Term
i)
NamesT Fail Term -> NamesT Fail Term -> NamesT Fail Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<#> (VerboseKey
-> (NamesT Fail Term -> NamesT Fail Term) -> NamesT Fail Term
forall (m :: * -> *).
MonadFail m =>
VerboseKey -> (NamesT m Term -> NamesT m Term) -> NamesT m Term
lam VerboseKey
"_" ((NamesT Fail Term -> NamesT Fail Term) -> NamesT Fail Term)
-> (NamesT Fail Term -> NamesT Fail Term) -> NamesT Fail Term
forall a b. (a -> b) -> a -> b
$ \ NamesT Fail Term
o -> NamesT Fail Term
rect)
NamesT Fail Term -> NamesT Fail Term -> NamesT Fail Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> (NamesT Fail Term
w NamesT Fail Term -> NamesT Fail Term -> NamesT Fail Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> (Term -> NamesT Fail Term
forall (f :: * -> *) a. Applicative f => a -> f a
pure Term
imin NamesT Fail Term -> NamesT Fail Term -> NamesT Fail Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> NamesT Fail Term
i NamesT Fail Term -> NamesT Fail Term -> NamesT Fail Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> NamesT Fail Term
j))
NamesT Fail Term -> NamesT Fail Term -> NamesT Fail Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> (VerboseKey
-> (NamesT Fail Term -> NamesT Fail Term) -> NamesT Fail Term
forall (m :: * -> *).
MonadFail m =>
VerboseKey -> (NamesT m Term -> NamesT m Term) -> NamesT m Term
lam VerboseKey
"_" ((NamesT Fail Term -> NamesT Fail Term) -> NamesT Fail Term)
-> (NamesT Fail Term -> NamesT Fail Term) -> NamesT Fail Term
forall a b. (a -> b) -> a -> b
$ \ NamesT Fail Term
o -> NamesT Fail Term
w0)
)
Term
u0 <- NamesT Fail Term
w0
Term -> NamesT Fail Term
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Term -> NamesT Fail Term) -> Term -> NamesT Fail Term
forall a b. (a -> b) -> a -> b
$ QName -> Elims -> Term
Def QName
theName [] Term -> [Arg Term] -> Term
forall t. Apply t => t -> [Arg Term] -> t
`apply` ([Arg Term]
args [Arg Term] -> [Arg Term] -> [Arg Term]
forall a. [a] -> [a] -> [a]
++ [Term -> Arg Term
forall e. e -> Arg e
argN Term
psi, Term -> Arg Term
forall e. e -> Arg e
argN Term
u, Term -> Arg Term
forall e. e -> Arg e
argN Term
u0])
where
underArg :: (f b -> f a) -> f (Arg b) -> f (Arg a)
underArg f b -> f a
k f (Arg b)
m = ArgInfo -> a -> Arg a
forall e. ArgInfo -> e -> Arg e
Arg (ArgInfo -> a -> Arg a) -> f ArgInfo -> f (a -> Arg a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Arg b -> ArgInfo
forall e. Arg e -> ArgInfo
argInfo (Arg b -> ArgInfo) -> f (Arg b) -> f ArgInfo
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (Arg b)
m) f (a -> Arg a) -> f a -> f (Arg a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (f b -> f a
k (Arg b -> b
forall e. Arg e -> e
unArg (Arg b -> b) -> f (Arg b) -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (Arg b)
m))
clause_types :: [Dom' Term LType]
clause_types = [Term] -> Substitution' Term
forall a. DeBruijn a => [a] -> Substitution' a
parallelS [Term
compTerm Term -> QName -> Term
`applyProj` (Arg QName -> QName
forall e. Arg e -> e
unArg Arg QName
fn)
| Arg QName
fn <- [Arg QName] -> [Arg QName]
forall a. [a] -> [a]
reverse [Arg QName]
fns] Substitution' Term -> [Dom' Term LType] -> [Dom' Term LType]
forall t a. Subst t a => Substitution' t -> a -> a
`applySubst`
Tele (Dom' Term LType) -> [Dom' Term LType]
forall a. Subst Term a => Tele (Dom a) -> [Dom a]
flattenTel (Int -> Substitution' Term
forall a. Int -> Substitution' a
raiseS (Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
gamma Int -> Int -> Int
forall a. Num a => a -> a -> a
- Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
delta) Substitution' Term
-> Tele (Dom' Term LType) -> Tele (Dom' Term LType)
forall t a. Subst t a => Substitution' t -> a -> a
`applySubst` Tele (Dom' Term LType)
fsT)
fsT' :: Tele (Dom' Term LType)
fsT' = Int -> Substitution' Term
forall a. Int -> Substitution' a
raiseS ((Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
gamma Int -> Int -> Int
forall a. Num a => a -> a -> a
- Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
delta) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) Substitution' Term
-> Tele (Dom' Term LType) -> Tele (Dom' Term LType)
forall t a. Subst t a => Substitution' t -> a -> a
`applySubst` Tele (Dom' Term LType)
fsT
filled_types :: [Dom' Term LType]
filled_types = [Term] -> Substitution' Term
forall a. DeBruijn a => [a] -> Substitution' a
parallelS [Int -> Term -> Term
forall t a. Subst t a => Int -> a -> a
raise Int
1 Term
fillTerm Term -> [Arg Term] -> Term
forall t. Apply t => t -> [Arg Term] -> t
`apply` [Term -> Arg Term
forall e. e -> Arg e
argN (Term -> Arg Term) -> Term -> Arg Term
forall a b. (a -> b) -> a -> b
$ Int -> Term
var Int
0] Term -> QName -> Term
`applyProj` (Arg QName -> QName
forall e. Arg e -> e
unArg Arg QName
fn)
| Arg QName
fn <- [Arg QName] -> [Arg QName]
forall a. [a] -> [a]
reverse [Arg QName]
fns] Substitution' Term -> [Dom' Term LType] -> [Dom' Term LType]
forall t a. Subst t a => Substitution' t -> a -> a
`applySubst`
Tele (Dom' Term LType) -> [Dom' Term LType]
forall a. Subst Term a => Tele (Dom a) -> [Dom a]
flattenTel Tele (Dom' Term LType)
fsT'
NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term
comp <- do
let
imax :: tcm Term -> tcm Term -> tcm Term
imax tcm Term
i tcm Term
j = Term -> tcm Term
forall (f :: * -> *) a. Applicative f => a -> f a
pure Term
tIMax tcm Term -> tcm Term -> tcm Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> tcm Term
i tcm Term -> tcm Term -> tcm Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> tcm Term
j
let forward :: NamesT m Term
-> NamesT m Term -> NamesT m Term -> NamesT m Term -> NamesT m Term
forward NamesT m Term
la NamesT m Term
bA NamesT m Term
r NamesT m Term
u = Term -> NamesT m Term
forall (f :: * -> *) a. Applicative f => a -> f a
pure Term
transp NamesT m Term -> NamesT m Term -> NamesT m Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<#> (VerboseKey -> (NamesT m Term -> NamesT m Term) -> NamesT m Term
forall (m :: * -> *).
MonadFail m =>
VerboseKey -> (NamesT m Term -> NamesT m Term) -> NamesT m Term
lam VerboseKey
"i" ((NamesT m Term -> NamesT m Term) -> NamesT m Term)
-> (NamesT m Term -> NamesT m Term) -> NamesT m Term
forall a b. (a -> b) -> a -> b
$ \ NamesT m Term
i -> NamesT m Term
la NamesT m Term -> NamesT m Term -> NamesT m Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> (NamesT m Term
i NamesT m Term -> NamesT m Term -> NamesT m Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
`imax` NamesT m Term
r))
NamesT m Term -> NamesT m Term -> NamesT m Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> (VerboseKey -> (NamesT m Term -> NamesT m Term) -> NamesT m Term
forall (m :: * -> *).
MonadFail m =>
VerboseKey -> (NamesT m Term -> NamesT m Term) -> NamesT m Term
lam VerboseKey
"i" ((NamesT m Term -> NamesT m Term) -> NamesT m Term)
-> (NamesT m Term -> NamesT m Term) -> NamesT m Term
forall a b. (a -> b) -> a -> b
$ \ NamesT m Term
i -> NamesT m Term
bA NamesT m Term -> NamesT m Term -> NamesT m Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> (NamesT m Term
i NamesT m Term -> NamesT m Term -> NamesT m Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
`imax` NamesT m Term
r))
NamesT m Term -> NamesT m Term -> NamesT m Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> NamesT m Term
r
NamesT m Term -> NamesT m Term -> NamesT m Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> NamesT m Term
u
(NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term)
-> TCMT
IO
(NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term)
forall (m :: * -> *) a. Monad m => a -> m a
return ((NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term)
-> TCMT
IO
(NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term))
-> (NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term)
-> TCMT
IO
(NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term)
forall a b. (a -> b) -> a -> b
$ \ NamesT Fail Term
la NamesT Fail Term
bA NamesT Fail Term
phi NamesT Fail Term
u NamesT Fail Term
u0 ->
Term -> NamesT Fail Term
forall (f :: * -> *) a. Applicative f => a -> f a
pure Term
hcomp NamesT Fail Term -> NamesT Fail Term -> NamesT Fail Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<#> (NamesT Fail Term
la NamesT Fail Term -> NamesT Fail Term -> NamesT Fail Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> Term -> NamesT Fail Term
forall (f :: * -> *) a. Applicative f => a -> f a
pure Term
io) NamesT Fail Term -> NamesT Fail Term -> NamesT Fail Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<#> (NamesT Fail Term
bA NamesT Fail Term -> NamesT Fail Term -> NamesT Fail Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> Term -> NamesT Fail Term
forall (f :: * -> *) a. Applicative f => a -> f a
pure Term
io) NamesT Fail Term -> NamesT Fail Term -> NamesT Fail Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<#> NamesT Fail Term
phi
NamesT Fail Term -> NamesT Fail Term -> NamesT Fail Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> (VerboseKey
-> (NamesT Fail Term -> NamesT Fail Term) -> NamesT Fail Term
forall (m :: * -> *).
MonadFail m =>
VerboseKey -> (NamesT m Term -> NamesT m Term) -> NamesT m Term
lam VerboseKey
"i" ((NamesT Fail Term -> NamesT Fail Term) -> NamesT Fail Term)
-> (NamesT Fail Term -> NamesT Fail Term) -> NamesT Fail Term
forall a b. (a -> b) -> a -> b
$ \ NamesT Fail Term
i -> VerboseKey
-> (NamesT Fail Term -> NamesT Fail Term) -> NamesT Fail Term
forall (m :: * -> *).
MonadFail m =>
VerboseKey -> (NamesT m Term -> NamesT m Term) -> NamesT m Term
ilam VerboseKey
"o" ((NamesT Fail Term -> NamesT Fail Term) -> NamesT Fail Term)
-> (NamesT Fail Term -> NamesT Fail Term) -> NamesT Fail Term
forall a b. (a -> b) -> a -> b
$ \ NamesT Fail Term
o ->
NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term
forall (m :: * -> *).
MonadFail m =>
NamesT m Term
-> NamesT m Term -> NamesT m Term -> NamesT m Term -> NamesT m Term
forward NamesT Fail Term
la NamesT Fail Term
bA NamesT Fail Term
i (NamesT Fail Term
u NamesT Fail Term -> NamesT Fail Term -> NamesT Fail Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> NamesT Fail Term
i NamesT Fail Term -> NamesT Fail Term -> NamesT Fail Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<..> NamesT Fail Term
o))
NamesT Fail Term -> NamesT Fail Term -> NamesT Fail Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term
forall (m :: * -> *).
MonadFail m =>
NamesT m Term
-> NamesT m Term -> NamesT m Term -> NamesT m Term -> NamesT m Term
forward NamesT Fail Term
la NamesT Fail Term
bA (Term -> NamesT Fail Term
forall (f :: * -> *) a. Applicative f => a -> f a
pure Term
iz) NamesT Fail Term
u0
let
mkBody :: (Arg QName, Dom' t LType) -> m Term
mkBody (Arg QName
fname, Dom' t LType
filled_ty') = do
let
proj :: f Term -> f Term
proj f Term
t = (Term -> QName -> Term
`applyProj` Arg QName -> QName
forall e. Arg e -> e
unArg Arg QName
fname) (Term -> Term) -> f Term -> f Term
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f Term
t
filled_ty :: Term
filled_ty = ArgInfo -> Abs Term -> Term
Lam ArgInfo
defaultArgInfo (VerboseKey -> Term -> Abs Term
forall a. VerboseKey -> a -> Abs a
Abs VerboseKey
"i" (Term -> Abs Term) -> Term -> Abs Term
forall a b. (a -> b) -> a -> b
$ (Type -> Term
forall t a. Type'' t a -> a
unEl (Type -> Term) -> (Dom' t LType -> Type) -> Dom' t LType -> Term
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LType -> Type
fromLType (LType -> Type) -> (Dom' t LType -> LType) -> Dom' t LType -> Type
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dom' t LType -> LType
forall t e. Dom' t e -> e
unDom) Dom' t LType
filled_ty')
Level' Term
l <- Level' Term -> m (Level' Term)
forall a (m :: * -> *). (Reduce a, MonadReduce m) => a -> m a
reduce (Level' Term -> m (Level' Term)) -> Level' Term -> m (Level' Term)
forall a b. (a -> b) -> a -> b
$ LType -> Level' Term
lTypeLevel (LType -> Level' Term) -> LType -> Level' Term
forall a b. (a -> b) -> a -> b
$ Dom' t LType -> LType
forall t e. Dom' t e -> e
unDom Dom' t LType
filled_ty'
let lvl :: Term
lvl = ArgInfo -> Abs Term -> Term
Lam ArgInfo
defaultArgInfo (VerboseKey -> Term -> Abs Term
forall a. VerboseKey -> a -> Abs a
Abs VerboseKey
"i" (Term -> Abs Term) -> Term -> Abs Term
forall a b. (a -> b) -> a -> b
$ Level' Term -> Term
Level Level' Term
l)
Term -> m Term
forall (m :: * -> *) a. Monad m => a -> m a
return (Term -> m Term) -> Term -> m Term
forall a b. (a -> b) -> a -> b
$ [VerboseKey] -> NamesT Fail Term -> Term
forall a. [VerboseKey] -> NamesT Fail a -> a
runNames [] (NamesT Fail Term -> Term) -> NamesT Fail Term -> Term
forall a b. (a -> b) -> a -> b
$ do
NamesT Fail Term
lvl <- Term -> NamesT Fail (NamesT Fail Term)
forall (m :: * -> *) t a.
(MonadFail m, Subst t a) =>
a -> NamesT m (NamesT m a)
open Term
lvl
[NamesT Fail Term
phi,NamesT Fail Term
w,NamesT Fail Term
w0] <- (Term -> NamesT Fail (NamesT Fail Term))
-> [Term] -> NamesT Fail [NamesT Fail Term]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Term -> NamesT Fail (NamesT Fail Term)
forall (m :: * -> *) t a.
(MonadFail m, Subst t a) =>
a -> NamesT m (NamesT m a)
open [Term
the_phi,Term
the_u,Term
the_u0]
NamesT Fail Term
filled_ty <- Term -> NamesT Fail (NamesT Fail Term)
forall (m :: * -> *) t a.
(MonadFail m, Subst t a) =>
a -> NamesT m (NamesT m a)
open Term
filled_ty
NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term
-> NamesT Fail Term
comp NamesT Fail Term
lvl
NamesT Fail Term
filled_ty
NamesT Fail Term
phi
(VerboseKey
-> (NamesT Fail Term -> NamesT Fail Term) -> NamesT Fail Term
forall (m :: * -> *).
MonadFail m =>
VerboseKey -> (NamesT m Term -> NamesT m Term) -> NamesT m Term
lam VerboseKey
"i" ((NamesT Fail Term -> NamesT Fail Term) -> NamesT Fail Term)
-> (NamesT Fail Term -> NamesT Fail Term) -> NamesT Fail Term
forall a b. (a -> b) -> a -> b
$ \ NamesT Fail Term
i -> VerboseKey
-> (NamesT Fail Term -> NamesT Fail Term) -> NamesT Fail Term
forall (m :: * -> *).
MonadFail m =>
VerboseKey -> (NamesT m Term -> NamesT m Term) -> NamesT m Term
lam VerboseKey
"o" ((NamesT Fail Term -> NamesT Fail Term) -> NamesT Fail Term)
-> (NamesT Fail Term -> NamesT Fail Term) -> NamesT Fail Term
forall a b. (a -> b) -> a -> b
$ \ NamesT Fail Term
o -> NamesT Fail Term -> NamesT Fail Term
forall (f :: * -> *). Functor f => f Term -> f Term
proj (NamesT Fail Term -> NamesT Fail Term)
-> NamesT Fail Term -> NamesT Fail Term
forall a b. (a -> b) -> a -> b
$ NamesT Fail Term
w NamesT Fail Term -> NamesT Fail Term -> NamesT Fail Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> NamesT Fail Term
i NamesT Fail Term -> NamesT Fail Term -> NamesT Fail Term
forall (tcm :: * -> *).
Monad tcm =>
tcm Term -> tcm Term -> tcm Term
<@> NamesT Fail Term
o)
(NamesT Fail Term -> NamesT Fail Term
forall (f :: * -> *). Functor f => f Term -> f Term
proj NamesT Fail Term
w0)
VerboseKey -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
VerboseKey -> Int -> TCMT IO Doc -> m ()
reportSDoc VerboseKey
"hcomp.rec" Int
60 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
forall a b. (a -> b) -> a -> b
$ VerboseKey -> TCMT IO Doc
forall (m :: * -> *). Monad m => VerboseKey -> m Doc
text (VerboseKey -> TCMT IO Doc) -> VerboseKey -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ VerboseKey
"filled_types sorts:" VerboseKey -> VerboseKey -> VerboseKey
forall a. [a] -> [a] -> [a]
++ [Sort] -> VerboseKey
forall a. Show a => a -> VerboseKey
show ((Dom' Term LType -> Sort) -> [Dom' Term LType] -> [Sort]
forall a b. (a -> b) -> [a] -> [b]
map (Type -> Sort
forall a. LensSort a => a -> Sort
getSort (Type -> Sort)
-> (Dom' Term LType -> Type) -> Dom' Term LType -> Sort
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LType -> Type
fromLType (LType -> Type)
-> (Dom' Term LType -> LType) -> Dom' Term LType -> Type
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dom' Term LType -> LType
forall t e. Dom' t e -> e
unDom) [Dom' Term LType]
filled_types)
[Term]
bodys <- ((Arg QName, Dom' Term LType) -> TCMT IO Term)
-> [(Arg QName, Dom' Term LType)] -> TCMT IO [Term]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Arg QName, Dom' Term LType) -> TCMT IO Term
forall (m :: * -> *) t.
MonadReduce m =>
(Arg QName, Dom' t LType) -> m Term
mkBody ([Arg QName] -> [Dom' Term LType] -> [(Arg QName, Dom' Term LType)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Arg QName]
fns [Dom' Term LType]
filled_types)
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
-> TCMT
IO
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
forall (m :: * -> *) a. Monad m => a -> m a
return (((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
-> TCMT
IO
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term))
-> ((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
-> TCMT
IO
((QName, Tele (Dom Type), Type, [Dom Type], [Term]),
Substitution' Term)
forall a b. (a -> b) -> a -> b
$ ((QName
theName, Tele (Dom Type)
gamma, Type
rtype, (Dom' Term LType -> Dom Type) -> [Dom' Term LType] -> [Dom Type]
forall a b. (a -> b) -> [a] -> [b]
map ((LType -> Type) -> Dom' Term LType -> Dom Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap LType -> Type
fromLType) [Dom' Term LType]
clause_types, [Term]
bodys),Substitution' Term
forall a. Substitution' a
IdS)
getGeneralizedParameters :: Set Name -> QName -> TCM [Maybe Name]
getGeneralizedParameters :: Set Name -> QName -> TCM [Maybe Name]
getGeneralizedParameters Set Name
gpars QName
name | Set Name -> Bool
forall a. Set a -> Bool
Set.null Set Name
gpars = [Maybe Name] -> TCM [Maybe Name]
forall (m :: * -> *) a. Monad m => a -> m a
return []
getGeneralizedParameters Set Name
gpars QName
name = do
let inscope :: Name -> f Name
inscope Name
x = Name
x Name -> f () -> f Name
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Bool -> f ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Name -> Set Name -> Bool
forall a. Ord a => a -> Set a -> Bool
Set.member Name
x Set Name
gpars)
(Maybe Name -> Maybe Name) -> [Maybe Name] -> [Maybe Name]
forall a b. (a -> b) -> [a] -> [b]
map (Maybe Name -> (Name -> Maybe Name) -> Maybe Name
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Name -> Maybe Name
forall (f :: * -> *). Alternative f => Name -> f Name
inscope) ([Maybe Name] -> [Maybe Name])
-> (Definition -> [Maybe Name]) -> Definition -> [Maybe Name]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Definition -> [Maybe Name]
defGeneralizedParams (Definition -> [Maybe Name])
-> TCMT IO Definition -> TCM [Maybe Name]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Definition -> TCMT IO Definition
forall (m :: * -> *).
(Functor m, HasConstInfo m, HasOptions m, ReadTCState m,
MonadTCEnv m, MonadDebug m) =>
Definition -> m Definition
instantiateDef (Definition -> TCMT IO Definition)
-> TCMT IO Definition -> TCMT IO Definition
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< QName -> TCMT IO Definition
forall (m :: * -> *). HasConstInfo m => QName -> m Definition
getConstInfo QName
name)
bindGeneralizedParameters :: [Maybe Name] -> Type -> (Telescope -> Type -> TCM a) -> TCM a
bindGeneralizedParameters :: [Maybe Name] -> Type -> (Tele (Dom Type) -> Type -> TCM a) -> TCM a
bindGeneralizedParameters [] Type
t Tele (Dom Type) -> Type -> TCM a
ret = Tele (Dom Type) -> Type -> TCM a
ret Tele (Dom Type)
forall a. Tele a
EmptyTel Type
t
bindGeneralizedParameters (Maybe Name
name : [Maybe Name]
names) Type
t Tele (Dom Type) -> Type -> TCM a
ret =
case Type -> Term
forall t a. Type'' t a -> a
unEl Type
t of
Pi Dom Type
a Abs Type
b -> TCM a -> TCM a
forall a. TCM a -> TCM a
ext (TCM a -> TCM a) -> TCM a -> TCM a
forall a b. (a -> b) -> a -> b
$ [Maybe Name] -> Type -> (Tele (Dom Type) -> Type -> TCM a) -> TCM a
forall a.
[Maybe Name] -> Type -> (Tele (Dom Type) -> Type -> TCM a) -> TCM a
bindGeneralizedParameters [Maybe Name]
names (Abs Type -> Type
forall a. Abs a -> a
unAbs Abs Type
b) ((Tele (Dom Type) -> Type -> TCM a) -> TCM a)
-> (Tele (Dom Type) -> Type -> TCM a) -> TCM a
forall a b. (a -> b) -> a -> b
$ \ Tele (Dom Type)
tel Type
t -> Tele (Dom Type) -> Type -> TCM a
ret (Dom Type -> Abs (Tele (Dom Type)) -> Tele (Dom Type)
forall a. a -> Abs (Tele a) -> Tele a
ExtendTel Dom Type
a (Tele (Dom Type)
tel Tele (Dom Type) -> Abs Type -> Abs (Tele (Dom Type))
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Abs Type
b)) Type
t
where
ext :: TCMT IO a -> TCMT IO a
ext | Just Name
x <- Maybe Name
name = (Name, Dom Type) -> TCMT IO a -> TCMT IO a
forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
addContext (Name
x, Dom Type
a)
| Bool
otherwise = (VerboseKey, Dom Type) -> TCMT IO a -> TCMT IO a
forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
addContext (Abs Type -> VerboseKey
forall a. Abs a -> VerboseKey
absName Abs Type
b, Dom Type
a)
Term
_ -> TCM a
forall a. HasCallStack => a
__IMPOSSIBLE__
bindParameters
:: Int
-> [A.LamBinding]
-> Type
-> (Telescope -> Type -> TCM a)
-> TCM a
bindParameters :: Int
-> [LamBinding]
-> Type
-> (Tele (Dom Type) -> Type -> TCM a)
-> TCM a
bindParameters Int
0 [] Type
a Tele (Dom Type) -> Type -> TCM a
ret = Tele (Dom Type) -> Type -> TCM a
ret Tele (Dom Type)
forall a. Tele a
EmptyTel Type
a
bindParameters Int
0 (LamBinding
par : [LamBinding]
_) Type
_ Tele (Dom Type) -> Type -> TCM a
_ = LamBinding -> TCM a -> TCM a
forall (tcm :: * -> *) x a.
(MonadTCM tcm, ReadTCState tcm, MonadDebug tcm, HasRange x) =>
x -> tcm a -> tcm a
setCurrentRange LamBinding
par (TCM a -> TCM a) -> TCM a -> TCM a
forall a b. (a -> b) -> a -> b
$
TypeError -> TCM a
forall (m :: * -> *) a.
(MonadTCEnv m, ReadTCState m, MonadError TCErr m) =>
TypeError -> m a
typeError (TypeError -> TCM a) -> (Doc -> TypeError) -> Doc -> TCM a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> TypeError
GenericDocError (Doc -> TCM a) -> TCMT IO Doc -> TCM a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< do
VerboseKey -> TCMT IO Doc
forall (m :: * -> *). Monad m => VerboseKey -> m Doc
text VerboseKey
"Unexpected parameter" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> LamBinding -> TCMT IO Doc
forall c a (m :: * -> *).
(Pretty c, ToConcrete a c, MonadAbsToCon m) =>
a -> m Doc
prettyA LamBinding
par
bindParameters Int
npars [] Type
t Tele (Dom Type) -> Type -> TCM a
ret =
case Type -> Term
forall t a. Type'' t a -> a
unEl Type
t of
Pi Dom Type
a Abs Type
b | Bool -> Bool
not (Dom Type -> Bool
forall a. LensHiding a => a -> Bool
visible Dom Type
a) -> do
Name
x <- VerboseKey -> TCMT IO Name
forall a (m :: * -> *).
(FreshName a, MonadFresh NameId m) =>
a -> m Name
freshName_ (Abs Type -> VerboseKey
forall a. Abs a -> VerboseKey
absName Abs Type
b)
Int
-> [LamBinding]
-> Name
-> Dom Type
-> Abs Type
-> (Tele (Dom Type) -> Type -> TCM a)
-> TCM a
forall a.
Int
-> [LamBinding]
-> Name
-> Dom Type
-> Abs Type
-> (Tele (Dom Type) -> Type -> TCM a)
-> TCM a
bindParameter Int
npars [] Name
x Dom Type
a Abs Type
b Tele (Dom Type) -> Type -> TCM a
ret
| Bool
otherwise ->
TypeError -> TCM a
forall (m :: * -> *) a.
(MonadTCEnv m, ReadTCState m, MonadError TCErr m) =>
TypeError -> m a
typeError (TypeError -> TCM a) -> (Doc -> TypeError) -> Doc -> TCM a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> TypeError
GenericDocError (Doc -> TCM a) -> TCMT IO Doc -> TCM a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
[TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *). Monad m => [m Doc] -> m Doc
sep [ TCMT IO Doc
"Expected binding for parameter"
, VerboseKey -> TCMT IO Doc
forall (m :: * -> *). Monad m => VerboseKey -> m Doc
text (Abs Type -> VerboseKey
forall a. Abs a -> VerboseKey
absName Abs Type
b) TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> VerboseKey -> TCMT IO Doc
forall (m :: * -> *). Monad m => VerboseKey -> m Doc
text VerboseKey
":" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM (Dom Type -> Type
forall t e. Dom' t e -> e
unDom Dom Type
a) ]
Term
_ -> TCM a
forall a. HasCallStack => a
__IMPOSSIBLE__
bindParameters Int
npars par :: [LamBinding]
par@(A.DomainFull (A.TBind Range
_ TacticAttr
_ [NamedArg Binder]
xs Expr
e) : [LamBinding]
bs) Type
a Tele (Dom Type) -> Type -> TCM a
ret =
[LamBinding] -> TCM a -> TCM a
forall (tcm :: * -> *) x a.
(MonadTCM tcm, ReadTCState tcm, MonadDebug tcm, HasRange x) =>
x -> tcm a -> tcm a
setCurrentRange [LamBinding]
par (TCM a -> TCM a) -> TCM a -> TCM a
forall a b. (a -> b) -> a -> b
$
TypeError -> TCM a
forall (m :: * -> *) a.
(MonadTCEnv m, ReadTCState m, MonadError TCErr m) =>
TypeError -> m a
typeError (TypeError -> TCM a) -> (Doc -> TypeError) -> Doc -> TCM a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> TypeError
GenericDocError (Doc -> TCM a) -> TCMT IO Doc -> TCM a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< do
let s :: VerboseKey
s | [NamedArg Binder] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [NamedArg Binder]
xs Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
1 = VerboseKey
"s"
| Bool
otherwise = VerboseKey
""
VerboseKey -> TCMT IO Doc
forall (m :: * -> *). Monad m => VerboseKey -> m Doc
text (VerboseKey
"Unexpected type signature for parameter" VerboseKey -> VerboseKey -> VerboseKey
forall a. [a] -> [a] -> [a]
++ VerboseKey
s) TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *). Monad m => [m Doc] -> m Doc
sep ((NamedArg Binder -> TCMT IO Doc)
-> [NamedArg Binder] -> [TCMT IO Doc]
forall a b. (a -> b) -> [a] -> [b]
map NamedArg Binder -> TCMT IO Doc
forall c a (m :: * -> *).
(Pretty c, ToConcrete a c, MonadAbsToCon m) =>
a -> m Doc
prettyA [NamedArg Binder]
xs)
bindParameters Int
_ (A.DomainFull A.TLet{} : [LamBinding]
_) Type
_ Tele (Dom Type) -> Type -> TCM a
_ = TCM a
forall a. HasCallStack => a
__IMPOSSIBLE__
bindParameters Int
_ (par :: LamBinding
par@(A.DomainFree TacticAttr
_ NamedArg Binder
arg) : [LamBinding]
ps) Type
_ Tele (Dom Type) -> Type -> TCM a
_
| NamedArg Binder -> Modality
forall a. LensModality a => a -> Modality
getModality NamedArg Binder
arg Modality -> Modality -> Bool
forall a. Eq a => a -> a -> Bool
/= Modality
defaultModality = LamBinding -> TCM a -> TCM a
forall (tcm :: * -> *) x a.
(MonadTCM tcm, ReadTCState tcm, MonadDebug tcm, HasRange x) =>
x -> tcm a -> tcm a
setCurrentRange LamBinding
par (TCM a -> TCM a) -> TCM a -> TCM a
forall a b. (a -> b) -> a -> b
$
TypeError -> TCM a
forall (m :: * -> *) a.
(MonadTCEnv m, ReadTCState m, MonadError TCErr m) =>
TypeError -> m a
typeError (TypeError -> TCM a) -> (Doc -> TypeError) -> Doc -> TCM a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> TypeError
GenericDocError (Doc -> TCM a) -> TCMT IO Doc -> TCM a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< do
VerboseKey -> TCMT IO Doc
forall (m :: * -> *). Monad m => VerboseKey -> m Doc
text VerboseKey
"Unexpected modality/relevance annotation in" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> LamBinding -> TCMT IO Doc
forall c a (m :: * -> *).
(Pretty c, ToConcrete a c, MonadAbsToCon m) =>
a -> m Doc
prettyA LamBinding
par
bindParameters Int
npars ps0 :: [LamBinding]
ps0@(par :: LamBinding
par@(A.DomainFree TacticAttr
_ NamedArg Binder
arg) : [LamBinding]
ps) Type
t Tele (Dom Type) -> Type -> TCM a
ret = do
let x :: Binder
x = NamedArg Binder -> Binder
forall a. NamedArg a -> a
namedArg NamedArg Binder
arg
TelV Tele (Dom Type)
tel Type
_ = Type -> TelV Type
telView' Type
t
case NamedArg Binder
-> [Dom' Term (VerboseKey, Type)] -> ImplicitInsertion
forall e a. NamedArg e -> [Dom a] -> ImplicitInsertion
insertImplicit NamedArg Binder
arg ([Dom' Term (VerboseKey, Type)] -> ImplicitInsertion)
-> [Dom' Term (VerboseKey, Type)] -> ImplicitInsertion
forall a b. (a -> b) -> a -> b
$ Tele (Dom Type) -> [Dom' Term (VerboseKey, Type)]
forall t. Tele (Dom t) -> [Dom (VerboseKey, t)]
telToList Tele (Dom Type)
tel of
ImplicitInsertion
NoInsertNeeded -> [LamBinding] -> Name -> TCM a
continue [LamBinding]
ps (Name -> TCM a) -> Name -> TCM a
forall a b. (a -> b) -> a -> b
$ BindName -> Name
A.unBind (BindName -> Name) -> BindName -> Name
forall a b. (a -> b) -> a -> b
$ Binder -> BindName
forall a. Binder' a -> a
A.binderName Binder
x
ImpInsert [Dom ()]
_ -> [LamBinding] -> Name -> TCM a
continue [LamBinding]
ps0 (Name -> TCM a) -> TCMT IO Name -> TCM a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< VerboseKey -> TCMT IO Name
forall a (m :: * -> *).
(FreshName a, MonadFresh NameId m) =>
a -> m Name
freshName_ (Abs Type -> VerboseKey
forall a. Abs a -> VerboseKey
absName Abs Type
b)
ImplicitInsertion
BadImplicits -> LamBinding -> TCM a -> TCM a
forall (tcm :: * -> *) x a.
(MonadTCM tcm, ReadTCState tcm, MonadDebug tcm, HasRange x) =>
x -> tcm a -> tcm a
setCurrentRange LamBinding
par (TCM a -> TCM a) -> TCM a -> TCM a
forall a b. (a -> b) -> a -> b
$
TypeError -> TCM a
forall (m :: * -> *) a.
(MonadTCEnv m, ReadTCState m, MonadError TCErr m) =>
TypeError -> m a
typeError (TypeError -> TCM a) -> (Doc -> TypeError) -> Doc -> TCM a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> TypeError
GenericDocError (Doc -> TCM a) -> TCMT IO Doc -> TCM a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< do
VerboseKey -> TCMT IO Doc
forall (m :: * -> *). Monad m => VerboseKey -> m Doc
text VerboseKey
"Unexpected parameter" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> LamBinding -> TCMT IO Doc
forall c a (m :: * -> *).
(Pretty c, ToConcrete a c, MonadAbsToCon m) =>
a -> m Doc
prettyA LamBinding
par
NoSuchName VerboseKey
x -> LamBinding -> TCM a -> TCM a
forall (tcm :: * -> *) x a.
(MonadTCM tcm, ReadTCState tcm, MonadDebug tcm, HasRange x) =>
x -> tcm a -> tcm a
setCurrentRange LamBinding
par (TCM a -> TCM a) -> TCM a -> TCM a
forall a b. (a -> b) -> a -> b
$
TypeError -> TCM a
forall (m :: * -> *) a.
(MonadTCEnv m, ReadTCState m, MonadError TCErr m) =>
TypeError -> m a
typeError (TypeError -> TCM a) -> (Doc -> TypeError) -> Doc -> TCM a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> TypeError
GenericDocError (Doc -> TCM a) -> TCMT IO Doc -> TCM a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< do
VerboseKey -> TCMT IO Doc
forall (m :: * -> *). Monad m => VerboseKey -> m Doc
text (VerboseKey
"No parameter of name " VerboseKey -> VerboseKey -> VerboseKey
forall a. [a] -> [a] -> [a]
++ VerboseKey
x)
where
Pi dom :: Dom Type
dom@(Dom{domInfo :: forall t e. Dom' t e -> ArgInfo
domInfo = ArgInfo
info', unDom :: forall t e. Dom' t e -> e
unDom = Type
a}) Abs Type
b = Type -> Term
forall t a. Type'' t a -> a
unEl Type
t
continue :: [LamBinding] -> Name -> TCM a
continue [LamBinding]
ps Name
x = Int
-> [LamBinding]
-> Name
-> Dom Type
-> Abs Type
-> (Tele (Dom Type) -> Type -> TCM a)
-> TCM a
forall a.
Int
-> [LamBinding]
-> Name
-> Dom Type
-> Abs Type
-> (Tele (Dom Type) -> Type -> TCM a)
-> TCM a
bindParameter Int
npars [LamBinding]
ps Name
x Dom Type
dom Abs Type
b Tele (Dom Type) -> Type -> TCM a
ret
bindParameter :: Int -> [A.LamBinding] -> Name -> Dom Type -> Abs Type -> (Telescope -> Type -> TCM a) -> TCM a
bindParameter :: Int
-> [LamBinding]
-> Name
-> Dom Type
-> Abs Type
-> (Tele (Dom Type) -> Type -> TCM a)
-> TCM a
bindParameter Int
npars [LamBinding]
ps Name
x Dom Type
a Abs Type
b Tele (Dom Type) -> Type -> TCM a
ret =
(Name, Dom Type) -> TCM a -> TCM a
forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
addContext (Name
x, Dom Type
a) (TCM a -> TCM a) -> TCM a -> TCM a
forall a b. (a -> b) -> a -> b
$
Int
-> [LamBinding]
-> Type
-> (Tele (Dom Type) -> Type -> TCM a)
-> TCM a
forall a.
Int
-> [LamBinding]
-> Type
-> (Tele (Dom Type) -> Type -> TCM a)
-> TCM a
bindParameters (Int
npars Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) [LamBinding]
ps (Abs Type -> Type
forall t a. Subst t a => Abs a -> a
absBody Abs Type
b) ((Tele (Dom Type) -> Type -> TCM a) -> TCM a)
-> (Tele (Dom Type) -> Type -> TCM a) -> TCM a
forall a b. (a -> b) -> a -> b
$ \ Tele (Dom Type)
tel Type
s ->
Tele (Dom Type) -> Type -> TCM a
ret (Dom Type -> Abs (Tele (Dom Type)) -> Tele (Dom Type)
forall a. a -> Abs (Tele a) -> Tele a
ExtendTel Dom Type
a (Abs (Tele (Dom Type)) -> Tele (Dom Type))
-> Abs (Tele (Dom Type)) -> Tele (Dom Type)
forall a b. (a -> b) -> a -> b
$ VerboseKey -> Tele (Dom Type) -> Abs (Tele (Dom Type))
forall a. VerboseKey -> a -> Abs a
Abs (Name -> VerboseKey
nameToArgName Name
x) Tele (Dom Type)
tel) Type
s
fitsIn :: UniverseCheck -> [IsForced] -> Type -> Sort -> TCM Int
fitsIn :: UniverseCheck -> [IsForced] -> Type -> Sort -> TCMT IO Int
fitsIn UniverseCheck
uc [IsForced]
forceds Type
t Sort
s = do
VerboseKey -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
VerboseKey -> Int -> TCMT IO Doc -> m ()
reportSDoc VerboseKey
"tc.data.fits" Int
10 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
forall a b. (a -> b) -> a -> b
$
[TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *). Monad m => [m Doc] -> m Doc
sep [ TCMT IO Doc
"does" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Type
t
, TCMT IO Doc
"of sort" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Sort -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM (Type -> Sort
forall a. LensSort a => a -> Sort
getSort Type
t)
, TCMT IO Doc
"fit in" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Sort -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Sort
s TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCMT IO Doc
"?"
]
Maybe (Bool, Dom Type, Abs Type)
vt <- do
Either (Dom Type, Abs Type) Type
t <- Type -> TCMT IO (Either (Dom Type, Abs Type) Type)
forall (m :: * -> *).
(MonadReduce m, HasBuiltins m) =>
Type -> m (Either (Dom Type, Abs Type) Type)
pathViewAsPi Type
t
Maybe (Bool, Dom Type, Abs Type)
-> TCMT IO (Maybe (Bool, Dom Type, Abs Type))
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (Bool, Dom Type, Abs Type)
-> TCMT IO (Maybe (Bool, Dom Type, Abs Type)))
-> Maybe (Bool, Dom Type, Abs Type)
-> TCMT IO (Maybe (Bool, Dom Type, Abs Type))
forall a b. (a -> b) -> a -> b
$ case Either (Dom Type, Abs Type) Type
t of
Left (Dom Type
a,Abs Type
b) -> (Bool, Dom Type, Abs Type) -> Maybe (Bool, Dom Type, Abs Type)
forall a. a -> Maybe a
Just (Bool
True ,Dom Type
a,Abs Type
b)
Right (El Sort
_ Term
t) | Pi Dom Type
a Abs Type
b <- Term
t
-> (Bool, Dom Type, Abs Type) -> Maybe (Bool, Dom Type, Abs Type)
forall a. a -> Maybe a
Just (Bool
False,Dom Type
a,Abs Type
b)
Either (Dom Type, Abs Type) Type
_ -> Maybe (Bool, Dom Type, Abs Type)
forall a. Maybe a
Nothing
case Maybe (Bool, Dom Type, Abs Type)
vt of
Just (Bool
isPath, Dom Type
dom, Abs Type
b) -> do
Bool
withoutK <- TCMT IO Bool
forall (m :: * -> *). HasOptions m => m Bool
withoutKOption
let (IsForced
forced,[IsForced]
forceds') = [IsForced] -> (IsForced, [IsForced])
nextIsForced [IsForced]
forceds
Bool -> TCM () -> TCM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (IsForced -> Bool
isForced IsForced
forced Bool -> Bool -> Bool
&& Bool -> Bool
not Bool
withoutK) (TCM () -> TCM ()) -> TCM () -> TCM ()
forall a b. (a -> b) -> a -> b
$ do
Sort
sa <- Sort -> TCMT IO Sort
forall a (m :: * -> *). (Reduce a, MonadReduce m) => a -> m a
reduce (Sort -> TCMT IO Sort) -> Sort -> TCMT IO Sort
forall a b. (a -> b) -> a -> b
$ Dom Type -> Sort
forall a. LensSort a => a -> Sort
getSort Dom Type
dom
Bool -> TCM () -> TCM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Bool
isPath Bool -> Bool -> Bool
|| UniverseCheck
uc UniverseCheck -> UniverseCheck -> Bool
forall a. Eq a => a -> a -> Bool
== UniverseCheck
NoUniverseCheck Bool -> Bool -> Bool
|| Sort
sa Sort -> Sort -> Bool
forall a. Eq a => a -> a -> Bool
== Sort
forall t. Sort' t
SizeUniv) (TCM () -> TCM ()) -> TCM () -> TCM ()
forall a b. (a -> b) -> a -> b
$ Sort
sa Sort -> Sort -> TCM ()
forall (m :: * -> *). MonadConversion m => Sort -> Sort -> m ()
`leqSort` Sort
s
(VerboseKey, Dom Type) -> TCMT IO Int -> TCMT IO Int
forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
addContext (Abs Type -> VerboseKey
forall a. Abs a -> VerboseKey
absName Abs Type
b, Dom Type
dom) (TCMT IO Int -> TCMT IO Int) -> TCMT IO Int -> TCMT IO Int
forall a b. (a -> b) -> a -> b
$ do
Int -> Int
forall a. Enum a => a -> a
succ (Int -> Int) -> TCMT IO Int -> TCMT IO Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> UniverseCheck -> [IsForced] -> Type -> Sort -> TCMT IO Int
fitsIn UniverseCheck
uc [IsForced]
forceds' (Abs Type -> Type
forall t a. Subst t a => Abs a -> a
absBody Abs Type
b) (Int -> Sort -> Sort
forall t a. Subst t a => Int -> a -> a
raise Int
1 Sort
s)
Maybe (Bool, Dom Type, Abs Type)
_ -> do
Type -> Sort
forall a. LensSort a => a -> Sort
getSort Type
t Sort -> Sort -> TCM ()
forall (m :: * -> *). MonadConversion m => Sort -> Sort -> m ()
`leqSort` Sort
s
Int -> TCMT IO Int
forall (m :: * -> *) a. Monad m => a -> m a
return Int
0
checkIndexSorts :: Sort -> Telescope -> TCM ()
checkIndexSorts :: Sort -> Tele (Dom Type) -> TCM ()
checkIndexSorts Sort
s = \case
Tele (Dom Type)
EmptyTel -> () -> TCM ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
ExtendTel Dom Type
a Abs (Tele (Dom Type))
tel' -> do
Dom Type -> Sort
forall a. LensSort a => a -> Sort
getSort Dom Type
a Sort -> Sort -> TCM ()
forall (m :: * -> *). MonadConversion m => Sort -> Sort -> m ()
`leqSort` Sort
s
Dom Type
-> Abs (Tele (Dom Type)) -> (Tele (Dom Type) -> TCM ()) -> TCM ()
forall t a (m :: * -> *) b.
(Subst t a, MonadAddContext m) =>
Dom Type -> Abs a -> (a -> m b) -> m b
underAbstraction Dom Type
a Abs (Tele (Dom Type))
tel' ((Tele (Dom Type) -> TCM ()) -> TCM ())
-> (Tele (Dom Type) -> TCM ()) -> TCM ()
forall a b. (a -> b) -> a -> b
$ Sort -> Tele (Dom Type) -> TCM ()
checkIndexSorts (Int -> Sort -> Sort
forall t a. Subst t a => Int -> a -> a
raise Int
1 Sort
s)
data IsPathCons = PathCons | PointCons
deriving (IsPathCons -> IsPathCons -> Bool
(IsPathCons -> IsPathCons -> Bool)
-> (IsPathCons -> IsPathCons -> Bool) -> Eq IsPathCons
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IsPathCons -> IsPathCons -> Bool
$c/= :: IsPathCons -> IsPathCons -> Bool
== :: IsPathCons -> IsPathCons -> Bool
$c== :: IsPathCons -> IsPathCons -> Bool
Eq,Int -> IsPathCons -> VerboseKey -> VerboseKey
[IsPathCons] -> VerboseKey -> VerboseKey
IsPathCons -> VerboseKey
(Int -> IsPathCons -> VerboseKey -> VerboseKey)
-> (IsPathCons -> VerboseKey)
-> ([IsPathCons] -> VerboseKey -> VerboseKey)
-> Show IsPathCons
forall a.
(Int -> a -> VerboseKey -> VerboseKey)
-> (a -> VerboseKey) -> ([a] -> VerboseKey -> VerboseKey) -> Show a
showList :: [IsPathCons] -> VerboseKey -> VerboseKey
$cshowList :: [IsPathCons] -> VerboseKey -> VerboseKey
show :: IsPathCons -> VerboseKey
$cshow :: IsPathCons -> VerboseKey
showsPrec :: Int -> IsPathCons -> VerboseKey -> VerboseKey
$cshowsPrec :: Int -> IsPathCons -> VerboseKey -> VerboseKey
Show)
constructs :: Int -> Int -> Type -> QName -> TCM IsPathCons
constructs :: Int -> Int -> Type -> QName -> TCM IsPathCons
constructs Int
nofPars Int
nofExtraVars Type
t QName
q = Int -> Type -> TCM IsPathCons
constrT Int
nofExtraVars Type
t
where
constrT :: Nat -> Type -> TCM IsPathCons
constrT :: Int -> Type -> TCM IsPathCons
constrT Int
n Type
t = do
Type
t <- Type -> TCMT IO Type
forall a (m :: * -> *). (Reduce a, MonadReduce m) => a -> m a
reduce Type
t
Type -> Either ((Dom Type, Abs Type), (Term, Term)) Type
pathV <- TCMT IO (Type -> Either ((Dom Type, Abs Type), (Term, Term)) Type)
forall (m :: * -> *).
HasBuiltins m =>
m (Type -> Either ((Dom Type, Abs Type), (Term, Term)) Type)
pathViewAsPi'whnf
case Type -> Term
forall t a. Type'' t a -> a
unEl Type
t of
Pi Dom Type
_ (NoAbs VerboseKey
_ Type
b) -> Int -> Type -> TCM IsPathCons
constrT Int
n Type
b
Pi Dom Type
a Abs Type
b -> Dom Type -> Abs Type -> (Type -> TCM IsPathCons) -> TCM IsPathCons
forall t a (m :: * -> *) b.
(Subst t a, MonadAddContext m) =>
Dom Type -> Abs a -> (a -> m b) -> m b
underAbstraction Dom Type
a Abs Type
b ((Type -> TCM IsPathCons) -> TCM IsPathCons)
-> (Type -> TCM IsPathCons) -> TCM IsPathCons
forall a b. (a -> b) -> a -> b
$ Int -> Type -> TCM IsPathCons
constrT (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
Term
_ | Left ((Dom Type
a,Abs Type
b),(Term, Term)
_) <- Type -> Either ((Dom Type, Abs Type), (Term, Term)) Type
pathV Type
t -> do
IsPathCons
_ <- case Abs Type
b of
NoAbs VerboseKey
_ Type
b -> Int -> Type -> TCM IsPathCons
constrT Int
n Type
b
Abs Type
b -> Dom Type -> Abs Type -> (Type -> TCM IsPathCons) -> TCM IsPathCons
forall t a (m :: * -> *) b.
(Subst t a, MonadAddContext m) =>
Dom Type -> Abs a -> (a -> m b) -> m b
underAbstraction Dom Type
a Abs Type
b ((Type -> TCM IsPathCons) -> TCM IsPathCons)
-> (Type -> TCM IsPathCons) -> TCM IsPathCons
forall a b. (a -> b) -> a -> b
$ Int -> Type -> TCM IsPathCons
constrT (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
IsPathCons -> TCM IsPathCons
forall (m :: * -> *) a. Monad m => a -> m a
return IsPathCons
PathCons
Def QName
d Elims
es | QName
d QName -> QName -> Bool
forall a. Eq a => a -> a -> Bool
== QName
q -> do
let vs :: [Arg Term]
vs = [Arg Term] -> Maybe [Arg Term] -> [Arg Term]
forall a. a -> Maybe a -> a
fromMaybe [Arg Term]
forall a. HasCallStack => a
__IMPOSSIBLE__ (Maybe [Arg Term] -> [Arg Term]) -> Maybe [Arg Term] -> [Arg Term]
forall a b. (a -> b) -> a -> b
$ Elims -> Maybe [Arg Term]
forall a. [Elim' a] -> Maybe [Arg a]
allApplyElims Elims
es
([Arg Term]
pars, [Arg Term]
ixs) <- ([Arg Term], [Arg Term]) -> TCMT IO ([Arg Term], [Arg Term])
forall a (m :: * -> *). (Normalise a, MonadReduce m) => a -> m a
normalise (([Arg Term], [Arg Term]) -> TCMT IO ([Arg Term], [Arg Term]))
-> ([Arg Term], [Arg Term]) -> TCMT IO ([Arg Term], [Arg Term])
forall a b. (a -> b) -> a -> b
$ Int -> [Arg Term] -> ([Arg Term], [Arg Term])
forall a. Int -> [a] -> ([a], [a])
splitAt Int
nofPars [Arg Term]
vs
Int -> [Arg Term] -> TCM ()
forall (m :: * -> *).
(MonadMetaSolver m, MonadWarning m, MonadStatistics m,
MonadFresh ProblemId m, MonadFresh Int m) =>
Int -> [Arg Term] -> m ()
checkParams Int
n [Arg Term]
pars
IsPathCons -> TCM IsPathCons
forall (m :: * -> *) a. Monad m => a -> m a
return IsPathCons
PointCons
MetaV{} -> do
Definition
def <- QName -> TCMT IO Definition
forall (m :: * -> *). HasConstInfo m => QName -> m Definition
getConstInfo QName
q
let td :: Type
td = Definition -> Type
defType Definition
def
TelV Tele (Dom Type)
tel Type
core <- Type -> TCMT IO (TelV Type)
forall (m :: * -> *).
(MonadReduce m, MonadAddContext m) =>
Type -> m (TelV Type)
telView Type
td
let us :: [Arg Term]
us = (Arg VerboseKey -> Int -> Arg Term)
-> [Arg VerboseKey] -> [Int] -> [Arg Term]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (\ Arg VerboseKey
arg Int
x -> Int -> Term
var Int
x Term -> Arg VerboseKey -> Arg Term
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Arg VerboseKey
arg ) (Tele (Dom Type) -> [Arg VerboseKey]
forall a. TelToArgs a => a -> [Arg VerboseKey]
telToArgs Tele (Dom Type)
tel) ([Int] -> [Arg Term]) -> [Int] -> [Arg Term]
forall a b. (a -> b) -> a -> b
$
Int -> [Int] -> [Int]
forall a. Int -> [a] -> [a]
take Int
nofPars ([Int] -> [Int]) -> [Int] -> [Int]
forall a b. (a -> b) -> a -> b
$ Int -> [Int]
forall a. Integral a => a -> [a]
downFrom (Int
nofPars Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
n)
[Arg Term]
xs <- Type -> TCMT IO [Arg Term]
forall (m :: * -> *). MonadMetaSolver m => Type -> m [Arg Term]
newArgsMeta (Type -> TCMT IO [Arg Term]) -> TCMT IO Type -> TCMT IO [Arg Term]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Type -> [Arg Term] -> TCMT IO Type
forall a (m :: * -> *).
(PiApplyM a, MonadReduce m) =>
Type -> a -> m Type
piApplyM Type
td [Arg Term]
us
let t' :: Type
t' = Sort -> Term -> Type
forall t a. Sort' t -> a -> Type'' t a
El (Int -> Sort -> Sort
forall t a. Subst t a => Int -> a -> a
raise Int
n (Sort -> Sort) -> Sort -> Sort
forall a b. (a -> b) -> a -> b
$ Defn -> Sort
dataSort (Defn -> Sort) -> Defn -> Sort
forall a b. (a -> b) -> a -> b
$ Definition -> Defn
theDef Definition
def) (Term -> Type) -> Term -> Type
forall a b. (a -> b) -> a -> b
$ QName -> Elims -> Term
Def QName
q (Elims -> Term) -> Elims -> Term
forall a b. (a -> b) -> a -> b
$ (Arg Term -> Elim' Term) -> [Arg Term] -> Elims
forall a b. (a -> b) -> [a] -> [b]
map Arg Term -> Elim' Term
forall a. Arg a -> Elim' a
Apply ([Arg Term] -> Elims) -> [Arg Term] -> Elims
forall a b. (a -> b) -> a -> b
$ [Arg Term]
us [Arg Term] -> [Arg Term] -> [Arg Term]
forall a. [a] -> [a] -> [a]
++ [Arg Term]
xs
TCMT IO Bool -> TCM IsPathCons -> TCM IsPathCons -> TCM IsPathCons
forall (m :: * -> *) a. Monad m => m Bool -> m a -> m a -> m a
ifM (TCM () -> TCMT IO Bool
forall (m :: * -> *).
(MonadConstraint m, MonadWarning m, MonadError TCErr m,
MonadFresh ProblemId m) =>
m () -> m Bool
tryConversion (TCM () -> TCMT IO Bool) -> TCM () -> TCMT IO Bool
forall a b. (a -> b) -> a -> b
$ Type -> Type -> TCM ()
forall (m :: * -> *). MonadConversion m => Type -> Type -> m ()
equalType Type
t Type
t')
(Int -> Type -> TCM IsPathCons
constrT Int
n Type
t')
(TypeError -> TCM IsPathCons
forall (m :: * -> *) a.
(MonadTCEnv m, ReadTCState m, MonadError TCErr m) =>
TypeError -> m a
typeError (TypeError -> TCM IsPathCons) -> TypeError -> TCM IsPathCons
forall a b. (a -> b) -> a -> b
$ Type -> TypeError
ShouldEndInApplicationOfTheDatatype Type
t)
Term
_ -> TypeError -> TCM IsPathCons
forall (m :: * -> *) a.
(MonadTCEnv m, ReadTCState m, MonadError TCErr m) =>
TypeError -> m a
typeError (TypeError -> TCM IsPathCons) -> TypeError -> TCM IsPathCons
forall a b. (a -> b) -> a -> b
$ Type -> TypeError
ShouldEndInApplicationOfTheDatatype Type
t
checkParams :: Int -> [Arg Term] -> m ()
checkParams Int
n [Arg Term]
vs = (Arg Term -> Int -> m ()) -> [Arg Term] -> [Int] -> m ()
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> m c) -> [a] -> [b] -> m ()
zipWithM_ Arg Term -> Int -> m ()
forall (m :: * -> *).
(MonadMetaSolver m, MonadWarning m, MonadStatistics m,
MonadFresh ProblemId m, MonadFresh Int m) =>
Arg Term -> Int -> m ()
sameVar [Arg Term]
vs [Int]
ps
where
nvs :: Int
nvs = [Arg Term] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Arg Term]
vs
ps :: [Int]
ps = [Int] -> [Int]
forall a. [a] -> [a]
reverse ([Int] -> [Int]) -> [Int] -> [Int]
forall a b. (a -> b) -> a -> b
$ Int -> [Int] -> [Int]
forall a. Int -> [a] -> [a]
take Int
nvs [Int
n..]
sameVar :: Arg Term -> Int -> m ()
sameVar Arg Term
arg Int
i
| Arg Term -> Bool
forall a. LensRelevance a => a -> Bool
isIrrelevant Arg Term
arg = () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise = do
Type
t <- Int -> m Type
forall (m :: * -> *).
(Applicative m, MonadFail m, MonadTCEnv m) =>
Int -> m Type
typeOfBV Int
i
Type -> Term -> Term -> m ()
forall (m :: * -> *).
MonadConversion m =>
Type -> Term -> Term -> m ()
equalTerm Type
t (Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
arg) (Int -> Term
var Int
i)
isCoinductive :: Type -> TCM (Maybe Bool)
isCoinductive :: Type -> TCM (Maybe Bool)
isCoinductive Type
t = do
El Sort
s Term
t <- Type -> TCMT IO Type
forall a (m :: * -> *). (Reduce a, MonadReduce m) => a -> m a
reduce Type
t
case Term
t of
Def QName
q Elims
_ -> do
Definition
def <- QName -> TCMT IO Definition
forall (m :: * -> *). HasConstInfo m => QName -> m Definition
getConstInfo QName
q
case Definition -> Defn
theDef Definition
def of
Axiom {} -> Maybe Bool -> TCM (Maybe Bool)
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False)
DataOrRecSig{} -> Maybe Bool -> TCM (Maybe Bool)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Bool
forall a. Maybe a
Nothing
Function {} -> Maybe Bool -> TCM (Maybe Bool)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Bool
forall a. Maybe a
Nothing
Datatype {} -> Maybe Bool -> TCM (Maybe Bool)
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False)
Record { recInduction :: Defn -> Maybe Induction
recInduction = Just Induction
CoInductive } -> Maybe Bool -> TCM (Maybe Bool)
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True)
Record { recInduction :: Defn -> Maybe Induction
recInduction = Maybe Induction
_ } -> Maybe Bool -> TCM (Maybe Bool)
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False)
GeneralizableVar{} -> TCM (Maybe Bool)
forall a. HasCallStack => a
__IMPOSSIBLE__
Constructor {} -> TCM (Maybe Bool)
forall a. HasCallStack => a
__IMPOSSIBLE__
Primitive {} -> TCM (Maybe Bool)
forall a. HasCallStack => a
__IMPOSSIBLE__
AbstractDefn{} -> TCM (Maybe Bool)
forall a. HasCallStack => a
__IMPOSSIBLE__
Var {} -> Maybe Bool -> TCM (Maybe Bool)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Bool
forall a. Maybe a
Nothing
Lam {} -> TCM (Maybe Bool)
forall a. HasCallStack => a
__IMPOSSIBLE__
Lit {} -> TCM (Maybe Bool)
forall a. HasCallStack => a
__IMPOSSIBLE__
Level {} -> TCM (Maybe Bool)
forall a. HasCallStack => a
__IMPOSSIBLE__
Con {} -> TCM (Maybe Bool)
forall a. HasCallStack => a
__IMPOSSIBLE__
Pi {} -> Maybe Bool -> TCM (Maybe Bool)
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False)
Sort {} -> Maybe Bool -> TCM (Maybe Bool)
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False)
MetaV {} -> Maybe Bool -> TCM (Maybe Bool)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Bool
forall a. Maybe a
Nothing
DontCare{} -> TCM (Maybe Bool)
forall a. HasCallStack => a
__IMPOSSIBLE__
Dummy VerboseKey
s Elims
_ -> VerboseKey -> TCM (Maybe Bool)
forall (m :: * -> *) a.
(HasCallStack, MonadDebug m) =>
VerboseKey -> m a
__IMPOSSIBLE_VERBOSE__ VerboseKey
s