{-# OPTIONS_GHC -Wunused-imports #-}
module Mikan.TypeChecking.Telescope where
import Prelude hiding (null)
import Control.Monad
import Data.Foldable
import Data.IntSet (IntSet)
import Data.IntSet qualified as IntSet
import Data.List qualified as List
import Data.Maybe
import Mikan.Syntax.Common
import Mikan.Syntax.Common.Pretty ( Pretty )
import Mikan.Syntax.Internal
import Mikan.TypeChecking.Monad.Builtin
import Mikan.TypeChecking.Monad
import Mikan.TypeChecking.Reduce
import Mikan.TypeChecking.Substitute
import Mikan.TypeChecking.Free
import Mikan.Utils.Either
import Mikan.Utils.Empty
import Mikan.Utils.Functor
import Mikan.Utils.Function
import Mikan.Utils.List
import Mikan.Utils.Null
import Mikan.Utils.Permutation
import Mikan.Utils.Singleton
import Mikan.Utils.Size
import Mikan.Utils.Tuple
import Mikan.Utils.VarSet (VarSet)
import Mikan.Utils.VarSet qualified as VarSet
import Mikan.Utils.Impossible
import Mikan.Utils.CallStack
flattenTel :: TermSubst a => Tele (Dom a) -> [Dom a]
flattenTel :: forall a. TermSubst a => Tele (Dom a) -> [Dom a]
flattenTel Tele (Dom a)
tel = Int -> Tele (Dom a) -> [Dom a]
forall {a}. Subst a => Int -> Tele a -> [a]
loop (Tele (Dom a) -> Int
forall a. Sized a => a -> Int
size Tele (Dom a)
tel) Tele (Dom a)
tel
where
loop :: Int -> Tele a -> [a]
loop Int
ix Tele a
EmptyTel = []
loop Int
ix (ExtendTel a
a (Abs ArgName
_ Tele a
tel)) = Int -> a -> a
forall a. Subst a => Int -> a -> a
raise Int
ix a
a a -> [a] -> [a]
forall a. a -> [a] -> [a]
: Int -> Tele a -> [a]
loop (Int
ix Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Tele a
tel
loop Int
ix (ExtendTel a
a (NoAbs ArgName
_ Tele a
tel)) = Int -> a -> a
forall a. Subst a => Int -> a -> a
raise Int
ix a
a a -> [a] -> [a]
forall a. a -> [a] -> [a]
: Int -> Tele a -> [a]
loop Int
ix Tele a
tel
{-# SPECIALIZE flattenTel :: Telescope -> [Dom Type] #-}
flattenRevTel :: TermSubst a => Tele (Dom a) -> [Dom a]
flattenRevTel :: forall a. TermSubst a => Tele (Dom a) -> [Dom a]
flattenRevTel Tele (Dom a)
tel = Int -> [Dom a] -> Tele (Dom a) -> [Dom a]
forall {a}. Subst a => Int -> [a] -> Tele a -> [a]
loop (Tele (Dom a) -> Int
forall a. Sized a => a -> Int
size Tele (Dom a)
tel) [] Tele (Dom a)
tel
where
loop :: Int -> [a] -> Tele a -> [a]
loop Int
ix [a]
acc Tele a
EmptyTel = [a]
acc
loop Int
ix [a]
acc (ExtendTel a
a (Abs ArgName
_ Tele a
tel)) = Int -> [a] -> Tele a -> [a]
loop (Int
ix Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) (Int -> a -> a
forall a. Subst a => Int -> a -> a
raise Int
ix a
a a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
acc) Tele a
tel
loop Int
ix [a]
acc (ExtendTel a
a (NoAbs ArgName
_ Tele a
tel)) = Int -> [a] -> Tele a -> [a]
loop Int
ix (Int -> a -> a
forall a. Subst a => Int -> a -> a
raise Int
ix a
a a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
acc) Tele a
tel
{-# SPECIALIZE flattenRevTel :: Telescope -> [Dom Type] #-}
flattenContext :: Context -> [ContextEntry]
flattenContext :: Context -> [ContextEntry]
flattenContext = Int -> [ContextEntry] -> [ContextEntry] -> [ContextEntry]
forall {a}. Subst a => Int -> [a] -> [a] -> [a]
loop Int
1 [] ([ContextEntry] -> [ContextEntry])
-> (Context -> [ContextEntry]) -> Context -> [ContextEntry]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Context -> [ContextEntry]
forall a. Context' a -> [a]
cxEntries
where
loop :: Int -> [a] -> [a] -> [a]
loop Int
n [a]
tel [] = [a]
tel
loop Int
n [a]
tel (a
ce:[a]
ctx) = Int -> [a] -> [a] -> [a]
loop (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Int -> a -> a
forall a. Subst a => Int -> a -> a
raise Int
n a
ce a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
tel) [a]
ctx
reorderTel :: [Dom Type] -> Maybe Permutation
reorderTel :: [Dom Type] -> Maybe Permutation
reorderTel [Dom Type]
tel = ((Int, Dom Type) -> (Int, Dom Type) -> Bool)
-> [(Int, Dom Type)] -> Maybe Permutation
forall a. (a -> a -> Bool) -> [a] -> Maybe Permutation
topoSort (Int, Dom Type) -> (Int, Dom Type) -> Bool
forall {t} {b} {a} {t} {t}.
Free t =>
(Int, b) -> (a, Dom' t (Type'' t t)) -> Bool
comesBefore [(Int, Dom Type)]
tel'
where
tel' :: [(Int, Dom Type)]
tel' = [Int] -> [Dom Type] -> [(Int, Dom Type)]
forall a b. [a] -> [b] -> [(a, b)]
zip (Int -> [Int]
forall a. Integral a => a -> [a]
downFrom (Int -> [Int]) -> Int -> [Int]
forall a b. (a -> b) -> a -> b
$ [Dom Type] -> Int
forall a. Sized a => a -> Int
size [Dom Type]
tel) [Dom Type]
tel
(Int
i, b
_) comesBefore :: (Int, b) -> (a, Dom' t (Type'' t t)) -> Bool
`comesBefore` (a
_, Dom' t (Type'' t t)
a) = Int
i Int -> t -> Bool
forall t. Free t => Int -> t -> Bool
`freeIn` Type'' t t -> t
forall t a. Type'' t a -> a
unEl (Dom' t (Type'' t t) -> Type'' t t
forall t e. Dom' t e -> e
unDom Dom' t (Type'' t t)
a)
reorderTel_ :: [Dom Type] -> Permutation
reorderTel_ :: [Dom Type] -> Permutation
reorderTel_ [Dom Type]
tel = Permutation -> Maybe Permutation -> Permutation
forall a. a -> Maybe a -> a
fromMaybe Permutation
forall a. HasCallStack => a
__IMPOSSIBLE__ ([Dom Type] -> Maybe Permutation
reorderTel [Dom Type]
tel)
unflattenTel :: [ArgName] -> [Dom Type] -> Telescope
unflattenTel :: [ArgName] -> [Dom Type] -> Tele (Dom Type)
unflattenTel [ArgName]
xs [Dom Type]
tel = Int -> [ArgName] -> [Dom Type] -> Tele (Dom Type)
unflattenTel' ([Dom Type] -> Int
forall a. Sized a => a -> Int
size [Dom Type]
tel) [ArgName]
xs [Dom Type]
tel
unflattenTel' :: Int -> [ArgName] -> [Dom Type] -> Telescope
unflattenTel' :: Int -> [ArgName] -> [Dom Type] -> Tele (Dom Type)
unflattenTel' !Int
n [ArgName]
xs [Dom Type]
tel = case ([ArgName]
xs, [Dom Type]
tel) of
([], []) -> Tele (Dom Type)
forall a. Tele a
EmptyTel
(ArgName
x : [ArgName]
xs, Dom Type
a : [Dom Type]
tel) -> Dom Type -> Abs (Tele (Dom Type)) -> Tele (Dom Type)
forall a. a -> Abs (Tele a) -> Tele a
ExtendTel Dom Type
a' (ArgName -> Tele (Dom Type) -> Abs (Tele (Dom Type))
forall a. ArgName -> a -> Abs a
Abs ArgName
x Tele (Dom Type)
tel')
where
tel' :: Tele (Dom Type)
tel' = Int -> [ArgName] -> [Dom Type] -> Tele (Dom Type)
unflattenTel' (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) [ArgName]
xs [Dom Type]
tel
a' :: Dom Type
a' = Substitution' (SubstArg (Dom Type)) -> Dom Type -> Dom Type
forall a. Subst a => Substitution' (SubstArg a) -> a -> a
applySubst Substitution' Term
Substitution' (SubstArg (Dom Type))
rho Dom Type
a
rho :: Substitution' Term
rho = Impossible -> Int -> Substitution' Term
forall a. Impossible -> Int -> Substitution' a
strengthenS Impossible
HasCallStack => Impossible
impossible Int
n
([], Dom Type
_ : [Dom Type]
_) -> Tele (Dom Type)
forall a. HasCallStack => a
__IMPOSSIBLE__
(ArgName
_ : [ArgName]
_, []) -> Tele (Dom Type)
forall a. HasCallStack => a
__IMPOSSIBLE__
renameTel :: [Maybe ArgName] -> Telescope -> Telescope
renameTel :: [Maybe ArgName] -> Tele (Dom Type) -> Tele (Dom Type)
renameTel [] Tele (Dom Type)
EmptyTel = Tele (Dom Type)
forall a. Tele a
EmptyTel
renameTel (Maybe ArgName
Nothing:[Maybe ArgName]
xs) (ExtendTel Dom Type
a Abs (Tele (Dom Type))
tel') = 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
$ [Maybe ArgName] -> Tele (Dom Type) -> Tele (Dom Type)
renameTel [Maybe ArgName]
xs (Tele (Dom Type) -> Tele (Dom Type))
-> Abs (Tele (Dom Type)) -> Abs (Tele (Dom Type))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Abs (Tele (Dom Type))
tel'
renameTel (Just ArgName
x :[Maybe ArgName]
xs) (ExtendTel Dom Type
a Abs (Tele (Dom Type))
tel') = 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
$ [Maybe ArgName] -> Tele (Dom Type) -> Tele (Dom Type)
renameTel [Maybe ArgName]
xs (Tele (Dom Type) -> Tele (Dom Type))
-> Abs (Tele (Dom Type)) -> Abs (Tele (Dom Type))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Abs (Tele (Dom Type))
tel' { absName = x })
renameTel [] (ExtendTel Dom Type
_ Abs (Tele (Dom Type))
_ ) = Tele (Dom Type)
forall a. HasCallStack => a
__IMPOSSIBLE__
renameTel (Maybe ArgName
_ :[Maybe ArgName]
_ ) Tele (Dom Type)
EmptyTel = Tele (Dom Type)
forall a. HasCallStack => a
__IMPOSSIBLE__
teleNames :: Telescope -> [ArgName]
teleNames :: Tele (Dom Type) -> [ArgName]
teleNames = (Dom (ArgName, Type) -> ArgName)
-> [Dom (ArgName, Type)] -> [ArgName]
forall a b. (a -> b) -> [a] -> [b]
map' ((ArgName, Type) -> ArgName
forall a b. (a, b) -> a
fst ((ArgName, Type) -> ArgName)
-> (Dom (ArgName, Type) -> (ArgName, Type))
-> Dom (ArgName, Type)
-> ArgName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dom (ArgName, Type) -> (ArgName, Type)
forall t e. Dom' t e -> e
unDom) ([Dom (ArgName, Type)] -> [ArgName])
-> (Tele (Dom Type) -> [Dom (ArgName, Type)])
-> Tele (Dom Type)
-> [ArgName]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tele (Dom Type) -> [Dom (ArgName, Type)]
forall t. Tele (Dom t) -> [Dom (ArgName, t)]
telToList
teleArgNames :: Telescope -> [Arg ArgName]
teleArgNames :: Tele (Dom Type) -> [Arg ArgName]
teleArgNames = Tele (Dom Type) -> [Arg ArgName]
forall a. TelToArgs a => a -> [Arg ArgName]
telToArgs
teleArgs :: (DeBruijn a) => Tele (Dom t) -> [Arg a]
teleArgs :: forall a t. DeBruijn a => Tele (Dom t) -> [Arg a]
teleArgs = (Dom' Term a -> Arg a) -> [Dom' Term a] -> [Arg a]
forall a b. (a -> b) -> [a] -> [b]
map' Dom' Term a -> Arg a
forall t a. Dom' t a -> Arg a
argFromDom ([Dom' Term a] -> [Arg a])
-> (Tele (Dom t) -> [Dom' Term a]) -> Tele (Dom t) -> [Arg a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tele (Dom t) -> [Dom' Term a]
forall a t. DeBruijn a => Tele (Dom t) -> [Dom a]
teleDoms
teleDoms :: (DeBruijn a) => Tele (Dom t) -> [Dom a]
teleDoms :: forall a t. DeBruijn a => Tele (Dom t) -> [Dom a]
teleDoms Tele (Dom t)
tel = (Int -> Dom (ArgName, t) -> Dom a)
-> [Int] -> [Dom (ArgName, t)] -> [Dom a]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (\ Int
i Dom (ArgName, t)
dom -> Int -> a
forall a. DeBruijn a => Int -> a
deBruijnVar Int
i a -> Dom (ArgName, t) -> Dom a
forall a b. a -> Dom' Term b -> Dom' Term a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Dom (ArgName, t)
dom) (Int -> [Int]
forall a. Integral a => a -> [a]
downFrom (Int -> [Int]) -> Int -> [Int]
forall a b. (a -> b) -> a -> b
$ [Dom (ArgName, t)] -> Int
forall a. Sized a => a -> Int
size [Dom (ArgName, t)]
l) [Dom (ArgName, t)]
l
where l :: [Dom (ArgName, t)]
l = Tele (Dom t) -> [Dom (ArgName, t)]
forall t. Tele (Dom t) -> [Dom (ArgName, t)]
telToList Tele (Dom t)
tel
teleNamedArgs :: (DeBruijn a) => Tele (Dom t) -> [NamedArg a]
teleNamedArgs :: forall a t. DeBruijn a => Tele (Dom t) -> [NamedArg a]
teleNamedArgs = (Dom' Term a -> NamedArg a) -> [Dom' Term a] -> [NamedArg a]
forall a b. (a -> b) -> [a] -> [b]
map' Dom' Term a -> NamedArg a
forall t a. Dom' t a -> NamedArg a
namedArgFromDom ([Dom' Term a] -> [NamedArg a])
-> (Tele (Dom t) -> [Dom' Term a]) -> Tele (Dom t) -> [NamedArg a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tele (Dom t) -> [Dom' Term a]
forall a t. DeBruijn a => Tele (Dom t) -> [Dom a]
teleDoms
{-# INLINABLE tele2NamedArgs #-}
tele2NamedArgs :: (DeBruijn a) => Telescope -> Telescope -> [NamedArg a]
tele2NamedArgs :: forall a.
DeBruijn a =>
Tele (Dom Type) -> Tele (Dom Type) -> [NamedArg a]
tele2NamedArgs Tele (Dom Type)
tel0 Tele (Dom Type)
tel =
[ ArgInfo -> Named_ a -> NamedArg a
forall e. ArgInfo -> e -> Arg e
Arg (Dom (ArgName, Type)
d1 Dom (ArgName, Type)
-> Getting ArgInfo (Dom (ArgName, Type)) ArgInfo -> ArgInfo
forall s a. s -> Getting a s a -> a
^. Getting ArgInfo (Dom (ArgName, Type)) ArgInfo
forall t e (f :: * -> *).
Functor f =>
(ArgInfo -> f ArgInfo) -> Dom' t e -> f (Dom' t e)
dInfo) (Maybe NamedName -> a -> Named_ a
forall name a. Maybe name -> a -> Named name a
Named (NamedName -> Maybe NamedName
forall a. a -> Maybe a
Just (NamedName -> Maybe NamedName) -> NamedName -> Maybe NamedName
forall a b. (a -> b) -> a -> b
$ Origin -> Ranged ArgName -> NamedName
forall a. Origin -> a -> WithOrigin a
WithOrigin Origin
Inserted (Ranged ArgName -> NamedName) -> Ranged ArgName -> NamedName
forall a b. (a -> b) -> a -> b
$ ArgName -> Ranged ArgName
forall a. a -> Ranged a
unranged (ArgName -> Ranged ArgName) -> ArgName -> Ranged ArgName
forall a b. (a -> b) -> a -> b
$ ArgName -> ArgName
argNameToString ((ArgName, Type) -> ArgName
forall a b. (a, b) -> a
fst (Dom (ArgName, Type) -> (ArgName, Type)
forall t e. Dom' t e -> e
unDom Dom (ArgName, Type)
d1)))
(ArgName -> Int -> a
forall a. DeBruijn a => ArgName -> Int -> a
deBruijnNamedVar ((ArgName, Type) -> ArgName
forall a b. (a, b) -> a
fst (Dom (ArgName, Type) -> (ArgName, Type)
forall t e. Dom' t e -> e
unDom Dom (ArgName, Type)
d2)) Int
i))
| (Int
i, Dom (ArgName, Type)
d1, Dom (ArgName, Type)
d2) <- [Int]
-> [Dom (ArgName, Type)]
-> [Dom (ArgName, Type)]
-> [(Int, Dom (ArgName, Type), Dom (ArgName, Type))]
forall a b c. [a] -> [b] -> [c] -> [(a, b, c)]
zip3 (Int -> [Int]
forall a. Integral a => a -> [a]
downFrom (Int -> [Int]) -> Int -> [Int]
forall a b. (a -> b) -> a -> b
$ [Dom (ArgName, Type)] -> Int
forall a. Sized a => a -> Int
size [Dom (ArgName, Type)]
l) [Dom (ArgName, Type)]
l0 [Dom (ArgName, Type)]
l ]
where
l :: [Dom (ArgName, Type)]
l = Tele (Dom Type) -> [Dom (ArgName, Type)]
forall t. Tele (Dom t) -> [Dom (ArgName, t)]
telToList Tele (Dom Type)
tel
l0 :: [Dom (ArgName, Type)]
l0 = Tele (Dom Type) -> [Dom (ArgName, Type)]
forall t. Tele (Dom t) -> [Dom (ArgName, t)]
telToList Tele (Dom Type)
tel0
splitTelescopeAt :: Int -> Telescope -> (Telescope,Telescope)
splitTelescopeAt :: Int -> Tele (Dom Type) -> (Tele (Dom Type), Tele (Dom Type))
splitTelescopeAt Int
n Tele (Dom Type)
tel
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 = (Tele (Dom Type)
forall a. Tele a
EmptyTel, Tele (Dom Type)
tel)
| Bool
otherwise = Int -> Tele (Dom Type) -> (Tele (Dom Type), Tele (Dom Type))
splitTelescopeAt' Int
n Tele (Dom Type)
tel
where
splitTelescopeAt' :: Int -> Tele (Dom Type) -> (Tele (Dom Type), Tele (Dom Type))
splitTelescopeAt' Int
_ Tele (Dom Type)
EmptyTel = (Tele (Dom Type)
forall a. Tele a
EmptyTel,Tele (Dom Type)
forall a. Tele a
EmptyTel)
splitTelescopeAt' Int
1 (ExtendTel Dom Type
a Abs (Tele (Dom Type))
tel) = (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))
tel Abs (Tele (Dom Type)) -> Tele (Dom Type) -> Abs (Tele (Dom Type))
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Tele (Dom Type)
forall a. Tele a
EmptyTel), Abs (Tele (Dom Type)) -> Tele (Dom Type)
forall a. Subst a => Abs a -> a
absBody Abs (Tele (Dom Type))
tel)
splitTelescopeAt' Int
m (ExtendTel Dom Type
a Abs (Tele (Dom Type))
tel) = (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))
tel Abs (Tele (Dom Type)) -> Tele (Dom Type) -> Abs (Tele (Dom Type))
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Tele (Dom Type)
tel'), Tele (Dom Type)
tel'')
where
(Tele (Dom Type)
tel', Tele (Dom Type)
tel'') = Int -> Tele (Dom Type) -> (Tele (Dom Type), Tele (Dom Type))
splitTelescopeAt (Int
m Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) (Tele (Dom Type) -> (Tele (Dom Type), Tele (Dom Type)))
-> Tele (Dom Type) -> (Tele (Dom Type), Tele (Dom Type))
forall a b. (a -> b) -> a -> b
$ Abs (Tele (Dom Type)) -> Tele (Dom Type)
forall a. Subst a => Abs a -> a
absBody Abs (Tele (Dom Type))
tel
takeTelescope :: Int -> Telescope -> Telescope
takeTelescope :: Int -> Tele (Dom Type) -> Tele (Dom Type)
takeTelescope Int
n Tele (Dom Type)
tel
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 = Tele (Dom Type)
forall a. Tele a
EmptyTel
| Bool
otherwise = Int -> Tele (Dom Type) -> Tele (Dom Type)
forall {t} {a}. (Eq t, Num t) => t -> Tele a -> Tele a
loop Int
n Tele (Dom Type)
tel where
loop :: t -> Tele a -> Tele a
loop t
_ Tele a
EmptyTel = Tele a
forall a. Tele a
EmptyTel
loop t
0 Tele a
tel = Tele a
forall a. Tele a
EmptyTel
loop t
n (ExtendTel a
a Abs (Tele a)
tel) = a -> Abs (Tele a) -> Tele a
forall a. a -> Abs (Tele a) -> Tele a
ExtendTel a
a (t -> Tele a -> Tele a
loop (t
n t -> t -> t
forall a. Num a => a -> a -> a
- t
1) (Tele a -> Tele a) -> Abs (Tele a) -> Abs (Tele a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Abs (Tele a)
tel)
dropEndTelescope :: Int -> Telescope -> Telescope
dropEndTelescope :: Int -> Tele (Dom Type) -> Tele (Dom Type)
dropEndTelescope Int
n Tele (Dom Type)
tel
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 = Tele (Dom Type)
forall a. Tele a
EmptyTel
| Bool
otherwise = (Int, Tele (Dom Type)) -> Tele (Dom Type)
forall a b. (a, b) -> b
snd ((Int, Tele (Dom Type)) -> Tele (Dom Type))
-> (Int, Tele (Dom Type)) -> Tele (Dom Type)
forall a b. (a -> b) -> a -> b
$ Tele (Dom Type) -> (Int, Tele (Dom Type))
loop Tele (Dom Type)
tel where
loop :: Tele (Dom Type) -> (Int, Tele (Dom Type))
loop Tele (Dom Type)
EmptyTel = (Int
n, Tele (Dom Type)
forall a. Tele a
EmptyTel)
loop (ExtendTel Dom Type
a Abs (Tele (Dom Type))
tel) =
let (Int
k, Tele (Dom Type)
pfx) = Tele (Dom Type) -> (Int, Tele (Dom Type))
loop (Abs (Tele (Dom Type)) -> Tele (Dom Type)
forall a. Abs a -> a
unAbs Abs (Tele (Dom Type))
tel)
in (Int
k Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1, Bool
-> (Tele (Dom Type) -> Tele (Dom Type))
-> Tele (Dom Type)
-> Tele (Dom Type)
forall b a. IsBool b => b -> (a -> a) -> a -> a
applyWhen (Int
k Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0) (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))
-> (Tele (Dom Type) -> Abs (Tele (Dom Type)))
-> Tele (Dom Type)
-> Tele (Dom Type)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Abs (Tele (Dom Type))
tel Abs (Tele (Dom Type)) -> Tele (Dom Type) -> Abs (Tele (Dom Type))
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$>)) Tele (Dom Type)
pfx)
permuteTel :: Permutation -> Telescope -> Telescope
permuteTel :: Permutation -> Tele (Dom Type) -> Tele (Dom Type)
permuteTel Permutation
perm Tele (Dom Type)
tel =
let names :: [ArgName]
names = Permutation -> [ArgName] -> [ArgName]
forall a. Permutation -> [a] -> [a]
permute Permutation
perm ([ArgName] -> [ArgName]) -> [ArgName] -> [ArgName]
forall a b. (a -> b) -> a -> b
$ Tele (Dom Type) -> [ArgName]
teleNames Tele (Dom Type)
tel
types :: [Dom Type]
types = Permutation -> [Dom Type] -> [Dom Type]
forall a. Permutation -> [a] -> [a]
permute Permutation
perm ([Dom Type] -> [Dom Type]) -> [Dom Type] -> [Dom Type]
forall a b. (a -> b) -> a -> b
$ Impossible -> Permutation -> [Dom Type] -> [Dom Type]
forall a. Subst a => Impossible -> Permutation -> a -> a
renameP Impossible
HasCallStack => Impossible
impossible (Permutation -> Permutation
reverseP Permutation
perm) ([Dom Type] -> [Dom Type]) -> [Dom Type] -> [Dom Type]
forall a b. (a -> b) -> a -> b
$ Tele (Dom Type) -> [Dom Type]
forall a. TermSubst a => Tele (Dom a) -> [Dom a]
flattenTel Tele (Dom Type)
tel
in [ArgName] -> [Dom Type] -> Tele (Dom Type)
unflattenTel [ArgName]
names [Dom Type]
types
permuteContext :: Permutation -> Context -> Telescope
permuteContext :: Permutation -> Context -> Tele (Dom Type)
permuteContext Permutation
perm Context
ctx = Permutation -> Tele (Dom Type) -> Tele (Dom Type)
permuteTel Permutation
perm (Tele (Dom Type) -> Tele (Dom Type))
-> Tele (Dom Type) -> Tele (Dom Type)
forall a b. (a -> b) -> a -> b
$ Context -> Tele (Dom Type)
contextToTel Context
ctx
varDependencies :: Telescope -> VarSet -> VarSet
varDependencies :: Tele (Dom Type) -> VarSet -> VarSet
varDependencies Tele (Dom Type)
tel = Tele (Dom Type) -> VarSet -> VarSet
allDependencies Tele (Dom Type)
tel
where
allDependencies :: Telescope -> VarSet -> VarSet
allDependencies :: Tele (Dom Type) -> VarSet -> VarSet
allDependencies Tele (Dom Type)
tel VarSet
vs = VarSet -> [Dom Type] -> Int -> VarSet -> VarSet
loop VarSet
forall a. Null a => a
empty (Tele (Dom Type) -> [Dom Type]
forall a. TermSubst a => Tele (Dom a) -> [Dom a]
flattenRevTel Tele (Dom Type)
tel) (-Int
1) VarSet
vs
where
loop :: VarSet -> [Dom Type] -> Int -> VarSet -> VarSet
loop :: VarSet -> [Dom Type] -> Int -> VarSet -> VarSet
loop !VarSet
deps [Dom Type]
telRev Int
prevIx VarSet
work =
case VarSet -> Maybe (Int, VarSet)
VarSet.minView VarSet
work of
Maybe (Int, VarSet)
Nothing -> VarSet
deps
Just (Int
ix, VarSet
work) ->
case Int -> [Dom Type] -> [Dom Type]
forall a. Int -> [a] -> [a]
drop (Int
ix Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
prevIx Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) [Dom Type]
telRev of
[] ->
VarSet
deps
(Dom Type
ti:[Dom Type]
telRev) ->
VarSet -> [Dom Type] -> Int -> VarSet -> VarSet
loop (Int -> VarSet -> VarSet
VarSet.insert Int
ix VarSet
deps) [Dom Type]
telRev Int
ix (VarSet -> VarSet -> VarSet
VarSet.union (Dom Type -> VarSet
forall t. Free t => t -> VarSet
freeVarSet Dom Type
ti) VarSet
work)
varDependents :: Telescope -> VarSet -> VarSet
varDependents :: Tele (Dom Type) -> VarSet -> VarSet
varDependents Tele (Dom Type)
tel VarSet
vs =
VarSet -> [Dom Type] -> Int -> VarSet -> VarSet
loop VarSet
forall a. Null a => a
empty (Tele (Dom Type) -> [Dom Type]
forall a. TermSubst a => Tele (Dom a) -> [Dom a]
flattenTel Tele (Dom Type)
tel) (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
- Int
1) VarSet
vs
where
loop :: VarSet -> [Dom Type] -> Int -> VarSet -> VarSet
loop :: VarSet -> [Dom Type] -> Int -> VarSet -> VarSet
loop !VarSet
deps [Dom Type]
tel Int
ix VarSet
work =
case [Dom Type]
tel of
[] -> VarSet
deps
(Dom Type
ti:[Dom Type]
tel) ->
if (Int -> Bool) -> Dom Type -> Bool
forall t. Free t => (Int -> Bool) -> t -> Bool
anyFreeVar (Int -> VarSet -> Bool
`VarSet.member` VarSet
work) Dom Type
ti then
VarSet -> [Dom Type] -> Int -> VarSet -> VarSet
loop (Int -> VarSet -> VarSet
VarSet.insert Int
ix VarSet
deps) [Dom Type]
tel (Int
ix Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) (Int -> VarSet -> VarSet
VarSet.insert Int
ix VarSet
work)
else
VarSet -> [Dom Type] -> Int -> VarSet -> VarSet
loop VarSet
deps [Dom Type]
tel (Int
ix Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) VarSet
work
data SplitTel = SplitTel
{ SplitTel -> Tele (Dom Type)
firstPart :: Telescope
, SplitTel -> Tele (Dom Type)
secondPart :: Telescope
, SplitTel -> Permutation
splitPerm :: Permutation
}
splitTelescope
:: VarSet
-> Int
-> Telescope
-> SplitTel
splitTelescope :: VarSet -> Int -> Tele (Dom Type) -> SplitTel
splitTelescope VarSet
fv Int
k Tele (Dom Type)
tel = Tele (Dom Type) -> Tele (Dom Type) -> Permutation -> SplitTel
SplitTel Tele (Dom Type)
tel1 Tele (Dom Type)
tel2 Permutation
perm
where
names :: [ArgName]
names = Tele (Dom Type) -> [ArgName]
teleNames Tele (Dom Type)
tel
ts0 :: [Dom Type]
ts0 = Tele (Dom Type) -> [Dom Type]
forall a. TermSubst a => Tele (Dom a) -> [Dom a]
flattenTel Tele (Dom Type)
tel
n :: Int
n = Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
tel
is :: VarSet
is = VarSet -> VarSet -> VarSet
VarSet.union (Tele (Dom Type) -> VarSet -> VarSet
varDependencies Tele (Dom Type)
tel VarSet
fv) (Int -> Int -> VarSet
VarSet.range (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
k Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Int
n)
isC :: VarSet
isC = Int -> VarSet -> VarSet
VarSet.complement Int
n VarSet
is
perm :: Permutation
perm = Int -> [Int] -> Permutation
Perm Int
n ([Int] -> Permutation) -> [Int] -> Permutation
forall a b. (a -> b) -> a -> b
$! (Int -> Int) -> [Int] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map' (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1Int -> Int -> Int
forall a. Num a => a -> a -> a
-) ([Int] -> [Int]) -> [Int] -> [Int]
forall a b. (a -> b) -> a -> b
$! VarSet -> [Int]
VarSet.toDescList VarSet
is [Int] -> [Int] -> [Int]
forall a. [a] -> [a] -> [a]
++! VarSet -> [Int]
VarSet.toDescList VarSet
isC
ts1 :: [Dom Type]
ts1 = Impossible -> Permutation -> [Dom Type] -> [Dom Type]
forall a. Subst a => Impossible -> Permutation -> a -> a
renameP Impossible
HasCallStack => Impossible
impossible (Permutation -> Permutation
reverseP Permutation
perm) (Permutation -> [Dom Type] -> [Dom Type]
forall a. Permutation -> [a] -> [a]
permute Permutation
perm [Dom Type]
ts0)
tel' :: Tele (Dom Type)
tel' = [ArgName] -> [Dom Type] -> Tele (Dom Type)
unflattenTel (Permutation -> [ArgName] -> [ArgName]
forall a. Permutation -> [a] -> [a]
permute Permutation
perm [ArgName]
names) [Dom Type]
ts1
m :: Int
m = VarSet -> Int
VarSet.size VarSet
is
(Tele (Dom Type)
tel1, Tele (Dom Type)
tel2) = [Dom (ArgName, Type)] -> Tele (Dom Type)
telFromList ([Dom (ArgName, Type)] -> Tele (Dom Type))
-> ([Dom (ArgName, Type)] -> Tele (Dom Type))
-> ([Dom (ArgName, Type)], [Dom (ArgName, Type)])
-> (Tele (Dom Type), Tele (Dom Type))
forall b c b' c'. (b -> c) -> (b' -> c') -> (b, b') -> (c, c')
forall (a :: * -> * -> *) b c b' c'.
Arrow a =>
a b c -> a b' c' -> a (b, b') (c, c')
*** [Dom (ArgName, Type)] -> Tele (Dom Type)
telFromList (([Dom (ArgName, Type)], [Dom (ArgName, Type)])
-> (Tele (Dom Type), Tele (Dom Type)))
-> ([Dom (ArgName, Type)], [Dom (ArgName, Type)])
-> (Tele (Dom Type), Tele (Dom Type))
forall a b. (a -> b) -> a -> b
$ Int
-> [Dom (ArgName, Type)]
-> ([Dom (ArgName, Type)], [Dom (ArgName, Type)])
forall a. Int -> [a] -> ([a], [a])
splitAt' Int
m ([Dom (ArgName, Type)]
-> ([Dom (ArgName, Type)], [Dom (ArgName, Type)]))
-> [Dom (ArgName, Type)]
-> ([Dom (ArgName, Type)], [Dom (ArgName, Type)])
forall a b. (a -> b) -> a -> b
$ Tele (Dom Type) -> [Dom (ArgName, Type)]
forall t. Tele (Dom t) -> [Dom (ArgName, t)]
telToList Tele (Dom Type)
tel'
splitTelescopeExact
:: [Int]
-> Telescope
-> Maybe SplitTel
splitTelescopeExact :: [Int] -> Tele (Dom Type) -> Maybe SplitTel
splitTelescopeExact [Int]
is Tele (Dom Type)
tel = Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard Bool
ok Maybe () -> SplitTel -> Maybe SplitTel
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Tele (Dom Type) -> Tele (Dom Type) -> Permutation -> SplitTel
SplitTel Tele (Dom Type)
tel1 Tele (Dom Type)
tel2 Permutation
perm
where
names :: [ArgName]
names = Tele (Dom Type) -> [ArgName]
teleNames Tele (Dom Type)
tel
ts0 :: [Dom Type]
ts0 = Tele (Dom Type) -> [Dom Type]
forall a. TermSubst a => Tele (Dom a) -> [Dom a]
flattenTel Tele (Dom Type)
tel
n :: Int
n = Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
tel
checkDependencies :: IntSet -> [Int] -> Bool
checkDependencies :: IntSet -> [Int] -> Bool
checkDependencies IntSet
soFar [] = Bool
True
checkDependencies IntSet
soFar (Int
j:[Int]
js) = Bool
ok Bool -> Bool -> Bool
&& IntSet -> [Int] -> Bool
checkDependencies (Int -> IntSet -> IntSet
IntSet.insert Int
j IntSet
soFar) [Int]
js
where
t :: Dom Type
t = Dom Type -> [Dom Type] -> Int -> Dom Type
forall a. a -> [a] -> Int -> a
indexWithDefault Dom Type
forall a. HasCallStack => a
__IMPOSSIBLE__ [Dom Type]
ts0 (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1Int -> Int -> Int
forall a. Num a => a -> a -> a
-Int
j)
good :: Int -> Bool
good Int
i = (Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
n) Bool -> Bool -> Bool
`implies` (Int
i Int -> IntSet -> Bool
`IntSet.member` IntSet
soFar) where implies :: Bool -> Bool -> Bool
implies = Bool -> Bool -> Bool
forall a. Ord a => a -> a -> Bool
(<=)
ok :: Bool
ok = (Int -> Bool) -> Dom Type -> Bool
forall t. Free t => (Int -> Bool) -> t -> Bool
allFreeVar Int -> Bool
good Dom Type
t
ok :: Bool
ok = (Int -> Bool) -> [Int] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
n) [Int]
is Bool -> Bool -> Bool
&& IntSet -> [Int] -> Bool
checkDependencies IntSet
IntSet.empty [Int]
is
isC :: [Int]
isC = Int -> [Int]
forall a. Integral a => a -> [a]
downFrom Int
n [Int] -> [Int] -> [Int]
forall a. Eq a => [a] -> [a] -> [a]
List.\\ [Int]
is
perm :: Permutation
perm = Int -> [Int] -> Permutation
Perm Int
n ([Int] -> Permutation) -> [Int] -> Permutation
forall a b. (a -> b) -> a -> b
$ (Int -> Int) -> [Int] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map' (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1Int -> Int -> Int
forall a. Num a => a -> a -> a
-) ([Int] -> [Int]) -> [Int] -> [Int]
forall a b. (a -> b) -> a -> b
$ [Int]
is [Int] -> [Int] -> [Int]
forall a. [a] -> [a] -> [a]
++! [Int]
isC
ts1 :: [Dom Type]
ts1 = Impossible -> Permutation -> [Dom Type] -> [Dom Type]
forall a. Subst a => Impossible -> Permutation -> a -> a
renameP Impossible
HasCallStack => Impossible
impossible (Permutation -> Permutation
reverseP Permutation
perm) (Permutation -> [Dom Type] -> [Dom Type]
forall a. Permutation -> [a] -> [a]
permute Permutation
perm [Dom Type]
ts0)
tel' :: Tele (Dom Type)
tel' = [ArgName] -> [Dom Type] -> Tele (Dom Type)
unflattenTel (Permutation -> [ArgName] -> [ArgName]
forall a. Permutation -> [a] -> [a]
permute Permutation
perm [ArgName]
names) [Dom Type]
ts1
m :: Int
m = [Int] -> Int
forall a. Sized a => a -> Int
size [Int]
is
(Tele (Dom Type)
tel1, Tele (Dom Type)
tel2) = [Dom (ArgName, Type)] -> Tele (Dom Type)
telFromList ([Dom (ArgName, Type)] -> Tele (Dom Type))
-> ([Dom (ArgName, Type)] -> Tele (Dom Type))
-> ([Dom (ArgName, Type)], [Dom (ArgName, Type)])
-> (Tele (Dom Type), Tele (Dom Type))
forall b c b' c'. (b -> c) -> (b' -> c') -> (b, b') -> (c, c')
forall (a :: * -> * -> *) b c b' c'.
Arrow a =>
a b c -> a b' c' -> a (b, b') (c, c')
*** [Dom (ArgName, Type)] -> Tele (Dom Type)
telFromList (([Dom (ArgName, Type)], [Dom (ArgName, Type)])
-> (Tele (Dom Type), Tele (Dom Type)))
-> ([Dom (ArgName, Type)], [Dom (ArgName, Type)])
-> (Tele (Dom Type), Tele (Dom Type))
forall a b. (a -> b) -> a -> b
$ Int
-> [Dom (ArgName, Type)]
-> ([Dom (ArgName, Type)], [Dom (ArgName, Type)])
forall a. Int -> [a] -> ([a], [a])
splitAt' Int
m ([Dom (ArgName, Type)]
-> ([Dom (ArgName, Type)], [Dom (ArgName, Type)]))
-> [Dom (ArgName, Type)]
-> ([Dom (ArgName, Type)], [Dom (ArgName, Type)])
forall a b. (a -> b) -> a -> b
$ Tele (Dom Type) -> [Dom (ArgName, Type)]
forall t. Tele (Dom t) -> [Dom (ArgName, t)]
telToList Tele (Dom Type)
tel'
instantiateTelescope
:: Telescope
-> Int
-> DeBruijnPattern
-> Maybe (Telescope,
PatternSubstitution,
Permutation)
instantiateTelescope :: Tele (Dom Type)
-> Int
-> Pattern' DBPatVar
-> Maybe (Tele (Dom Type), PatternSubstitution, Permutation)
instantiateTelescope Tele (Dom Type)
tel Int
k Pattern' DBPatVar
p = Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard Bool
ok Maybe ()
-> (Tele (Dom Type), PatternSubstitution, Permutation)
-> Maybe (Tele (Dom Type), PatternSubstitution, Permutation)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> (Tele (Dom Type)
tel', PatternSubstitution
sigma, Permutation -> Permutation
reverseP Permutation
perm)
where
names :: [ArgName]
names = Tele (Dom Type) -> [ArgName]
teleNames Tele (Dom Type)
tel
ts0 :: [Dom Type]
ts0 = Tele (Dom Type) -> [Dom Type]
forall a. TermSubst a => Tele (Dom a) -> [Dom a]
flattenTel Tele (Dom Type)
tel
n :: Int
n = Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
tel
j :: Int
j = Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1Int -> Int -> Int
forall a. Num a => a -> a -> a
-Int
k
u :: Term
u = Pattern' DBPatVar -> Term
patternToTerm Pattern' DBPatVar
p
is0 :: VarSet
is0 = Tele (Dom Type) -> VarSet -> VarSet
varDependencies Tele (Dom Type)
tel (VarSet -> VarSet) -> VarSet -> VarSet
forall a b. (a -> b) -> a -> b
$ Term -> VarSet
forall t. Free t => t -> VarSet
freeVarSet Term
u
is1 :: VarSet
is1 = Tele (Dom Type) -> VarSet -> VarSet
varDependents Tele (Dom Type)
tel (VarSet -> VarSet) -> VarSet -> VarSet
forall a b. (a -> b) -> a -> b
$ Int -> VarSet
forall el coll. Singleton el coll => el -> coll
singleton Int
j
lasti :: Int
lasti = Int -> Maybe Int -> Int
forall a. a -> Maybe a -> a
fromMaybe Int
n (Maybe Int -> Int) -> Maybe Int -> Int
forall a b. (a -> b) -> a -> b
$ VarSet -> Maybe Int
VarSet.lookupMin VarSet
is0
([Int]
as,[Int]
bs) = (Int -> Bool) -> [Int] -> ([Int], [Int])
forall a. (a -> Bool) -> [a] -> ([a], [a])
List.partition (Int -> VarSet -> Bool
`VarSet.member` VarSet
is1) [ Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1 , Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
2 .. Int
lasti ]
is :: [Int]
is = [Int] -> [Int]
forall a. [a] -> [a]
reverse ([Int] -> [Int]) -> [Int] -> [Int]
forall a b. (a -> b) -> a -> b
$ [Int]
bs [Int] -> [Int] -> [Int]
forall a. [a] -> [a] -> [a]
++! [Int]
as [Int] -> [Int] -> [Int]
forall a. [a] -> [a] -> [a]
++! Int -> [Int]
forall a. Integral a => a -> [a]
downFrom Int
lasti
perm :: Permutation
perm = Int -> [Int] -> Permutation
Perm Int
n [Int]
is
ok :: Bool
ok = Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ Int
j Int -> VarSet -> Bool
`VarSet.member` VarSet
is0
perm' :: Permutation
perm' = Int -> Permutation -> Permutation
deleteP Int
j Permutation
perm
permL' :: Permutation
permL' = Permutation -> Permutation
reverseP Permutation
perm'
j' :: Int
j' = Int -> Maybe Int -> Int
forall a. a -> Maybe a -> a
fromMaybe Int
forall a. HasCallStack => a
__IMPOSSIBLE__ (Maybe Int -> Int) -> Maybe Int -> Int
forall a b. (a -> b) -> a -> b
$ Permutation -> Int -> Maybe Int
lookupRP Permutation
perm Int
j
p1 :: Pattern' DBPatVar
p1 = Impossible -> Permutation -> Pattern' DBPatVar -> Pattern' DBPatVar
forall a. Subst a => Impossible -> Permutation -> a -> a
renameP Impossible
HasCallStack => Impossible
impossible Permutation
perm' Pattern' DBPatVar
p
sigma :: PatternSubstitution
sigma = Int -> Pattern' DBPatVar -> PatternSubstitution
forall a. DeBruijn a => Int -> a -> Substitution' a
singletonS Int
j' Pattern' DBPatVar
p1 PatternSubstitution -> PatternSubstitution -> PatternSubstitution
forall a.
EndoSubst a =>
Substitution' a -> Substitution' a -> Substitution' a
`composeS` Impossible -> Permutation -> PatternSubstitution
forall a.
DeBruijn a =>
Impossible -> Permutation -> Substitution' a
renaming Impossible
HasCallStack => Impossible
impossible Permutation
perm
ts1 :: [Dom Type]
ts1 = Permutation -> [Dom Type] -> [Dom Type]
forall a. Permutation -> [a] -> [a]
permute Permutation
permL' ([Dom Type] -> [Dom Type]) -> [Dom Type] -> [Dom Type]
forall a b. (a -> b) -> a -> b
$ PatternSubstitution -> [Dom Type] -> [Dom Type]
forall a. TermSubst a => PatternSubstitution -> a -> a
applyPatSubst PatternSubstitution
sigma [Dom Type]
ts0
tel' :: Tele (Dom Type)
tel' = [ArgName] -> [Dom Type] -> Tele (Dom Type)
unflattenTel (Permutation -> [ArgName] -> [ArgName]
forall a. Permutation -> [a] -> [a]
permute Permutation
permL' [ArgName]
names) [Dom Type]
ts1
expandTelescopeVar
:: Telescope
-> Int
-> Telescope
-> ConHead
-> ( Telescope
, PatternSubstitution)
expandTelescopeVar :: Tele (Dom Type)
-> Int
-> Tele (Dom Type)
-> ConHead
-> (Tele (Dom Type), PatternSubstitution)
expandTelescopeVar Tele (Dom Type)
gamma Int
k Tele (Dom Type)
delta ConHead
c = (Tele (Dom Type)
tel', PatternSubstitution
rho)
where
([Dom (ArgName, Type)]
ts1,Dom (ArgName, Type)
xa:[Dom (ArgName, Type)]
ts2) = ([Dom (ArgName, Type)], [Dom (ArgName, Type)])
-> Maybe ([Dom (ArgName, Type)], [Dom (ArgName, Type)])
-> ([Dom (ArgName, Type)], [Dom (ArgName, Type)])
forall a. a -> Maybe a -> a
fromMaybe ([Dom (ArgName, Type)], [Dom (ArgName, Type)])
forall a. HasCallStack => a
__IMPOSSIBLE__ (Maybe ([Dom (ArgName, Type)], [Dom (ArgName, Type)])
-> ([Dom (ArgName, Type)], [Dom (ArgName, Type)]))
-> Maybe ([Dom (ArgName, Type)], [Dom (ArgName, Type)])
-> ([Dom (ArgName, Type)], [Dom (ArgName, Type)])
forall a b. (a -> b) -> a -> b
$
Int
-> [Dom (ArgName, Type)]
-> Maybe ([Dom (ArgName, Type)], [Dom (ArgName, Type)])
forall n a. Integral n => n -> [a] -> Maybe ([a], [a])
splitExactlyAt Int
k ([Dom (ArgName, Type)]
-> Maybe ([Dom (ArgName, Type)], [Dom (ArgName, Type)]))
-> [Dom (ArgName, Type)]
-> Maybe ([Dom (ArgName, Type)], [Dom (ArgName, Type)])
forall a b. (a -> b) -> a -> b
$ Tele (Dom Type) -> [Dom (ArgName, Type)]
forall t. Tele (Dom t) -> [Dom (ArgName, t)]
telToList Tele (Dom Type)
gamma
a :: Dom Type
a = Int -> Dom Type -> Dom Type
forall a. Subst a => Int -> a -> a
raise (Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
delta) ((ArgName, Type) -> Type
forall a b. (a, b) -> b
snd ((ArgName, Type) -> Type) -> Dom (ArgName, Type) -> Dom Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Dom (ArgName, Type)
xa)
cpi :: ConPatternInfo
cpi = ConPatternInfo
{ conPInfo :: PatternInfo
conPInfo = PatternInfo
defaultPatternInfo
, conPRecord :: Bool
conPRecord = Bool
True
, conPFallThrough :: Bool
conPFallThrough
= Bool
False
, conPType :: Maybe (Arg Type)
conPType = 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
$ Dom Type -> Arg Type
forall t a. Dom' t a -> Arg a
argFromDom Dom Type
a
, conPLazy :: Bool
conPLazy = Bool
True
}
cargs :: [NamedArg (Pattern' DBPatVar)]
cargs = (NamedArg (Pattern' DBPatVar) -> NamedArg (Pattern' DBPatVar))
-> [NamedArg (Pattern' DBPatVar)] -> [NamedArg (Pattern' DBPatVar)]
forall a b. (a -> b) -> [a] -> [b]
map' (Origin
-> NamedArg (Pattern' DBPatVar) -> NamedArg (Pattern' DBPatVar)
forall a. LensOrigin a => Origin -> a -> a
setOrigin Origin
Inserted) ([NamedArg (Pattern' DBPatVar)] -> [NamedArg (Pattern' DBPatVar)])
-> [NamedArg (Pattern' DBPatVar)] -> [NamedArg (Pattern' DBPatVar)]
forall a b. (a -> b) -> a -> b
$ Tele (Dom Type) -> [NamedArg (Pattern' DBPatVar)]
forall a t. DeBruijn a => Tele (Dom t) -> [NamedArg a]
teleNamedArgs Tele (Dom Type)
delta
cdelta :: Pattern' DBPatVar
cdelta = ConHead
-> ConPatternInfo
-> [NamedArg (Pattern' DBPatVar)]
-> Pattern' DBPatVar
forall x.
ConHead -> ConPatternInfo -> [NamedArg (Pattern' x)] -> Pattern' x
ConP ConHead
c ConPatternInfo
cpi [NamedArg (Pattern' DBPatVar)]
cargs
rho0 :: PatternSubstitution
rho0 = Pattern' DBPatVar -> PatternSubstitution -> PatternSubstitution
forall a. DeBruijn a => a -> Substitution' a -> Substitution' a
consS Pattern' DBPatVar
cdelta (PatternSubstitution -> PatternSubstitution)
-> PatternSubstitution -> PatternSubstitution
forall a b. (a -> b) -> a -> b
$ Int -> PatternSubstitution
forall a. Int -> Substitution' a
raiseS (Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
delta)
rho :: PatternSubstitution
rho = Int -> PatternSubstitution -> PatternSubstitution
forall a. Int -> Substitution' a -> Substitution' a
liftS ([Dom (ArgName, Type)] -> Int
forall a. Sized a => a -> Int
size [Dom (ArgName, Type)]
ts2) PatternSubstitution
rho0
gamma1 :: Tele (Dom Type)
gamma1 = [Dom (ArgName, Type)] -> Tele (Dom Type)
telFromList [Dom (ArgName, Type)]
ts1
gamma2' :: Tele (Dom Type)
gamma2' = PatternSubstitution -> Tele (Dom Type) -> Tele (Dom Type)
forall a. TermSubst a => PatternSubstitution -> a -> a
applyPatSubst PatternSubstitution
rho0 (Tele (Dom Type) -> Tele (Dom Type))
-> Tele (Dom Type) -> Tele (Dom Type)
forall a b. (a -> b) -> a -> b
$ [Dom (ArgName, Type)] -> Tele (Dom Type)
telFromList [Dom (ArgName, Type)]
ts2
tel' :: Tele (Dom Type)
tel' = Tele (Dom Type)
gamma1 Tele (Dom Type) -> Tele (Dom Type) -> Tele (Dom Type)
forall t. Abstract t => Tele (Dom Type) -> t -> t
`abstract` (Tele (Dom Type)
delta Tele (Dom Type) -> Tele (Dom Type) -> Tele (Dom Type)
forall t. Abstract t => Tele (Dom Type) -> t -> t
`abstract` Tele (Dom Type)
gamma2')
{-# INLINE telView #-}
telView :: (MonadReduce m, MonadAddContext m) => Type -> m TelView
telView :: forall (m :: * -> *).
(MonadReduce m, MonadAddContext m) =>
Type -> m TelView
telView = Int -> Type -> m TelView
forall (m :: * -> *).
(MonadReduce m, MonadAddContext m) =>
Int -> Type -> m TelView
telViewUpTo (-Int
1)
{-# INLINE telViewUpTo #-}
telViewUpTo :: (MonadReduce m, MonadAddContext m) => Int -> Type -> m TelView
telViewUpTo :: forall (m :: * -> *).
(MonadReduce m, MonadAddContext m) =>
Int -> Type -> m TelView
telViewUpTo Int
n Type
t =
Int -> (Dom Type -> Bool) -> Type -> m TelView
forall (m :: * -> *).
(MonadReduce m, MonadAddContext m) =>
Int -> (Dom Type -> Bool) -> Type -> m TelView
telViewUpTo' Int
n (Bool -> Dom Type -> Bool
forall a b. a -> b -> a
const Bool
True) Type
t
{-# SPECIALIZE telViewUpTo' :: Int -> (Dom Type -> Bool) -> Type -> TCM TelView #-}
telViewUpTo' :: (MonadReduce m, MonadAddContext m) => Int -> (Dom Type -> Bool) -> Type -> m TelView
telViewUpTo' :: forall (m :: * -> *).
(MonadReduce m, MonadAddContext m) =>
Int -> (Dom Type -> Bool) -> Type -> m TelView
telViewUpTo' Int
0 Dom Type -> Bool
p Type
t = TelView -> m TelView
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (TelView -> m TelView) -> TelView -> m TelView
forall a b. (a -> b) -> a -> b
$ Tele (Dom Type) -> Type -> TelView
forall a. Tele (Dom a) -> a -> TelV a
TelV Tele (Dom Type)
forall a. Tele a
EmptyTel Type
t
telViewUpTo' Int
n Dom Type -> Bool
p Type
t = do
t <- Type -> m Type
forall a (m :: * -> *). (Reduce a, MonadReduce m) => a -> m a
reduce Type
t
case unEl t of
Pi Dom Type
a Abs Type
b | Dom Type -> Bool
p Dom Type
a ->
let !bn :: ArgName
bn = Abs Type -> ArgName
forall a. Abs a -> ArgName
absName Abs Type
b in
Dom Type -> ArgName -> TelView -> TelView
forall a. Dom a -> ArgName -> TelV a -> TelV a
absV Dom Type
a ArgName
bn (TelView -> TelView) -> m TelView -> m TelView
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
Dom Type -> Abs Type -> (Type -> m TelView) -> m TelView
forall a (m :: * -> *) b.
(Subst a, MonadAddContext m) =>
Dom Type -> Abs a -> (a -> m b) -> m b
underAbstractionAbs Dom Type
a Abs Type
b \Type
b ->
Int -> (Dom Type -> Bool) -> Type -> m TelView
forall (m :: * -> *).
(MonadReduce m, MonadAddContext m) =>
Int -> (Dom Type -> Bool) -> Type -> m TelView
telViewUpTo' (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Dom Type -> Bool
p Type
b
Term
_ -> TelView -> m TelView
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (TelView -> m TelView) -> TelView -> m TelView
forall a b. (a -> b) -> a -> b
$ Tele (Dom Type) -> Type -> TelView
forall a. Tele (Dom a) -> a -> TelV a
TelV Tele (Dom Type)
forall a. Tele a
EmptyTel Type
t
{-# INLINE telViewPath #-}
telViewPath :: PureTCM m => Type -> m TelView
telViewPath :: forall (m :: * -> *). PureTCM m => Type -> m TelView
telViewPath = Int -> Type -> m TelView
forall (m :: * -> *). PureTCM m => Int -> Type -> m TelView
telViewUpToPath (-Int
1)
{-# SPECIALIZE telViewUpToPath :: Int -> Type -> TCM TelView #-}
telViewUpToPath :: PureTCM m => Int -> Type -> m TelView
telViewUpToPath :: forall (m :: * -> *). PureTCM m => Int -> Type -> m TelView
telViewUpToPath Int
n Type
t = if Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 then Type -> m TelView
forall {m :: * -> *} {a}. Monad m => a -> m (TelV a)
done Type
t else do
Type -> m (Either (Dom Type, Abs Type) Type)
forall (m :: * -> *).
PureTCM m =>
Type -> m (Either (Dom Type, Abs Type) Type)
pathViewAsPi Type
t m (Either (Dom Type, Abs Type) Type)
-> (Either (Dom Type, Abs Type) Type -> m TelView) -> m TelView
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Left (Dom Type
a, Abs Type
b) -> Dom Type -> Abs Type -> m TelView
recurse Dom Type
a Abs Type
b
Right (El Sort' Term
_ (Pi Dom Type
a Abs Type
b)) -> Dom Type -> Abs Type -> m TelView
recurse Dom Type
a Abs Type
b
Right Type
t -> Type -> m TelView
forall {m :: * -> *} {a}. Monad m => a -> m (TelV a)
done Type
t
where
done :: a -> m (TelV a)
done a
t = TelV a -> m (TelV a)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (TelV a -> m (TelV a)) -> TelV a -> m (TelV a)
forall a b. (a -> b) -> a -> b
$ Tele (Dom a) -> a -> TelV a
forall a. Tele (Dom a) -> a -> TelV a
TelV Tele (Dom a)
forall a. Tele a
EmptyTel a
t
recurse :: Dom Type -> Abs Type -> m TelView
recurse Dom Type
a Abs Type
b = Dom Type -> ArgName -> TelView -> TelView
forall a. Dom a -> ArgName -> TelV a -> TelV a
absV Dom Type
a (Abs Type -> ArgName
forall a. Abs a -> ArgName
absName Abs Type
b) (TelView -> TelView) -> m TelView -> m TelView
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Type -> m TelView
forall (m :: * -> *). PureTCM m => Int -> Type -> m TelView
telViewUpToPath (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) (Abs Type -> Type
forall a. Subst a => Abs a -> a
absBody Abs Type
b)
newtype Boundary' x a = Boundary { forall x a. Boundary' x a -> [(x, (a, a))]
theBoundary :: [(x,(a,a))] }
deriving (Int -> Boundary' x a -> ShowS
[Boundary' x a] -> ShowS
Boundary' x a -> String
(Int -> Boundary' x a -> ShowS)
-> (Boundary' x a -> String)
-> ([Boundary' x a] -> ShowS)
-> Show (Boundary' x a)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall x a. (Show x, Show a) => Int -> Boundary' x a -> ShowS
forall x a. (Show x, Show a) => [Boundary' x a] -> ShowS
forall x a. (Show x, Show a) => Boundary' x a -> String
$cshowsPrec :: forall x a. (Show x, Show a) => Int -> Boundary' x a -> ShowS
showsPrec :: Int -> Boundary' x a -> ShowS
$cshow :: forall x a. (Show x, Show a) => Boundary' x a -> String
show :: Boundary' x a -> String
$cshowList :: forall x a. (Show x, Show a) => [Boundary' x a] -> ShowS
showList :: [Boundary' x a] -> ShowS
Show, Boundary' x a
Boundary' x a -> Bool
Boundary' x a -> (Boundary' x a -> Bool) -> Null (Boundary' x a)
forall a. a -> (a -> Bool) -> Null a
forall x a. Boundary' x a
forall x a. Boundary' x a -> Bool
$cempty :: forall x a. Boundary' x a
empty :: Boundary' x a
$cnull :: forall x a. Boundary' x a -> Bool
null :: Boundary' x a -> Bool
Null)
type Boundary = Boundary' Int Term
type TmBoundary = Boundary' Term Term
tmBoundary :: Boundary' Int a -> Boundary' Term a
tmBoundary :: forall a. Boundary' Int a -> Boundary' Term a
tmBoundary = [(Term, (a, a))] -> Boundary' Term a
forall x a. [(x, (a, a))] -> Boundary' x a
Boundary ([(Term, (a, a))] -> Boundary' Term a)
-> (Boundary' Int a -> [(Term, (a, a))])
-> Boundary' Int a
-> Boundary' Term a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Int, (a, a)) -> (Term, (a, a)))
-> [(Int, (a, a))] -> [(Term, (a, a))]
forall a b. (a -> b) -> [a] -> [b]
map' ((Int -> Term) -> (Int, (a, a)) -> (Term, (a, a))
forall a b c. (a -> b) -> (a, c) -> (b, c)
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first Int -> Term
var) ([(Int, (a, a))] -> [(Term, (a, a))])
-> (Boundary' Int a -> [(Int, (a, a))])
-> Boundary' Int a
-> [(Term, (a, a))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Boundary' Int a -> [(Int, (a, a))]
forall x a. Boundary' x a -> [(x, (a, a))]
theBoundary
varBoundary :: Boundary' Term a -> Boundary' Int a
varBoundary :: forall a. Boundary' Term a -> Boundary' Int a
varBoundary = [(Int, (a, a))] -> Boundary' Int a
forall x a. [(x, (a, a))] -> Boundary' x a
Boundary ([(Int, (a, a))] -> Boundary' Int a)
-> (Boundary' Term a -> [(Int, (a, a))])
-> Boundary' Term a
-> Boundary' Int a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Term, (a, a)) -> (Int, (a, a)))
-> [(Term, (a, a))] -> [(Int, (a, a))]
forall a b. (a -> b) -> [a] -> [b]
map' ((Term -> Int) -> (Term, (a, a)) -> (Int, (a, a))
forall a b c. (a -> b) -> (a, c) -> (b, c)
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first Term -> Int
unVar) ([(Term, (a, a))] -> [(Int, (a, a))])
-> (Boundary' Term a -> [(Term, (a, a))])
-> Boundary' Term a
-> [(Int, (a, a))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Boundary' Term a -> [(Term, (a, a))]
forall x a. Boundary' x a -> [(x, (a, a))]
theBoundary
where
unVar :: Term -> Int
unVar (Var Int
i []) = Int
i
unVar Term
_ = Int
forall a. HasCallStack => a
__IMPOSSIBLE__
instance Subst Boundary where
type SubstArg Boundary = Term
applySubst :: Substitution' (SubstArg Boundary) -> Boundary -> Boundary
applySubst Substitution' (SubstArg Boundary)
sub = Boundary' Term Term -> Boundary
forall a. Boundary' Term a -> Boundary' Int a
varBoundary (Boundary' Term Term -> Boundary)
-> (Boundary -> Boundary' Term Term) -> Boundary -> Boundary
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Substitution' (SubstArg (Boundary' Term Term))
-> Boundary' Term Term -> Boundary' Term Term
forall a. Subst a => Substitution' (SubstArg a) -> a -> a
applySubst Substitution' (SubstArg Boundary)
Substitution' (SubstArg (Boundary' Term Term))
sub (Boundary' Term Term -> Boundary' Term Term)
-> (Boundary -> Boundary' Term Term)
-> Boundary
-> Boundary' Term Term
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Boundary -> Boundary' Term Term
forall a. Boundary' Int a -> Boundary' Term a
tmBoundary
instance Subst TmBoundary where
type SubstArg TmBoundary = Term
applySubst :: Substitution' (SubstArg (Boundary' Term Term))
-> Boundary' Term Term -> Boundary' Term Term
applySubst Substitution' (SubstArg (Boundary' Term Term))
sub = [(Term, (Term, Term))] -> Boundary' Term Term
forall x a. [(x, (a, a))] -> Boundary' x a
Boundary ([(Term, (Term, Term))] -> Boundary' Term Term)
-> (Boundary' Term Term -> [(Term, (Term, Term))])
-> Boundary' Term Term
-> Boundary' Term Term
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Substitution' (SubstArg [(Term, (Term, Term))])
-> [(Term, (Term, Term))] -> [(Term, (Term, Term))]
forall a. Subst a => Substitution' (SubstArg a) -> a -> a
applySubst Substitution' (SubstArg [(Term, (Term, Term))])
Substitution' (SubstArg (Boundary' Term Term))
sub ([(Term, (Term, Term))] -> [(Term, (Term, Term))])
-> (Boundary' Term Term -> [(Term, (Term, Term))])
-> Boundary' Term Term
-> [(Term, (Term, Term))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Boundary' Term Term -> [(Term, (Term, Term))]
forall x a. Boundary' x a -> [(x, (a, a))]
theBoundary
deriving instance (Pretty x, Pretty a) => Pretty (Boundary' x a)
{-# SPECIALIZE telViewUpToPathBoundary' :: Int -> Type -> TCM (TelView, Boundary) #-}
telViewUpToPathBoundary' :: PureTCM m => Int -> Type -> m (TelView, Boundary)
telViewUpToPathBoundary' :: forall (m :: * -> *).
PureTCM m =>
Int -> Type -> m (TelView, Boundary)
telViewUpToPathBoundary' Int
n Type
t = if Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 then Type -> m (TelView, Boundary)
forall {m :: * -> *} {b} {a}.
(Monad m, Null b) =>
a -> m (TelV a, b)
done Type
t else do
Type -> m (Either ((Dom Type, Abs Type), (Term, Term)) Type)
forall (m :: * -> *).
PureTCM m =>
Type -> m (Either ((Dom Type, Abs Type), (Term, Term)) Type)
pathViewAsPi' Type
t m (Either ((Dom Type, Abs Type), (Term, Term)) Type)
-> (Either ((Dom Type, Abs Type), (Term, Term)) Type
-> m (TelView, Boundary))
-> m (TelView, Boundary)
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Left ((Dom Type
a, Abs Type
b), (Term, Term)
xy) -> (Term, Term) -> (TelView, Boundary) -> (TelView, Boundary)
forall {a} {a}.
Subst a =>
(a, a) -> (TelV a, Boundary' Int a) -> (TelV a, Boundary' Int a)
addEndPoints (Term, Term)
xy ((TelView, Boundary) -> (TelView, Boundary))
-> m (TelView, Boundary) -> m (TelView, Boundary)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Dom Type -> Abs Type -> m (TelView, Boundary)
recurse Dom Type
a Abs Type
b
Right (El Sort' Term
_ (Pi Dom Type
a Abs Type
b)) -> Dom Type -> Abs Type -> m (TelView, Boundary)
recurse Dom Type
a Abs Type
b
Right Type
t -> Type -> m (TelView, Boundary)
forall {m :: * -> *} {b} {a}.
(Monad m, Null b) =>
a -> m (TelV a, b)
done Type
t
where
done :: a -> m (TelV a, b)
done a
t = (TelV a, b) -> m (TelV a, b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Tele (Dom a) -> a -> TelV a
forall a. Tele (Dom a) -> a -> TelV a
TelV Tele (Dom a)
forall a. Tele a
EmptyTel a
t, b
forall a. Null a => a
empty)
recurse :: Dom Type -> Abs Type -> m (TelView, Boundary)
recurse Dom Type
a Abs Type
b = (TelView -> TelView) -> (TelView, Boundary) -> (TelView, Boundary)
forall a b c. (a -> b) -> (a, c) -> (b, c)
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first (Dom Type -> ArgName -> TelView -> TelView
forall a. Dom a -> ArgName -> TelV a -> TelV a
absV Dom Type
a (Abs Type -> ArgName
forall a. Abs a -> ArgName
absName Abs Type
b)) ((TelView, Boundary) -> (TelView, Boundary))
-> m (TelView, Boundary) -> m (TelView, Boundary)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> do
Dom Type
-> Abs Type
-> (Type -> m (TelView, Boundary))
-> m (TelView, Boundary)
forall a (m :: * -> *) b.
(Subst a, MonadAddContext m) =>
Dom Type -> Abs a -> (a -> m b) -> m b
underAbstractionAbs Dom Type
a Abs Type
b ((Type -> m (TelView, Boundary)) -> m (TelView, Boundary))
-> (Type -> m (TelView, Boundary)) -> m (TelView, Boundary)
forall a b. (a -> b) -> a -> b
$ \Type
b -> Int -> Type -> m (TelView, Boundary)
forall (m :: * -> *).
PureTCM m =>
Int -> Type -> m (TelView, Boundary)
telViewUpToPathBoundary' (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Type
b
addEndPoints :: (a, a) -> (TelV a, Boundary' Int a) -> (TelV a, Boundary' Int a)
addEndPoints (a, a)
xy (telv :: TelV a
telv@(TelV Tele (Dom a)
tel a
_), Boundary [(Int, (a, a))]
cs) =
let !s :: Int
s = Tele (Dom a) -> Int
forall a. Sized a => a -> Int
size Tele (Dom a)
tel Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
in (TelV a
telv, [(Int, (a, a))] -> Boundary' Int a
forall x a. [(x, (a, a))] -> Boundary' x a
Boundary ([(Int, (a, a))] -> Boundary' Int a)
-> [(Int, (a, a))] -> Boundary' Int a
forall a b. (a -> b) -> a -> b
$ (Int
s, Int -> (a, a) -> (a, a)
forall a. Subst a => Int -> a -> a
raise (Tele (Dom a) -> Int
forall a. Sized a => a -> Int
size Tele (Dom a)
tel) (a, a)
xy) (Int, (a, a)) -> [(Int, (a, a))] -> [(Int, (a, a))]
forall a. a -> [a] -> [a]
: [(Int, (a, a))]
cs)
fullBoundary :: Telescope -> Boundary -> Boundary
fullBoundary :: Tele (Dom Type) -> Boundary -> Boundary
fullBoundary Tele (Dom Type)
tel Boundary
bs =
let es :: [Elim]
es = Tele (Dom Type) -> Boundary -> [Elim]
forall a.
DeBruijn a =>
Tele (Dom Type) -> Boundary' Int a -> [Elim' a]
teleElims Tele (Dom Type)
tel Boundary
bs
l :: Int
l = Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
tel
in [(Int, (Term, Term))] -> Boundary
forall x a. [(x, (a, a))] -> Boundary' x a
Boundary ([(Int, (Term, Term))] -> Boundary)
-> [(Int, (Term, Term))] -> Boundary
forall a b. (a -> b) -> a -> b
$ ((Int, (Term, Term)) -> (Int, (Term, Term)))
-> [(Int, (Term, Term))] -> [(Int, (Term, Term))]
forall a b. (a -> b) -> [a] -> [b]
map' (\ (Int
i, (Term, Term)
xy) -> (Int
i, (Term, Term)
xy (Term, Term) -> [Elim] -> (Term, Term)
forall t. Apply t => t -> [Elim] -> t
`applyE` (Int -> [Elim] -> [Elim]
forall a. Int -> [a] -> [a]
drop (Int
l Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
i) [Elim]
es))) ([(Int, (Term, Term))] -> [(Int, (Term, Term))])
-> [(Int, (Term, Term))] -> [(Int, (Term, Term))]
forall a b. (a -> b) -> a -> b
$ Boundary -> [(Int, (Term, Term))]
forall x a. Boundary' x a -> [(x, (a, a))]
theBoundary Boundary
bs
{-# SPECIALIZE telViewUpToPathBoundary :: Int -> Type -> TCM (TelView, Boundary) #-}
telViewUpToPathBoundary :: PureTCM m => Int -> Type -> m (TelView, Boundary)
telViewUpToPathBoundary :: forall (m :: * -> *).
PureTCM m =>
Int -> Type -> m (TelView, Boundary)
telViewUpToPathBoundary Int
i Type
a = do
(telv@(TelV tel b), bs) <- Int -> Type -> m (TelView, Boundary)
forall (m :: * -> *).
PureTCM m =>
Int -> Type -> m (TelView, Boundary)
telViewUpToPathBoundary' Int
i Type
a
return (telv, fullBoundary tel bs)
{-# INLINE telViewPathBoundary #-}
telViewPathBoundary :: PureTCM m => Type -> m (TelView, Boundary)
telViewPathBoundary :: forall (m :: * -> *). PureTCM m => Type -> m (TelView, Boundary)
telViewPathBoundary = Int -> Type -> m (TelView, Boundary)
forall (m :: * -> *).
PureTCM m =>
Int -> Type -> m (TelView, Boundary)
telViewUpToPathBoundary' (-Int
1)
teleElims :: DeBruijn a => Telescope -> Boundary' Int a -> [Elim' a]
teleElims :: forall a.
DeBruijn a =>
Tele (Dom Type) -> Boundary' Int a -> [Elim' a]
teleElims Tele (Dom Type)
tel (Boundary []) = (Arg a -> Elim' a) -> [Arg a] -> [Elim' a]
forall a b. (a -> b) -> [a] -> [b]
map' Arg a -> Elim' a
forall a. Arg a -> Elim' a
Apply ([Arg a] -> [Elim' a]) -> [Arg a] -> [Elim' a]
forall a b. (a -> b) -> a -> b
$ Tele (Dom Type) -> [Arg a]
forall a t. DeBruijn a => Tele (Dom t) -> [Arg a]
teleArgs Tele (Dom Type)
tel
teleElims Tele (Dom Type)
tel (Boundary [(Int, (a, a))]
boundary) = (Arg a -> Elim' a) -> [Arg a] -> [Elim' a]
forall a b. (a -> b) -> [a] -> [b]
map' Arg a -> Elim' a
updateArg ([Arg a] -> [Elim' a]) -> [Arg a] -> [Elim' a]
forall a b. (a -> b) -> a -> b
$ Tele (Dom Type) -> [Arg a]
forall a t. DeBruijn a => Tele (Dom t) -> [Arg a]
teleArgs Tele (Dom Type)
tel
where
matchVar :: Int -> Maybe (a, a)
matchVar Int
i = (Int, (a, a)) -> (a, a)
forall a b. (a, b) -> b
snd ((Int, (a, a)) -> (a, a)) -> Maybe (Int, (a, a)) -> Maybe (a, a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((Int, (a, a)) -> Bool) -> [(Int, (a, a))] -> Maybe (Int, (a, a))
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find ((Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
==) (Int -> Bool) -> ((Int, (a, a)) -> Int) -> (Int, (a, a)) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int, (a, a)) -> Int
forall a b. (a, b) -> a
fst) [(Int, (a, a))]
boundary
updateArg :: Arg a -> Elim' a
updateArg a :: Arg a
a@(Arg ArgInfo
info a
p) =
case a -> Maybe Int
forall a. DeBruijn a => a -> Maybe Int
deBruijnView a
p of
Just Int
i | Just (a
t,a
u) <- Int -> Maybe (a, a)
matchVar Int
i -> a -> a -> a -> Elim' a
forall a. a -> a -> a -> Elim' a
IApply a
t a
u a
p
Maybe Int
_ -> Arg a -> Elim' a
forall a. Arg a -> Elim' a
Apply Arg a
a
{-# SPECIALIZE pathViewAsPi :: Type -> TCM (Either (Dom Type, Abs Type) Type) #-}
pathViewAsPi
:: PureTCM m => Type -> m (Either (Dom Type, Abs Type) Type)
pathViewAsPi :: forall (m :: * -> *).
PureTCM m =>
Type -> m (Either (Dom Type, Abs Type) Type)
pathViewAsPi Type
t = (((Dom Type, Abs Type), (Term, Term))
-> Either (Dom Type, Abs Type) Type)
-> (Type -> Either (Dom Type, Abs Type) Type)
-> Either ((Dom Type, Abs Type), (Term, Term)) Type
-> Either (Dom Type, Abs Type) Type
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either ((Dom Type, Abs Type) -> Either (Dom Type, Abs Type) Type
forall a b. a -> Either a b
Left ((Dom Type, Abs Type) -> Either (Dom Type, Abs Type) Type)
-> (((Dom Type, Abs Type), (Term, Term)) -> (Dom Type, Abs Type))
-> ((Dom Type, Abs Type), (Term, Term))
-> Either (Dom Type, Abs Type) Type
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Dom Type, Abs Type), (Term, Term)) -> (Dom Type, Abs Type)
forall a b. (a, b) -> a
fst) Type -> Either (Dom Type, Abs Type) Type
forall a b. b -> Either a b
Right (Either ((Dom Type, Abs Type), (Term, Term)) Type
-> Either (Dom Type, Abs Type) Type)
-> m (Either ((Dom Type, Abs Type), (Term, Term)) Type)
-> m (Either (Dom Type, Abs Type) Type)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Type -> m (Either ((Dom Type, Abs Type), (Term, Term)) Type)
forall (m :: * -> *).
PureTCM m =>
Type -> m (Either ((Dom Type, Abs Type), (Term, Term)) Type)
pathViewAsPi' Type
t
{-# SPECIALIZE pathViewAsPi' :: Type -> TCM (Either ((Dom Type, Abs Type), (Term,Term)) Type) #-}
pathViewAsPi'
:: PureTCM m => Type -> m (Either ((Dom Type, Abs Type), (Term,Term)) Type)
pathViewAsPi' :: forall (m :: * -> *).
PureTCM m =>
Type -> m (Either ((Dom Type, Abs Type), (Term, Term)) Type)
pathViewAsPi' Type
t = do
m (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 m (Type -> Either ((Dom Type, Abs Type), (Term, Term)) Type)
-> m Type -> m (Either ((Dom Type, Abs Type), (Term, Term)) Type)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Type -> m Type
forall a (m :: * -> *). (Reduce a, MonadReduce m) => a -> m a
reduce Type
t
{-# SPECIALIZE pathViewAsPi'whnf :: TCM (Type -> Either ((Dom Type, Abs Type), (Term,Term)) Type) #-}
pathViewAsPi'whnf
:: (HasBuiltins m)
=> m (Type -> Either ((Dom Type, Abs Type), (Term,Term)) Type)
pathViewAsPi'whnf :: forall (m :: * -> *).
HasBuiltins m =>
m (Type -> Either ((Dom Type, Abs Type), (Term, Term)) Type)
pathViewAsPi'whnf = do
view <- m (Type -> PathView)
forall (m :: * -> *). HasBuiltins m => m (Type -> PathView)
pathView'
minterval <- getTerm' builtinInterval
return $ \case
(Type -> PathView
view -> PathType Sort' Term
s QName
l Arg Term
p Arg Term
a Arg Term
x Arg Term
y) | Just Term
interval <- Maybe Term
minterval ->
let name :: ArgName
name | Lam ArgInfo
_ (Abs ArgName
n Term
_) <- Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
a = ArgName
n
| Bool
otherwise = ArgName
"i"
in
((Dom Type, Abs Type), (Term, Term))
-> Either ((Dom Type, Abs Type), (Term, Term)) Type
forall a b. a -> Either a b
Left ( ( Type -> Dom Type
forall a t. a -> Dom' t a
defaultDom (Type -> Dom Type) -> Type -> Dom Type
forall a b. (a -> b) -> a -> b
$ Sort' Term -> Term -> Type
forall t a. Sort' t -> a -> Type'' t a
El Sort' Term
intervalSort Term
interval
, ArgName -> Type -> Abs Type
forall a. ArgName -> a -> Abs a
Abs ArgName
name (Type -> Abs Type) -> Type -> Abs Type
forall a b. (a -> b) -> a -> b
$ Sort' Term -> Term -> Type
forall t a. Sort' t -> a -> Type'' t a
El (Int -> Sort' Term -> Sort' Term
forall a. Subst a => Int -> a -> a
raise Int
1 Sort' Term
s) (Term -> Type) -> Term -> Type
forall a b. (a -> b) -> a -> b
$ Int -> Term -> Term
forall a. Subst a => Int -> a -> a
raise Int
1 (Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
a) Term -> Args -> Term
forall t. Apply t => t -> Args -> t
`apply` [Term -> Arg Term
forall a. a -> Arg a
defaultArg (Term -> Arg Term) -> Term -> Arg Term
forall a b. (a -> b) -> a -> b
$ Int -> Term
var Int
0]
)
, (Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
x, Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
y)
)
Type
t -> Type -> Either ((Dom Type, Abs Type), (Term, Term)) Type
forall a b. b -> Either a b
Right Type
t
piOrPath :: HasBuiltins m => Type -> m (Either (Dom Type, Abs Type) Type)
piOrPath :: forall (m :: * -> *).
HasBuiltins m =>
Type -> m (Either (Dom Type, Abs Type) Type)
piOrPath Type
t = do
(m (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 m (Type -> Either ((Dom Type, Abs Type), (Term, Term)) Type)
-> m Type -> m (Either ((Dom Type, Abs Type), (Term, Term)) Type)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Type -> m Type
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Type
t) m (Either ((Dom Type, Abs Type), (Term, Term)) Type)
-> (Either ((Dom Type, Abs Type), (Term, Term)) Type
-> Either (Dom Type, Abs Type) Type)
-> m (Either (Dom Type, Abs Type) Type)
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \case
Left ((Dom Type, Abs Type)
p, (Term, Term)
_) -> (Dom Type, Abs Type) -> Either (Dom Type, Abs Type) Type
forall a b. a -> Either a b
Left (Dom Type, Abs Type)
p
Right (El Sort' Term
_ (Pi Dom Type
a Abs Type
b)) -> (Dom Type, Abs Type) -> Either (Dom Type, Abs Type) Type
forall a b. a -> Either a b
Left (Dom Type
a,Abs Type
b)
Right Type
_ -> Type -> Either (Dom Type, Abs Type) Type
forall a b. b -> Either a b
Right Type
t
telView'UpToPath :: Int -> Type -> TCM TelView
telView'UpToPath :: Int -> Type -> TCM TelView
telView'UpToPath Int
n Type
t = if Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 then TCM TelView
done else do
Type -> TCMT IO (Either (Dom Type, Abs Type) Type)
forall (m :: * -> *).
HasBuiltins m =>
Type -> m (Either (Dom Type, Abs Type) Type)
piOrPath Type
t TCMT IO (Either (Dom Type, Abs Type) Type)
-> (Either (Dom Type, Abs Type) Type -> TCM TelView) -> TCM TelView
forall a b. TCMT IO a -> (a -> TCMT IO b) -> TCMT IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Left (Dom Type
a, Abs Type
b) -> Dom Type -> ArgName -> TelView -> TelView
forall a. Dom a -> ArgName -> TelV a -> TelV a
absV Dom Type
a (Abs Type -> ArgName
forall a. Abs a -> ArgName
absName Abs Type
b) (TelView -> TelView) -> TCM TelView -> TCM TelView
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Type -> TCM TelView
forall (m :: * -> *). PureTCM m => Int -> Type -> m TelView
telViewUpToPath (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) (Abs Type -> Type
forall a. Subst a => Abs a -> a
absBody Abs Type
b)
Right Type
_ -> TCM TelView
done
where
done :: TCM TelView
done = TelView -> TCM TelView
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (TelView -> TCM TelView) -> TelView -> TCM TelView
forall a b. (a -> b) -> a -> b
$ Tele (Dom Type) -> Type -> TelView
forall a. Tele (Dom a) -> a -> TelV a
TelV Tele (Dom Type)
forall a. Tele a
EmptyTel Type
t
telView'Path :: Type -> TCM TelView
telView'Path :: Type -> TCM TelView
telView'Path = Int -> Type -> TCM TelView
telView'UpToPath (-Int
1)
isPath :: PureTCM m => Type -> m (Maybe (Dom Type, Abs Type))
isPath :: forall (m :: * -> *).
PureTCM m =>
Type -> m (Maybe (Dom Type, Abs Type))
isPath Type
t = Type
-> (Dom Type -> Abs Type -> m (Maybe (Dom Type, Abs Type)))
-> (Type -> m (Maybe (Dom Type, Abs Type)))
-> m (Maybe (Dom Type, Abs Type))
forall (m :: * -> *) a.
PureTCM m =>
Type -> (Dom Type -> Abs Type -> m a) -> (Type -> m a) -> m a
ifPath Type
t (\Dom Type
a Abs Type
b -> Maybe (Dom Type, Abs Type) -> m (Maybe (Dom Type, Abs Type))
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (Dom Type, Abs Type) -> m (Maybe (Dom Type, Abs Type)))
-> Maybe (Dom Type, Abs Type) -> m (Maybe (Dom Type, Abs Type))
forall a b. (a -> b) -> a -> b
$ (Dom Type, Abs Type) -> Maybe (Dom Type, Abs Type)
forall a. a -> Maybe a
Just (Dom Type
a,Abs Type
b)) (m (Maybe (Dom Type, Abs Type))
-> Type -> m (Maybe (Dom Type, Abs Type))
forall a b. a -> b -> a
const (m (Maybe (Dom Type, Abs Type))
-> Type -> m (Maybe (Dom Type, Abs Type)))
-> m (Maybe (Dom Type, Abs Type))
-> Type
-> m (Maybe (Dom Type, Abs Type))
forall a b. (a -> b) -> a -> b
$ Maybe (Dom Type, Abs Type) -> m (Maybe (Dom Type, Abs Type))
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (Dom Type, Abs Type)
forall a. Maybe a
Nothing)
ifPath :: PureTCM m => Type -> (Dom Type -> Abs Type -> m a) -> (Type -> m a) -> m a
ifPath :: forall (m :: * -> *) a.
PureTCM m =>
Type -> (Dom Type -> Abs Type -> m a) -> (Type -> m a) -> m a
ifPath Type
t Dom Type -> Abs Type -> m a
yes Type -> m a
no = Type
-> (Dom Type -> Abs Type -> m a) -> (Blocked Type -> m a) -> m a
forall (m :: * -> *) a.
PureTCM m =>
Type
-> (Dom Type -> Abs Type -> m a) -> (Blocked Type -> m a) -> m a
ifPathB Type
t Dom Type -> Abs Type -> m a
yes ((Blocked Type -> m a) -> m a) -> (Blocked Type -> m a) -> m a
forall a b. (a -> b) -> a -> b
$ Type -> m a
no (Type -> m a) -> (Blocked Type -> Type) -> Blocked Type -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Blocked Type -> Type
forall t a. Blocked' t a -> a
ignoreBlocking
{-# SPECIALIZE ifPathB :: Type -> (Dom Type -> Abs Type -> TCM a) -> (Blocked Type -> TCM a) -> TCM a #-}
ifPathB :: PureTCM m => Type -> (Dom Type -> Abs Type -> m a) -> (Blocked Type -> m a) -> m a
ifPathB :: forall (m :: * -> *) a.
PureTCM m =>
Type
-> (Dom Type -> Abs Type -> m a) -> (Blocked Type -> m a) -> m a
ifPathB Type
t Dom Type -> Abs Type -> m a
yes Blocked Type -> m a
no = Type
-> (Blocker -> Type -> m a) -> (NotBlocked -> Type -> m a) -> m a
forall t (m :: * -> *) a.
(Reduce t, IsMeta t, MonadReduce m) =>
t -> (Blocker -> t -> m a) -> (NotBlocked -> t -> m a) -> m a
ifBlocked Type
t
(\Blocker
b Type
t -> Blocked Type -> m a
no (Blocked Type -> m a) -> Blocked Type -> m a
forall a b. (a -> b) -> a -> b
$ Blocker -> Type -> Blocked Type
forall t a. Blocker -> a -> Blocked' t a
Blocked Blocker
b Type
t)
(\NotBlocked
nb Type
t -> m (Either ((Dom Type, Abs Type), (Term, Term)) Type)
-> (((Dom Type, Abs Type), (Term, Term)) -> m a)
-> (Type -> m a)
-> m a
forall (m :: * -> *) a b c.
Monad m =>
m (Either a b) -> (a -> m c) -> (b -> m c) -> m c
caseEitherM (m (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 m (Type -> Either ((Dom Type, Abs Type), (Term, Term)) Type)
-> m Type -> m (Either ((Dom Type, Abs Type), (Term, Term)) Type)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Type -> m Type
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Type
t)
((Dom Type -> Abs Type -> m a) -> (Dom Type, Abs Type) -> m a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Dom Type -> Abs Type -> m a
yes ((Dom Type, Abs Type) -> m a)
-> (((Dom Type, Abs Type), (Term, Term)) -> (Dom Type, Abs Type))
-> ((Dom Type, Abs Type), (Term, Term))
-> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Dom Type, Abs Type), (Term, Term)) -> (Dom Type, Abs Type)
forall a b. (a, b) -> a
fst)
(Blocked Type -> m a
no (Blocked Type -> m a) -> (Type -> Blocked Type) -> Type -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NotBlocked -> Type -> Blocked Type
forall t a. NotBlocked' t -> a -> Blocked' t a
NotBlocked NotBlocked
nb))
ifNotPathB :: PureTCM m => Type -> (Blocked Type -> m a) -> (Dom Type -> Abs Type -> m a) -> m a
ifNotPathB :: forall (m :: * -> *) a.
PureTCM m =>
Type
-> (Blocked Type -> m a) -> (Dom Type -> Abs Type -> m a) -> m a
ifNotPathB = ((Dom Type -> Abs Type -> m a) -> (Blocked Type -> m a) -> m a)
-> (Blocked Type -> m a) -> (Dom Type -> Abs Type -> m a) -> m a
forall a b c. (a -> b -> c) -> b -> a -> c
flip (((Dom Type -> Abs Type -> m a) -> (Blocked Type -> m a) -> m a)
-> (Blocked Type -> m a) -> (Dom Type -> Abs Type -> m a) -> m a)
-> (Type
-> (Dom Type -> Abs Type -> m a) -> (Blocked Type -> m a) -> m a)
-> Type
-> (Blocked Type -> m a)
-> (Dom Type -> Abs Type -> m a)
-> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Type
-> (Dom Type -> Abs Type -> m a) -> (Blocked Type -> m a) -> m a
forall (m :: * -> *) a.
PureTCM m =>
Type
-> (Dom Type -> Abs Type -> m a) -> (Blocked Type -> m a) -> m a
ifPathB
ifPiOrPathB :: PureTCM m => Type -> (Dom Type -> Abs Type -> m a) -> (Blocked Type -> m a) -> m a
ifPiOrPathB :: forall (m :: * -> *) a.
PureTCM m =>
Type
-> (Dom Type -> Abs Type -> m a) -> (Blocked Type -> m a) -> m a
ifPiOrPathB Type
t Dom Type -> Abs Type -> m a
yes Blocked Type -> m a
no = Type
-> (Dom Type -> Abs Type -> m a) -> (Blocked Type -> m a) -> m a
forall (m :: * -> *) a.
MonadReduce m =>
Type
-> (Dom Type -> Abs Type -> m a) -> (Blocked Type -> m a) -> m a
ifPiTypeB Type
t
(\Dom Type
a Abs Type
b -> Dom Type -> Abs Type -> m a
yes Dom Type
a Abs Type
b)
(\Blocked Type
bt -> m (Either ((Dom Type, Abs Type), (Term, Term)) Type)
-> (((Dom Type, Abs Type), (Term, Term)) -> m a)
-> (Type -> m a)
-> m a
forall (m :: * -> *) a b c.
Monad m =>
m (Either a b) -> (a -> m c) -> (b -> m c) -> m c
caseEitherM (m (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 m (Type -> Either ((Dom Type, Abs Type), (Term, Term)) Type)
-> m Type -> m (Either ((Dom Type, Abs Type), (Term, Term)) Type)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Type -> m Type
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Blocked Type -> Type
forall t a. Blocked' t a -> a
ignoreBlocking Blocked Type
bt))
((Dom Type -> Abs Type -> m a) -> (Dom Type, Abs Type) -> m a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Dom Type -> Abs Type -> m a
yes ((Dom Type, Abs Type) -> m a)
-> (((Dom Type, Abs Type), (Term, Term)) -> (Dom Type, Abs Type))
-> ((Dom Type, Abs Type), (Term, Term))
-> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Dom Type, Abs Type), (Term, Term)) -> (Dom Type, Abs Type)
forall a b. (a, b) -> a
fst)
(Blocked Type -> m a
no (Blocked Type -> m a) -> (Type -> Blocked Type) -> Type -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Blocked Type
bt Blocked Type -> Type -> Blocked Type
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$>)))
ifNotPiOrPathB :: PureTCM m => Type -> (Blocked Type -> m a) -> (Dom Type -> Abs Type -> m a) -> m a
ifNotPiOrPathB :: forall (m :: * -> *) a.
PureTCM m =>
Type
-> (Blocked Type -> m a) -> (Dom Type -> Abs Type -> m a) -> m a
ifNotPiOrPathB = ((Dom Type -> Abs Type -> m a) -> (Blocked Type -> m a) -> m a)
-> (Blocked Type -> m a) -> (Dom Type -> Abs Type -> m a) -> m a
forall a b c. (a -> b -> c) -> b -> a -> c
flip (((Dom Type -> Abs Type -> m a) -> (Blocked Type -> m a) -> m a)
-> (Blocked Type -> m a) -> (Dom Type -> Abs Type -> m a) -> m a)
-> (Type
-> (Dom Type -> Abs Type -> m a) -> (Blocked Type -> m a) -> m a)
-> Type
-> (Blocked Type -> m a)
-> (Dom Type -> Abs Type -> m a)
-> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Type
-> (Dom Type -> Abs Type -> m a) -> (Blocked Type -> m a) -> m a
forall (m :: * -> *) a.
PureTCM m =>
Type
-> (Dom Type -> Abs Type -> m a) -> (Blocked Type -> m a) -> m a
ifPiOrPathB
telePatterns :: DeBruijn a => Telescope -> Boundary -> [NamedArg (Pattern' a)]
telePatterns :: forall a.
DeBruijn a =>
Tele (Dom Type) -> Boundary -> [NamedArg (Pattern' a)]
telePatterns = (forall a. DeBruijn a => Tele (Dom Type) -> [NamedArg a])
-> Tele (Dom Type) -> Boundary -> [NamedArg (Pattern' a)]
forall a.
DeBruijn a =>
(forall a. DeBruijn a => Tele (Dom Type) -> [NamedArg a])
-> Tele (Dom Type) -> Boundary -> [NamedArg (Pattern' a)]
telePatterns' Tele (Dom Type) -> [NamedArg a]
forall a. DeBruijn a => Tele (Dom Type) -> [NamedArg a]
forall a t. DeBruijn a => Tele (Dom t) -> [NamedArg a]
teleNamedArgs
telePatterns' :: DeBruijn a =>
(forall a. (DeBruijn a) => Telescope -> [NamedArg a]) -> Telescope -> Boundary -> [NamedArg (Pattern' a)]
telePatterns' :: forall a.
DeBruijn a =>
(forall a. DeBruijn a => Tele (Dom Type) -> [NamedArg a])
-> Tele (Dom Type) -> Boundary -> [NamedArg (Pattern' a)]
telePatterns' forall a. DeBruijn a => Tele (Dom Type) -> [NamedArg a]
f Tele (Dom Type)
tel (Boundary []) = Tele (Dom Type) -> [NamedArg (Pattern' a)]
forall a. DeBruijn a => Tele (Dom Type) -> [NamedArg a]
f Tele (Dom Type)
tel
telePatterns' forall a. DeBruijn a => Tele (Dom Type) -> [NamedArg a]
f Tele (Dom Type)
tel (Boundary [(Int, (Term, Term))]
boundary) = [Arg (Named NamedName a)] -> [NamedArg (Pattern' a)]
recurse ([Arg (Named NamedName a)] -> [NamedArg (Pattern' a)])
-> [Arg (Named NamedName a)] -> [NamedArg (Pattern' a)]
forall a b. (a -> b) -> a -> b
$ Tele (Dom Type) -> [Arg (Named NamedName a)]
forall a. DeBruijn a => Tele (Dom Type) -> [NamedArg a]
f Tele (Dom Type)
tel
where
recurse :: [Arg (Named NamedName a)] -> [NamedArg (Pattern' a)]
recurse = ((Arg (Named NamedName a) -> NamedArg (Pattern' a))
-> [Arg (Named NamedName a)] -> [NamedArg (Pattern' a)]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Arg (Named NamedName a) -> NamedArg (Pattern' a))
-> [Arg (Named NamedName a)] -> [NamedArg (Pattern' a)])
-> ((a -> Pattern' a)
-> Arg (Named NamedName a) -> NamedArg (Pattern' a))
-> (a -> Pattern' a)
-> [Arg (Named NamedName a)]
-> [NamedArg (Pattern' a)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Named NamedName a -> Named NamedName (Pattern' a))
-> Arg (Named NamedName a) -> NamedArg (Pattern' a)
forall a b. (a -> b) -> Arg a -> Arg b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Named NamedName a -> Named NamedName (Pattern' a))
-> Arg (Named NamedName a) -> NamedArg (Pattern' a))
-> ((a -> Pattern' a)
-> Named NamedName a -> Named NamedName (Pattern' a))
-> (a -> Pattern' a)
-> Arg (Named NamedName a)
-> NamedArg (Pattern' a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Pattern' a)
-> Named NamedName a -> Named NamedName (Pattern' a)
forall a b. (a -> b) -> Named NamedName a -> Named NamedName b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap) a -> Pattern' a
updateVar
matchVar :: Int -> Maybe (Term, Term)
matchVar Int
i = (Int, (Term, Term)) -> (Term, Term)
forall a b. (a, b) -> b
snd ((Int, (Term, Term)) -> (Term, Term))
-> Maybe (Int, (Term, Term)) -> Maybe (Term, Term)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((Int, (Term, Term)) -> Bool)
-> [(Int, (Term, Term))] -> Maybe (Int, (Term, Term))
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find ((Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
==) (Int -> Bool)
-> ((Int, (Term, Term)) -> Int) -> (Int, (Term, Term)) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int, (Term, Term)) -> Int
forall a b. (a, b) -> a
fst) [(Int, (Term, Term))]
boundary
updateVar :: a -> Pattern' a
updateVar a
x =
case a -> Maybe Int
forall a. DeBruijn a => a -> Maybe Int
deBruijnView a
x of
Just Int
i | Just (Term
t,Term
u) <- Int -> Maybe (Term, Term)
matchVar Int
i -> PatternInfo -> Term -> Term -> a -> Pattern' a
forall x. PatternInfo -> Term -> Term -> x -> Pattern' x
IApplyP PatternInfo
defaultPatternInfo Term
t Term
u a
x
Maybe Int
_ -> PatternInfo -> a -> Pattern' a
forall x. PatternInfo -> x -> Pattern' x
VarP PatternInfo
defaultPatternInfo a
x
mustBePi :: MonadReduce m => Type -> m (Dom Type, Abs Type)
mustBePi :: forall (m :: * -> *).
MonadReduce m =>
Type -> m (Dom Type, Abs Type)
mustBePi Type
t = Type
-> (Type -> m (Dom Type, Abs Type))
-> (Dom Type -> Abs Type -> m (Dom Type, Abs Type))
-> m (Dom Type, Abs Type)
forall (m :: * -> *) a.
MonadReduce m =>
Type -> (Type -> m a) -> (Dom Type -> Abs Type -> m a) -> m a
ifNotPiType Type
t Type -> m (Dom Type, Abs Type)
forall a. HasCallStack => a
__IMPOSSIBLE__ ((Dom Type -> Abs Type -> m (Dom Type, Abs Type))
-> m (Dom Type, Abs Type))
-> (Dom Type -> Abs Type -> m (Dom Type, Abs Type))
-> m (Dom Type, Abs Type)
forall a b. (a -> b) -> a -> b
$ ((Dom Type, Abs Type) -> m (Dom Type, Abs Type))
-> Dom Type -> Abs Type -> m (Dom Type, Abs Type)
forall a b c. ((a, b) -> c) -> a -> b -> c
curry (Dom Type, Abs Type) -> m (Dom Type, Abs Type)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
ifPi :: MonadReduce m => Term -> (Dom Type -> Abs Type -> m a) -> (Term -> m a) -> m a
ifPi :: forall (m :: * -> *) a.
MonadReduce m =>
Term -> (Dom Type -> Abs Type -> m a) -> (Term -> m a) -> m a
ifPi Term
t Dom Type -> Abs Type -> m a
yes Term -> m a
no = Term
-> (Dom Type -> Abs Type -> m a) -> (Blocked Term -> m a) -> m a
forall (m :: * -> *) a.
MonadReduce m =>
Term
-> (Dom Type -> Abs Type -> m a) -> (Blocked Term -> m a) -> m a
ifPiB Term
t Dom Type -> Abs Type -> m a
yes (Term -> m a
no (Term -> m a) -> (Blocked Term -> Term) -> Blocked Term -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Blocked Term -> Term
forall t a. Blocked' t a -> a
ignoreBlocking)
ifPiB :: (MonadReduce m) => Term -> (Dom Type -> Abs Type -> m a) -> (Blocked Term -> m a) -> m a
ifPiB :: forall (m :: * -> *) a.
MonadReduce m =>
Term
-> (Dom Type -> Abs Type -> m a) -> (Blocked Term -> m a) -> m a
ifPiB Term
t Dom Type -> Abs Type -> m a
yes Blocked Term -> m a
no = Term
-> (Blocker -> Term -> m a) -> (NotBlocked -> Term -> m a) -> m a
forall t (m :: * -> *) a.
(Reduce t, IsMeta t, MonadReduce m) =>
t -> (Blocker -> t -> m a) -> (NotBlocked -> t -> m a) -> m a
ifBlocked Term
t
(\Blocker
b Term
t -> Blocked Term -> m a
no (Blocked Term -> m a) -> Blocked Term -> m a
forall a b. (a -> b) -> a -> b
$ Blocker -> Term -> Blocked Term
forall t a. Blocker -> a -> Blocked' t a
Blocked Blocker
b Term
t)
(\NotBlocked
nb Term
t -> case Term
t of
Pi Dom Type
a Abs Type
b -> Dom Type -> Abs Type -> m a
yes Dom Type
a Abs Type
b
Term
_ -> Blocked Term -> m a
no (Blocked Term -> m a) -> Blocked Term -> m a
forall a b. (a -> b) -> a -> b
$ NotBlocked -> Term -> Blocked Term
forall t a. NotBlocked' t -> a -> Blocked' t a
NotBlocked NotBlocked
nb Term
t)
ifPiTypeB :: (MonadReduce m) => Type -> (Dom Type -> Abs Type -> m a) -> (Blocked Type -> m a) -> m a
ifPiTypeB :: forall (m :: * -> *) a.
MonadReduce m =>
Type
-> (Dom Type -> Abs Type -> m a) -> (Blocked Type -> m a) -> m a
ifPiTypeB (El Sort' Term
s Term
t) Dom Type -> Abs Type -> m a
yes Blocked Type -> m a
no = Term
-> (Dom Type -> Abs Type -> m a) -> (Blocked Term -> m a) -> m a
forall (m :: * -> *) a.
MonadReduce m =>
Term
-> (Dom Type -> Abs Type -> m a) -> (Blocked Term -> m a) -> m a
ifPiB Term
t Dom Type -> Abs Type -> m a
yes (\Blocked Term
bt -> Blocked Type -> m a
no (Blocked Type -> m a) -> Blocked Type -> m a
forall a b. (a -> b) -> a -> b
$ Sort' Term -> Term -> Type
forall t a. Sort' t -> a -> Type'' t a
El Sort' Term
s (Term -> Type) -> Blocked Term -> Blocked Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Blocked Term
bt)
ifPiType :: MonadReduce m => Type -> (Dom Type -> Abs Type -> m a) -> (Type -> m a) -> m a
ifPiType :: forall (m :: * -> *) a.
MonadReduce m =>
Type -> (Dom Type -> Abs Type -> m a) -> (Type -> m a) -> m a
ifPiType (El Sort' Term
s Term
t) Dom Type -> Abs Type -> m a
yes Type -> m a
no = Term -> (Dom Type -> Abs Type -> m a) -> (Term -> m a) -> m a
forall (m :: * -> *) a.
MonadReduce m =>
Term -> (Dom Type -> Abs Type -> m a) -> (Term -> m a) -> m a
ifPi Term
t Dom Type -> Abs Type -> m a
yes (Type -> m a
no (Type -> m a) -> (Term -> Type) -> Term -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Sort' Term -> Term -> Type
forall t a. Sort' t -> a -> Type'' t a
El Sort' Term
s)
ifNotPi :: MonadReduce m => Term -> (Term -> m a) -> (Dom Type -> Abs Type -> m a) -> m a
ifNotPi :: forall (m :: * -> *) a.
MonadReduce m =>
Term -> (Term -> m a) -> (Dom Type -> Abs Type -> m a) -> m a
ifNotPi = ((Dom Type -> Abs Type -> m a) -> (Term -> m a) -> m a)
-> (Term -> m a) -> (Dom Type -> Abs Type -> m a) -> m a
forall a b c. (a -> b -> c) -> b -> a -> c
flip (((Dom Type -> Abs Type -> m a) -> (Term -> m a) -> m a)
-> (Term -> m a) -> (Dom Type -> Abs Type -> m a) -> m a)
-> (Term -> (Dom Type -> Abs Type -> m a) -> (Term -> m a) -> m a)
-> Term
-> (Term -> m a)
-> (Dom Type -> Abs Type -> m a)
-> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Term -> (Dom Type -> Abs Type -> m a) -> (Term -> m a) -> m a
forall (m :: * -> *) a.
MonadReduce m =>
Term -> (Dom Type -> Abs Type -> m a) -> (Term -> m a) -> m a
ifPi
ifNotPiType :: MonadReduce m => Type -> (Type -> m a) -> (Dom Type -> Abs Type -> m a) -> m a
ifNotPiType :: forall (m :: * -> *) a.
MonadReduce m =>
Type -> (Type -> m a) -> (Dom Type -> Abs Type -> m a) -> m a
ifNotPiType = ((Dom Type -> Abs Type -> m a) -> (Type -> m a) -> m a)
-> (Type -> m a) -> (Dom Type -> Abs Type -> m a) -> m a
forall a b c. (a -> b -> c) -> b -> a -> c
flip (((Dom Type -> Abs Type -> m a) -> (Type -> m a) -> m a)
-> (Type -> m a) -> (Dom Type -> Abs Type -> m a) -> m a)
-> (Type -> (Dom Type -> Abs Type -> m a) -> (Type -> m a) -> m a)
-> Type
-> (Type -> m a)
-> (Dom Type -> Abs Type -> m a)
-> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Type -> (Dom Type -> Abs Type -> m a) -> (Type -> m a) -> m a
forall (m :: * -> *) a.
MonadReduce m =>
Type -> (Dom Type -> Abs Type -> m a) -> (Type -> m a) -> m a
ifPiType
ifNotPiOrPathType :: (MonadReduce tcm, HasBuiltins tcm) => Type -> (Type -> tcm a) -> (Dom Type -> Abs Type -> tcm a) -> tcm a
ifNotPiOrPathType :: forall (tcm :: * -> *) a.
(MonadReduce tcm, HasBuiltins tcm) =>
Type -> (Type -> tcm a) -> (Dom Type -> Abs Type -> tcm a) -> tcm a
ifNotPiOrPathType Type
t Type -> tcm a
no Dom Type -> Abs Type -> tcm a
yes = do
Type -> (Dom Type -> Abs Type -> tcm a) -> (Type -> tcm a) -> tcm a
forall (m :: * -> *) a.
MonadReduce m =>
Type -> (Dom Type -> Abs Type -> m a) -> (Type -> m a) -> m a
ifPiType Type
t Dom Type -> Abs Type -> tcm a
yes (\ Type
t -> (((Dom Type, Abs Type), (Term, Term)) -> tcm a)
-> (Type -> tcm a)
-> Either ((Dom Type, Abs Type), (Term, Term)) Type
-> tcm a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either ((Dom Type -> Abs Type -> tcm a) -> (Dom Type, Abs Type) -> tcm a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Dom Type -> Abs Type -> tcm a
yes ((Dom Type, Abs Type) -> tcm a)
-> (((Dom Type, Abs Type), (Term, Term)) -> (Dom Type, Abs Type))
-> ((Dom Type, Abs Type), (Term, Term))
-> tcm a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Dom Type, Abs Type), (Term, Term)) -> (Dom Type, Abs Type)
forall a b. (a, b) -> a
fst) (tcm a -> Type -> tcm a
forall a b. a -> b -> a
const (tcm a -> Type -> tcm a) -> tcm a -> Type -> tcm a
forall a b. (a -> b) -> a -> b
$ Type -> tcm a
no Type
t) (Either ((Dom Type, Abs Type), (Term, Term)) Type -> tcm a)
-> tcm (Either ((Dom Type, Abs Type), (Term, Term)) Type) -> tcm a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (tcm (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 tcm (Type -> Either ((Dom Type, Abs Type), (Term, Term)) Type)
-> tcm Type
-> tcm (Either ((Dom Type, Abs Type), (Term, Term)) Type)
forall a b. tcm (a -> b) -> tcm a -> tcm b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Type -> tcm Type
forall a. a -> tcm a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Type
t))
shouldBePath :: (PureTCM m, MonadBlock m, MonadTCError m) => Type -> m (Dom Type, Abs Type)
shouldBePath :: forall (m :: * -> *).
(PureTCM m, MonadBlock m, MonadTCError m) =>
Type -> m (Dom Type, Abs Type)
shouldBePath Type
t = Type
-> (Dom Type -> Abs Type -> m (Dom Type, Abs Type))
-> (Blocked Type -> m (Dom Type, Abs Type))
-> m (Dom Type, Abs Type)
forall (m :: * -> *) a.
PureTCM m =>
Type
-> (Dom Type -> Abs Type -> m a) -> (Blocked Type -> m a) -> m a
ifPathB Type
t
(((Dom Type, Abs Type) -> m (Dom Type, Abs Type))
-> Dom Type -> Abs Type -> m (Dom Type, Abs Type)
forall a b c. ((a, b) -> c) -> a -> b -> c
curry (Dom Type, Abs Type) -> m (Dom Type, Abs Type)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return)
(Blocked Type -> m Type
forall (m :: * -> *) a. MonadBlock m => Blocked a -> m a
fromBlocked (Blocked Type -> m Type)
-> (Type -> m (Dom Type, Abs Type))
-> Blocked Type
-> m (Dom Type, Abs Type)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> \case
El Sort' Term
_ Dummy{} -> (Dom Type, Abs Type) -> m (Dom Type, Abs Type)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Dom Type
HasCallStack => Dom Type
__DUMMY_DOM__, ArgName -> Type -> Abs Type
forall a. ArgName -> a -> Abs a
Abs ArgName
"x" Type
HasCallStack => Type
__DUMMY_TYPE__)
Type
t -> TypeError -> m (Dom Type, Abs Type)
forall (m :: * -> *) e a.
(HasCallStack, MonadTCError m, Diagnostic e) =>
e -> m a
typeError (TypeError -> m (Dom Type, Abs Type))
-> TypeError -> m (Dom Type, Abs Type)
forall a b. (a -> b) -> a -> b
$ Type -> TypeError
ShouldBePath Type
t)
shouldBePi :: (PureTCM m, MonadBlock m, MonadTCError m) => Type -> m (Dom Type, Abs Type)
shouldBePi :: forall (m :: * -> *).
(PureTCM m, MonadBlock m, MonadTCError m) =>
Type -> m (Dom Type, Abs Type)
shouldBePi Type
t = Type
-> (Dom Type -> Abs Type -> m (Dom Type, Abs Type))
-> (Blocked Type -> m (Dom Type, Abs Type))
-> m (Dom Type, Abs Type)
forall (m :: * -> *) a.
MonadReduce m =>
Type
-> (Dom Type -> Abs Type -> m a) -> (Blocked Type -> m a) -> m a
ifPiTypeB Type
t
(((Dom Type, Abs Type) -> m (Dom Type, Abs Type))
-> Dom Type -> Abs Type -> m (Dom Type, Abs Type)
forall a b c. ((a, b) -> c) -> a -> b -> c
curry (Dom Type, Abs Type) -> m (Dom Type, Abs Type)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return)
(Blocked Type -> m Type
forall (m :: * -> *) a. MonadBlock m => Blocked a -> m a
fromBlocked (Blocked Type -> m Type)
-> (Type -> m (Dom Type, Abs Type))
-> Blocked Type
-> m (Dom Type, Abs Type)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> \case
El Sort' Term
_ Dummy{} -> (Dom Type, Abs Type) -> m (Dom Type, Abs Type)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Dom Type
HasCallStack => Dom Type
__DUMMY_DOM__, ArgName -> Type -> Abs Type
forall a. ArgName -> a -> Abs a
Abs ArgName
"x" Type
HasCallStack => Type
__DUMMY_TYPE__)
Type
t -> TypeError -> m (Dom Type, Abs Type)
forall (m :: * -> *) e a.
(HasCallStack, MonadTCError m, Diagnostic e) =>
e -> m a
typeError (TypeError -> m (Dom Type, Abs Type))
-> TypeError -> m (Dom Type, Abs Type)
forall a b. (a -> b) -> a -> b
$ Type -> TypeError
ShouldBePi Type
t)
shouldBePiOrPath :: (PureTCM m, MonadBlock m, MonadTCError m) => Type -> m (Dom Type, Abs Type, Boundary)
shouldBePiOrPath :: forall (m :: * -> *).
(PureTCM m, MonadBlock m, MonadTCError m) =>
Type -> m (Dom Type, Abs Type, Boundary)
shouldBePiOrPath Type
t = do
(TelV tel t', b) <- Int -> Type -> m (TelView, Boundary)
forall (m :: * -> *).
PureTCM m =>
Int -> Type -> m (TelView, Boundary)
telViewUpToPathBoundary Int
1 Type
t
case tel of
ExtendTel Dom Type
dom (Abs ArgName
nm Tele (Dom Type)
EmptyTel) -> (Dom Type, Abs Type, Boundary) -> m (Dom Type, Abs Type, Boundary)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Dom Type
dom, ArgName -> Type -> Abs Type
forall a. ArgName -> a -> Abs a
Abs ArgName
nm Type
t', Boundary
b)
Tele (Dom Type)
_ -> TypeError -> m (Dom Type, Abs Type, Boundary)
forall (m :: * -> *) e a.
(HasCallStack, MonadTCError m, Diagnostic e) =>
e -> m a
typeError (TypeError -> m (Dom Type, Abs Type, Boundary))
-> TypeError -> m (Dom Type, Abs Type, Boundary)
forall a b. (a -> b) -> a -> b
$ Type -> TypeError
ShouldBePi Type
t
piApplyM''
:: forall m. (MonadReduce m, HasBuiltins m)
=> m Empty
-> Type
-> [Term]
-> m Type
piApplyM'' :: forall (m :: * -> *).
(MonadReduce m, HasBuiltins m) =>
m Empty -> Type -> [Term] -> m Type
piApplyM'' m Empty
err = Substitution' Term -> Type -> [Term] -> m Type
loop Substitution' Term
forall a. Substitution' a
idS where
abort :: m Type
abort :: m Type
abort = Empty -> Type
forall a. Empty -> a
absurd (Empty -> Type) -> m Empty -> m Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Empty
err
loop :: Substitution -> Type -> [Term] -> m Type
loop :: Substitution' Term -> Type -> [Term] -> m Type
loop !Substitution' Term
rho !Type
t [] = Type -> m Type
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Type -> m Type) -> Type -> m Type
forall a b. (a -> b) -> a -> b
$! Substitution' (SubstArg Type) -> Type -> Type
forall a. Subst a => Substitution' (SubstArg a) -> a -> a
applySubst Substitution' Term
Substitution' (SubstArg Type)
rho Type
t
loop Substitution' Term
rho Type
t (Term
a:[Term]
as) = case Type -> Term
forall t a. Type'' t a -> a
unEl Type
t of
Pi Dom Type
_ Abs Type
abs -> case Abs Type
abs of
Abs ArgName
_ Type
body -> Substitution' Term -> Type -> [Term] -> m Type
loop (Term
a Term -> Substitution' Term -> Substitution' Term
forall a. DeBruijn a => a -> Substitution' a -> Substitution' a
`consS` Substitution' Term
rho) Type
body [Term]
as
NoAbs ArgName
_ Type
body -> Substitution' Term -> Type -> [Term] -> m Type
loop Substitution' Term
rho Type
body [Term]
as
Lam{} -> m Type
abort
Con{} -> m Type
abort
Lit{} -> m Type
abort
Sort{} -> m Type
abort
Level{} -> m Type
abort
Term
_ -> Type
-> (Type -> m Type) -> (Dom Type -> Abs Type -> m Type) -> m Type
forall (tcm :: * -> *) a.
(MonadReduce tcm, HasBuiltins tcm) =>
Type -> (Type -> tcm a) -> (Dom Type -> Abs Type -> tcm a) -> tcm a
ifNotPiOrPathType (Substitution' (SubstArg Type) -> Type -> Type
forall a. Subst a => Substitution' (SubstArg a) -> a -> a
applySubst Substitution' Term
Substitution' (SubstArg Type)
rho Type
t)
(\Type
_ -> m Type
abort)
(\Dom Type
_ Abs Type
b -> Substitution' Term -> Type -> [Term] -> m Type
loop Substitution' Term
forall a. Substitution' a
idS (Abs Type -> SubstArg Type -> Type
forall a. Subst a => Abs a -> SubstArg a -> a
absApp Abs Type
b Term
SubstArg Type
a) [Term]
as)
{-# SPECIALIZE piApplyM'' :: TCM Empty -> Type -> [Term] -> TCM Type #-}
class PiApplyArgs a where
toPiArgs :: a -> [Term]
instance PiApplyArgs Term where
toPiArgs :: Term -> [Term]
toPiArgs = Term -> [Term]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
pure
instance PiApplyArgs a => PiApplyArgs (Arg a) where
toPiArgs :: Arg a -> [Term]
toPiArgs = a -> [Term]
forall a. PiApplyArgs a => a -> [Term]
toPiArgs (a -> [Term]) -> (Arg a -> a) -> Arg a -> [Term]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Arg a -> a
forall e. Arg e -> e
unArg
instance PiApplyArgs a => PiApplyArgs (Named n a) where
toPiArgs :: Named n a -> [Term]
toPiArgs = a -> [Term]
forall a. PiApplyArgs a => a -> [Term]
toPiArgs (a -> [Term]) -> (Named n a -> a) -> Named n a -> [Term]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Named n a -> a
forall name a. Named name a -> a
namedThing
instance PiApplyArgs a => PiApplyArgs [a] where
toPiArgs :: [a] -> [Term]
toPiArgs = (a -> [Term]) -> [a] -> [Term]
forall a b. (a -> [b]) -> [a] -> [b]
concatMap' a -> [Term]
forall a. PiApplyArgs a => a -> [Term]
toPiArgs
piApplyM' :: (MonadReduce m, HasBuiltins m, PiApplyArgs a) => m Empty -> Type -> a -> m Type
piApplyM' :: forall (m :: * -> *) a.
(MonadReduce m, HasBuiltins m, PiApplyArgs a) =>
m Empty -> Type -> a -> m Type
piApplyM' m Empty
err Type
ty a
as = m Empty -> Type -> [Term] -> m Type
forall (m :: * -> *).
(MonadReduce m, HasBuiltins m) =>
m Empty -> Type -> [Term] -> m Type
piApplyM'' m Empty
err Type
ty ([Term] -> m Type) -> [Term] -> m Type
forall a b. (a -> b) -> a -> b
$! a -> [Term]
forall a. PiApplyArgs a => a -> [Term]
toPiArgs a
as
{-# INLINE piApplyM' #-}
piApplyM :: (MonadReduce m, HasBuiltins m, PiApplyArgs a) => Type -> a -> m Type
piApplyM :: forall (m :: * -> *) a.
(MonadReduce m, HasBuiltins m, PiApplyArgs a) =>
Type -> a -> m Type
piApplyM = m Empty -> Type -> a -> m Type
forall (m :: * -> *) a.
(MonadReduce m, HasBuiltins m, PiApplyArgs a) =>
m Empty -> Type -> a -> m Type
piApplyM' m Empty
forall a. HasCallStack => a
__IMPOSSIBLE__
{-# INLINE piApplyM #-}
typeArity :: Type -> TCM Nat
typeArity :: Type -> TCM Int
typeArity Type
t = do
TelV tel _ <- Type -> TCM TelView
forall (m :: * -> *).
(MonadReduce m, MonadAddContext m) =>
Type -> m TelView
telView Type
t
return (size tel)
foldrTelescopeM
:: MonadAddContext m
=> (Dom (ArgName, Type) -> m b -> m b)
-> m b
-> Telescope
-> m b
foldrTelescopeM :: forall (m :: * -> *) b.
MonadAddContext m =>
(Dom (ArgName, Type) -> m b -> m b)
-> m b -> Tele (Dom Type) -> m b
foldrTelescopeM Dom (ArgName, Type) -> m b -> m b
f m b
b = Tele (Dom Type) -> m b
go
where
go :: Tele (Dom Type) -> m b
go Tele (Dom Type)
EmptyTel = m b
b
go (ExtendTel Dom Type
a Abs (Tele (Dom Type))
tel) =
Dom (ArgName, Type) -> m b -> m b
f ((Abs (Tele (Dom Type)) -> ArgName
forall a. Abs a -> ArgName
absName Abs (Tele (Dom Type))
tel,) (Type -> (ArgName, Type)) -> Dom Type -> Dom (ArgName, Type)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Dom Type
a) (m b -> m b) -> m b -> m b
forall a b. (a -> b) -> a -> b
$ Dom Type
-> Abs (Tele (Dom Type)) -> (Tele (Dom Type) -> m b) -> m b
forall a (m :: * -> *) b.
(Subst a, MonadAddContext m) =>
Dom Type -> Abs a -> (a -> m b) -> m b
underAbstraction Dom Type
a Abs (Tele (Dom Type))
tel Tele (Dom Type) -> m b
go
teleApply'
:: Teletype
-> Args
-> (Telescope -> Type -> a)
-> (Type -> Args -> a)
-> a
teleApply' :: forall a.
Teletype
-> Args
-> (Tele (Dom Type) -> Type -> a)
-> (Type -> Args -> a)
-> a
teleApply' Teletype
tel Args
args Tele (Dom Type) -> Type -> a
okay Type -> Args -> a
fail =
let
go :: Substitution' Term -> Args -> Teletype -> a
go !Substitution' Term
rho [] Teletype
tt = do
let (!Tele (Dom Type)
tel, !Type
ty) = Teletype -> (Tele (Dom Type), Type)
unpackTeletype Teletype
tt
Tele (Dom Type) -> Type -> a
okay (Substitution' (SubstArg (Tele (Dom Type)))
-> Tele (Dom Type) -> Tele (Dom Type)
forall a. Subst a => Substitution' (SubstArg a) -> a -> a
applySubst Substitution' Term
Substitution' (SubstArg (Tele (Dom Type)))
rho Tele (Dom Type)
tel) (Type -> a) -> Type -> a
forall a b. (a -> b) -> a -> b
$! Substitution' (SubstArg Type) -> Type -> Type
forall a. Subst a => Substitution' (SubstArg a) -> a -> a
applySubst (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)
tel) Substitution' Term
rho) Type
ty
go Substitution' Term
rho (Arg Term
a:Args
as) Teletype
tt = case Teletype
tt of
ExtendTt Dom Type
_ Abs Teletype
b -> Substitution' Term -> Args -> Teletype -> a
go (Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
a Term -> Substitution' Term -> Substitution' Term
forall a. DeBruijn a => a -> Substitution' a -> Substitution' a
`consS` Substitution' Term
rho) Args
as (Abs Teletype -> Teletype
forall a. Subst a => Abs a -> a
absBody Abs Teletype
b)
EmptyTt Type
ty -> (Type -> Args -> a) -> Args -> Type -> a
forall a b c. (a -> b -> c) -> b -> a -> c
flip Type -> Args -> a
fail (Arg Term
aArg Term -> Args -> Args
forall a. a -> [a] -> [a]
:Args
as) (Type -> a) -> Type -> a
forall a b. (a -> b) -> a -> b
$! Substitution' (SubstArg Type) -> Type -> Type
forall a. Subst a => Substitution' (SubstArg a) -> a -> a
applySubst Substitution' Term
Substitution' (SubstArg Type)
rho Type
ty
in Substitution' Term -> Args -> Teletype -> a
go Substitution' Term
forall a. Substitution' a
idS Args
args Teletype
tel
{-# INLINE teleApply' #-}
teleApplyM
:: forall m. (HasBuiltins m, MonadReduce m)
=> m Empty
-> Teletype
-> Args
-> m Type
teleApplyM :: forall (m :: * -> *).
(HasBuiltins m, MonadReduce m) =>
m Empty -> Teletype -> Args -> m Type
teleApplyM m Empty
abort Teletype
tel Args
args = Teletype
-> Args
-> (Tele (Dom Type) -> Type -> m Type)
-> (Type -> Args -> m Type)
-> m Type
forall a.
Teletype
-> Args
-> (Tele (Dom Type) -> Type -> a)
-> (Type -> Args -> a)
-> a
teleApply' Teletype
tel Args
args (\Tele (Dom Type)
tel Type
ty -> Type -> m Type
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Type -> m Type) -> Type -> m Type
forall a b. (a -> b) -> a -> b
$! Tele (Dom Type) -> Type -> Type
telePi_ Tele (Dom Type)
tel Type
ty) (m Empty -> Type -> Args -> m Type
forall (m :: * -> *) a.
(MonadReduce m, HasBuiltins m, PiApplyArgs a) =>
m Empty -> Type -> a -> m Type
piApplyM' m Empty
abort)
{-# INLINABLE teleApplyM #-}
teleApply :: HasCallStack => Teletype -> Args -> Type
teleApply :: HasCallStack => Teletype -> Args -> Type
teleApply Teletype
tel Args
args = Teletype
-> Args
-> (Tele (Dom Type) -> Type -> Type)
-> (Type -> Args -> Type)
-> Type
forall a.
Teletype
-> Args
-> (Tele (Dom Type) -> Type -> a)
-> (Type -> Args -> a)
-> a
teleApply' Teletype
tel Args
args Tele (Dom Type) -> Type -> Type
telePi_ \Type
_ Args
_ -> Type
forall a. HasCallStack => a
__IMPOSSIBLE__
{-# INLINABLE teleApply #-}
teleView :: MonadReduce m => Teletype -> m TelView
teleView :: forall (m :: * -> *). MonadReduce m => Teletype -> m TelView
teleView Teletype
tty = ReduceM TelView -> m TelView
forall a. ReduceM a -> m a
forall (m :: * -> *) a. MonadReduce m => ReduceM a -> m a
liftReduce do
let (!Tele (Dom Type)
tel, !Type
ty) = Teletype -> (Tele (Dom Type), Type)
unpackTeletype Teletype
tty
Tele (Dom Type) -> ReduceM TelView -> ReduceM TelView
forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
forall (m :: * -> *) a.
MonadAddContext m =>
Tele (Dom Type) -> m a -> m a
addContext Tele (Dom Type)
tel do
TelV tel' ty <- Type -> ReduceM TelView
forall (m :: * -> *).
(MonadReduce m, MonadAddContext m) =>
Type -> m TelView
telView Type
ty
pure (TelV (tel `abstract` tel') ty)
{-# INLINE teleView #-}
teleType :: Telescope -> Type -> Teletype
teleType :: Tele (Dom Type) -> Type -> Teletype
teleType Tele (Dom Type)
tele Type
inty =
let
TelV Tele (Dom Type)
tele' Type
ty = Type -> TelView
telView' Type
inty
loop :: Tele (Dom Type) -> Teletype
loop Tele (Dom Type)
EmptyTel = Type -> Teletype
EmptyTt Type
ty
loop (ExtendTel Dom Type
a Abs (Tele (Dom Type))
b) = Dom Type -> Abs Teletype -> Teletype
ExtendTt Dom Type
a (Abs Teletype -> Teletype) -> Abs Teletype -> Teletype
forall a b. (a -> b) -> a -> b
$! Tele (Dom Type) -> Teletype
loop (Tele (Dom Type) -> Teletype)
-> Abs (Tele (Dom Type)) -> Abs Teletype
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Abs (Tele (Dom Type))
b
in Tele (Dom Type) -> Teletype
loop (Tele (Dom Type)
tele Tele (Dom Type) -> Tele (Dom Type) -> Tele (Dom Type)
forall t. Abstract t => Tele (Dom Type) -> t -> t
`abstract` Tele (Dom Type)
tele')
teleCons :: Dom (ArgName, Type) -> Teletype -> Teletype
teleCons :: Dom (ArgName, Type) -> Teletype -> Teletype
teleCons Dom (ArgName, Type)
dom !Teletype
tt =
let !nm :: ArgName
nm = (ArgName, Type) -> ArgName
forall a b. (a, b) -> a
fst ((ArgName, Type) -> ArgName) -> (ArgName, Type) -> ArgName
forall a b. (a -> b) -> a -> b
$ Dom (ArgName, Type) -> (ArgName, Type)
forall t e. Dom' t e -> e
unDom Dom (ArgName, Type)
dom
in Dom Type -> Abs Teletype -> Teletype
ExtendTt ((ArgName, Type) -> Type
forall a b. (a, b) -> b
snd ((ArgName, Type) -> Type) -> Dom (ArgName, Type) -> Dom Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Dom (ArgName, Type)
dom) (ArgName -> Teletype -> Abs Teletype
forall a. ArgName -> a -> Abs a
Abs ArgName
nm Teletype
tt)
{-# INLINE teleCons #-}
teleViewUpToPathBoundary :: PureTCM m => Int -> Teletype -> m (TelView, Boundary)
teleViewUpToPathBoundary :: forall (m :: * -> *).
PureTCM m =>
Int -> Teletype -> m (TelView, Boundary)
teleViewUpToPathBoundary !Int
n Teletype
tty = do
let
loop :: (Tele (Dom Type) -> Tele (Dom Type))
-> Int -> Teletype -> f (TelView, Boundary)
loop !Tele (Dom Type) -> Tele (Dom Type)
tel Int
0 Teletype
tty = do
let !ty :: Type
ty = HasCallStack => Teletype -> Args -> Type
Teletype -> Args -> Type
teleApply Teletype
tty []
(TelView, Boundary) -> f (TelView, Boundary)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Tele (Dom Type) -> Type -> TelView
forall a. Tele (Dom a) -> a -> TelV a
TelV (Tele (Dom Type) -> Tele (Dom Type)
tel Tele (Dom Type)
forall a. Tele a
EmptyTel) Type
ty, [(Int, (Term, Term))] -> Boundary
forall x a. [(x, (a, a))] -> Boundary' x a
Boundary [])
loop Tele (Dom Type) -> Tele (Dom Type)
tel Int
n Teletype
tty = case Teletype
tty of
EmptyTt Type
ty -> do
(TelV tel' ty, b) <- Tele (Dom Type) -> f (TelView, Boundary) -> f (TelView, Boundary)
forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
forall (m :: * -> *) a.
MonadAddContext m =>
Tele (Dom Type) -> m a -> m a
addContext (Tele (Dom Type) -> Tele (Dom Type)
tel Tele (Dom Type)
forall a. Tele a
EmptyTel) (f (TelView, Boundary) -> f (TelView, Boundary))
-> f (TelView, Boundary) -> f (TelView, Boundary)
forall a b. (a -> b) -> a -> b
$ Int -> Type -> f (TelView, Boundary)
forall (m :: * -> *).
PureTCM m =>
Int -> Type -> m (TelView, Boundary)
telViewUpToPathBoundary' Int
n Type
ty
pure (TelV (tel tel') ty, b)
ExtendTt Dom Type
dom Abs Teletype
abs -> (Tele (Dom Type) -> Tele (Dom Type))
-> Int -> Teletype -> f (TelView, Boundary)
loop (Tele (Dom Type) -> Tele (Dom Type)
tel (Tele (Dom Type) -> Tele (Dom Type))
-> (Tele (Dom Type) -> Tele (Dom Type))
-> Tele (Dom Type)
-> Tele (Dom Type)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dom Type -> Abs (Tele (Dom Type)) -> Tele (Dom Type)
forall a. a -> Abs (Tele a) -> Tele a
ExtendTel Dom Type
dom (Abs (Tele (Dom Type)) -> Tele (Dom Type))
-> (Tele (Dom Type) -> Abs (Tele (Dom Type)))
-> Tele (Dom Type)
-> Tele (Dom Type)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ArgName -> Tele (Dom Type) -> Abs (Tele (Dom Type))
forall a. ArgName -> a -> Abs a
Abs (Abs Teletype -> ArgName
forall a. Abs a -> ArgName
absName Abs Teletype
abs)) (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) (Abs Teletype -> Teletype
forall a. Abs a -> a
unAbs Abs Teletype
abs)
(v@(TelV !tel _), bndry) <- (Tele (Dom Type) -> Tele (Dom Type))
-> Int -> Teletype -> m (TelView, Boundary)
forall {f :: * -> *}.
PureTCM f =>
(Tele (Dom Type) -> Tele (Dom Type))
-> Int -> Teletype -> f (TelView, Boundary)
loop Tele (Dom Type) -> Tele (Dom Type)
forall a. a -> a
id Int
n Teletype
tty
pure (v, fullBoundary tel bndry)
{-# SPECIALIZE teleViewUpToPathBoundary :: Int -> Teletype -> TCM (TelView, Boundary) #-}
teleViewUpToPath :: PureTCM m => Int -> Teletype -> m TelView
teleViewUpToPath :: forall (m :: * -> *). PureTCM m => Int -> Teletype -> m TelView
teleViewUpToPath Int
n Teletype
tty = (TelView, Boundary) -> TelView
forall a b. (a, b) -> a
fst ((TelView, Boundary) -> TelView)
-> m (TelView, Boundary) -> m TelView
forall (m :: * -> *) a b. Monad m => (a -> b) -> m a -> m b
<$!> Int -> Teletype -> m (TelView, Boundary)
forall (m :: * -> *).
PureTCM m =>
Int -> Teletype -> m (TelView, Boundary)
teleViewUpToPathBoundary Int
n Teletype
tty
{-# INLINE teleViewUpToPath #-}