module Agda.TypeChecking.RecordPatterns
( translateRecordPatterns
, translateCompiledClauses
, translateSplitTree
, recordPatternToProjections
) where
import Control.Arrow ( first, second )
import Control.Monad ( forM, unless, when, zipWithM )
import Control.Monad.Fix ( mfix )
import Control.Monad.IO.Class ( MonadIO(..) )
import Control.Monad.Reader ( MonadReader(..), ReaderT(..), runReaderT )
import Control.Monad.State ( MonadState(..), StateT(..), runStateT )
import Control.Monad.Trans ( lift )
import qualified Data.List as List
import Data.Maybe
import qualified Data.Map as Map
import Agda.Syntax.Common
import Agda.Syntax.Internal as I
import Agda.Syntax.Internal.Pattern as I
import Agda.TypeChecking.CompiledClause
import Agda.TypeChecking.Coverage.SplitTree
import Agda.TypeChecking.Datatypes
import Agda.TypeChecking.Monad
import Agda.TypeChecking.Pretty hiding (pretty)
import Agda.TypeChecking.Records
import Agda.TypeChecking.Reduce
import Agda.TypeChecking.Substitute
import Agda.TypeChecking.Telescope
import Agda.Interaction.Options
import Agda.Utils.Either
import Agda.Utils.Functor
import Agda.Utils.Permutation hiding (dropFrom)
import Agda.Utils.Pretty (Pretty(..))
import qualified Agda.Utils.Pretty as P
import Agda.Utils.Size
import Agda.Utils.Update (MonadChange, tellDirty)
import Agda.Utils.Impossible
recordPatternToProjections :: DeBruijnPattern -> TCM [Term -> Term]
recordPatternToProjections :: DeBruijnPattern -> TCM [Term -> Term]
recordPatternToProjections DeBruijnPattern
p =
case DeBruijnPattern
p of
VarP{} -> [Term -> Term] -> TCM [Term -> Term]
forall (m :: * -> *) a. Monad m => a -> m a
return [ Term -> Term
forall a. a -> a
id ]
LitP{} -> TypeError -> TCM [Term -> Term]
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCM [Term -> Term])
-> TypeError -> TCM [Term -> Term]
forall a b. (a -> b) -> a -> b
$ DeBruijnPattern -> TypeError
ShouldBeRecordPattern DeBruijnPattern
p
DotP{} -> TypeError -> TCM [Term -> Term]
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCM [Term -> Term])
-> TypeError -> TCM [Term -> Term]
forall a b. (a -> b) -> a -> b
$ DeBruijnPattern -> TypeError
ShouldBeRecordPattern DeBruijnPattern
p
ConP ConHead
c ConPatternInfo
ci [NamedArg DeBruijnPattern]
ps -> do
Bool -> TCMT IO () -> TCMT IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (ConPatternInfo -> Bool
conPRecord ConPatternInfo
ci) (TCMT IO () -> TCMT IO ()) -> TCMT IO () -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$
TypeError -> TCMT IO ()
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCMT IO ()) -> TypeError -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ DeBruijnPattern -> TypeError
ShouldBeRecordPattern DeBruijnPattern
p
let t :: Type
t = Arg Type -> Type
forall e. Arg e -> e
unArg (Arg Type -> Type) -> Arg Type -> Type
forall a b. (a -> b) -> a -> b
$ Arg Type -> Maybe (Arg Type) -> Arg Type
forall a. a -> Maybe a -> a
fromMaybe Arg Type
forall a. HasCallStack => a
__IMPOSSIBLE__ (Maybe (Arg Type) -> Arg Type) -> Maybe (Arg Type) -> Arg Type
forall a b. (a -> b) -> a -> b
$ ConPatternInfo -> Maybe (Arg Type)
conPType ConPatternInfo
ci
VerboseKey -> VerboseLevel -> TCM Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
VerboseKey -> VerboseLevel -> TCM Doc -> m ()
reportSDoc VerboseKey
"tc.rec" VerboseLevel
45 (TCM Doc -> TCMT IO ()) -> TCM Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [TCM Doc] -> TCM Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCM Doc
"recordPatternToProjections: "
, VerboseLevel -> TCM Doc -> TCM Doc
forall (m :: * -> *). Functor m => VerboseLevel -> m Doc -> m Doc
nest VerboseLevel
2 (TCM Doc -> TCM Doc) -> TCM Doc -> TCM Doc
forall a b. (a -> b) -> a -> b
$ TCM Doc
"constructor pattern " TCM Doc -> TCM Doc -> TCM Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> DeBruijnPattern -> TCM Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM DeBruijnPattern
p TCM Doc -> TCM Doc -> TCM Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCM Doc
" has type " TCM Doc -> TCM Doc -> TCM Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Type -> TCM Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Type
t
]
VerboseKey -> VerboseLevel -> VerboseKey -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
VerboseKey -> VerboseLevel -> VerboseKey -> m ()
reportSLn VerboseKey
"tc.rec" VerboseLevel
70 (VerboseKey -> TCMT IO ()) -> VerboseKey -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ VerboseKey
" type raw: " VerboseKey -> VerboseKey -> VerboseKey
forall a. [a] -> [a] -> [a]
++ Type -> VerboseKey
forall a. Show a => a -> VerboseKey
show Type
t
[Dom QName]
fields <- Type -> TCM [Dom QName]
getRecordTypeFields Type
t
[[Term -> Term]] -> [Term -> Term]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[Term -> Term]] -> [Term -> Term])
-> TCMT IO [[Term -> Term]] -> TCM [Term -> Term]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((Term -> Term) -> DeBruijnPattern -> TCM [Term -> Term])
-> [Term -> Term] -> [DeBruijnPattern] -> TCMT IO [[Term -> Term]]
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> m c) -> [a] -> [b] -> m [c]
zipWithM (Term -> Term) -> DeBruijnPattern -> TCM [Term -> Term]
comb ((Dom QName -> Term -> Term) -> [Dom QName] -> [Term -> Term]
forall a b. (a -> b) -> [a] -> [b]
map Dom QName -> Term -> Term
forall t t. Apply t => Dom' t QName -> t -> t
proj [Dom QName]
fields) ((NamedArg DeBruijnPattern -> DeBruijnPattern)
-> [NamedArg DeBruijnPattern] -> [DeBruijnPattern]
forall a b. (a -> b) -> [a] -> [b]
map NamedArg DeBruijnPattern -> DeBruijnPattern
forall a. NamedArg a -> a
namedArg [NamedArg DeBruijnPattern]
ps)
ProjP{} -> TCM [Term -> Term]
forall a. HasCallStack => a
__IMPOSSIBLE__
IApplyP{} -> TypeError -> TCM [Term -> Term]
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCM [Term -> Term])
-> TypeError -> TCM [Term -> Term]
forall a b. (a -> b) -> a -> b
$ DeBruijnPattern -> TypeError
ShouldBeRecordPattern DeBruijnPattern
p
DefP{} -> TypeError -> TCM [Term -> Term]
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCM [Term -> Term])
-> TypeError -> TCM [Term -> Term]
forall a b. (a -> b) -> a -> b
$ DeBruijnPattern -> TypeError
ShouldBeRecordPattern DeBruijnPattern
p
where
proj :: Dom' t QName -> t -> t
proj Dom' t QName
p = (t -> Elims -> t
forall t. Apply t => t -> Elims -> t
`applyE` [ProjOrigin -> QName -> Elim' Term
forall a. ProjOrigin -> QName -> Elim' a
Proj ProjOrigin
ProjSystem (QName -> Elim' Term) -> QName -> Elim' Term
forall a b. (a -> b) -> a -> b
$ Dom' t QName -> QName
forall t e. Dom' t e -> e
unDom Dom' t QName
p])
comb :: (Term -> Term) -> DeBruijnPattern -> TCM [Term -> Term]
comb :: (Term -> Term) -> DeBruijnPattern -> TCM [Term -> Term]
comb Term -> Term
prj DeBruijnPattern
p = ((Term -> Term) -> Term -> Term)
-> [Term -> Term] -> [Term -> Term]
forall a b. (a -> b) -> [a] -> [b]
map (\ Term -> Term
f -> Term -> Term
f (Term -> Term) -> (Term -> Term) -> Term -> Term
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Term -> Term
prj) ([Term -> Term] -> [Term -> Term])
-> TCM [Term -> Term] -> TCM [Term -> Term]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> DeBruijnPattern -> TCM [Term -> Term]
recordPatternToProjections DeBruijnPattern
p
conjColumns :: [[Bool]] -> [Bool]
conjColumns :: [[Bool]] -> [Bool]
conjColumns = ([Bool] -> [Bool] -> [Bool]) -> [[Bool]] -> [Bool]
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldl1 ((Bool -> Bool -> Bool) -> [Bool] -> [Bool] -> [Bool]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith Bool -> Bool -> Bool
(&&))
getEtaAndArity :: SplitTag -> TCM (Bool, Nat)
getEtaAndArity :: SplitTag -> TCM (Bool, VerboseLevel)
getEtaAndArity (SplitCon QName
c) =
TCMT IO ConstructorInfo
-> (ConstructorInfo -> (Bool, VerboseLevel))
-> TCM (Bool, VerboseLevel)
forall (m :: * -> *) a b. Functor m => m a -> (a -> b) -> m b
for (QName -> TCMT IO ConstructorInfo
forall (m :: * -> *). HasConstInfo m => QName -> m ConstructorInfo
getConstructorInfo QName
c) ((ConstructorInfo -> (Bool, VerboseLevel))
-> TCM (Bool, VerboseLevel))
-> (ConstructorInfo -> (Bool, VerboseLevel))
-> TCM (Bool, VerboseLevel)
forall a b. (a -> b) -> a -> b
$ \case
DataCon VerboseLevel
n -> (Bool
False, VerboseLevel
n)
RecordCon PatternOrCopattern
_ HasEta
eta [Dom QName]
fs -> (HasEta
eta HasEta -> HasEta -> Bool
forall a. Eq a => a -> a -> Bool
== HasEta
forall a. HasEta' a
YesEta, [Dom QName] -> VerboseLevel
forall a. Sized a => a -> VerboseLevel
size [Dom QName]
fs)
getEtaAndArity (SplitLit Literal
l) = (Bool, VerboseLevel) -> TCM (Bool, VerboseLevel)
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool
False, VerboseLevel
0)
getEtaAndArity SplitTag
SplitCatchall = (Bool, VerboseLevel) -> TCM (Bool, VerboseLevel)
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool
False, VerboseLevel
1)
translateCompiledClauses
:: forall m. (HasConstInfo m, MonadChange m)
=> CompiledClauses -> m CompiledClauses
translateCompiledClauses :: CompiledClauses -> m CompiledClauses
translateCompiledClauses CompiledClauses
cc = m CompiledClauses -> m CompiledClauses
forall (m :: * -> *) a. MonadTCEnv m => m a -> m a
ignoreAbstractMode (m CompiledClauses -> m CompiledClauses)
-> m CompiledClauses -> m CompiledClauses
forall a b. (a -> b) -> a -> b
$ do
VerboseKey -> VerboseLevel -> TCM Doc -> m ()
forall (m :: * -> *).
MonadDebug m =>
VerboseKey -> VerboseLevel -> TCM Doc -> m ()
reportSDoc VerboseKey
"tc.cc.record" VerboseLevel
20 (TCM Doc -> m ()) -> TCM Doc -> m ()
forall a b. (a -> b) -> a -> b
$ [TCM Doc] -> TCM Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCM Doc
"translate record patterns in compiled clauses"
, VerboseLevel -> TCM Doc -> TCM Doc
forall (m :: * -> *). Functor m => VerboseLevel -> m Doc -> m Doc
nest VerboseLevel
2 (TCM Doc -> TCM Doc) -> TCM Doc -> TCM Doc
forall a b. (a -> b) -> a -> b
$ Doc -> TCM Doc
forall (m :: * -> *) a. Monad m => a -> m a
return (Doc -> TCM Doc) -> Doc -> TCM Doc
forall a b. (a -> b) -> a -> b
$ CompiledClauses -> Doc
forall a. Pretty a => a -> Doc
pretty CompiledClauses
cc
]
CompiledClauses
cc <- CompiledClauses -> m CompiledClauses
loop CompiledClauses
cc
VerboseKey -> VerboseLevel -> TCM Doc -> m ()
forall (m :: * -> *).
MonadDebug m =>
VerboseKey -> VerboseLevel -> TCM Doc -> m ()
reportSDoc VerboseKey
"tc.cc.record" VerboseLevel
20 (TCM Doc -> m ()) -> TCM Doc -> m ()
forall a b. (a -> b) -> a -> b
$ [TCM Doc] -> TCM Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCM Doc
"translated compiled clauses (no eta record patterns):"
, VerboseLevel -> TCM Doc -> TCM Doc
forall (m :: * -> *). Functor m => VerboseLevel -> m Doc -> m Doc
nest VerboseLevel
2 (TCM Doc -> TCM Doc) -> TCM Doc -> TCM Doc
forall a b. (a -> b) -> a -> b
$ Doc -> TCM Doc
forall (m :: * -> *) a. Monad m => a -> m a
return (Doc -> TCM Doc) -> Doc -> TCM Doc
forall a b. (a -> b) -> a -> b
$ CompiledClauses -> Doc
forall a. Pretty a => a -> Doc
pretty CompiledClauses
cc
]
CompiledClauses
cc <- CompiledClauses -> m CompiledClauses
forall (m :: * -> *).
(HasConstInfo m, MonadChange m) =>
CompiledClauses -> m CompiledClauses
recordExpressionsToCopatterns CompiledClauses
cc
VerboseKey -> VerboseLevel -> TCM Doc -> m ()
forall (m :: * -> *).
MonadDebug m =>
VerboseKey -> VerboseLevel -> TCM Doc -> m ()
reportSDoc VerboseKey
"tc.cc.record" VerboseLevel
20 (TCM Doc -> m ()) -> TCM Doc -> m ()
forall a b. (a -> b) -> a -> b
$ [TCM Doc] -> TCM Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCM Doc
"translated compiled clauses (record expressions to copatterns):"
, VerboseLevel -> TCM Doc -> TCM Doc
forall (m :: * -> *). Functor m => VerboseLevel -> m Doc -> m Doc
nest VerboseLevel
2 (TCM Doc -> TCM Doc) -> TCM Doc -> TCM Doc
forall a b. (a -> b) -> a -> b
$ Doc -> TCM Doc
forall (m :: * -> *) a. Monad m => a -> m a
return (Doc -> TCM Doc) -> Doc -> TCM Doc
forall a b. (a -> b) -> a -> b
$ CompiledClauses -> Doc
forall a. Pretty a => a -> Doc
pretty CompiledClauses
cc
]
CompiledClauses -> m CompiledClauses
forall (m :: * -> *) a. Monad m => a -> m a
return CompiledClauses
cc
where
loop :: CompiledClauses -> m (CompiledClauses)
loop :: CompiledClauses -> m CompiledClauses
loop CompiledClauses
cc = case CompiledClauses
cc of
Fail{} -> CompiledClauses -> m CompiledClauses
forall (m :: * -> *) a. Monad m => a -> m a
return CompiledClauses
cc
Done{} -> CompiledClauses -> m CompiledClauses
forall (m :: * -> *) a. Monad m => a -> m a
return CompiledClauses
cc
Case Arg VerboseLevel
i Case CompiledClauses
cs -> Arg VerboseLevel -> Case CompiledClauses -> m CompiledClauses
loops Arg VerboseLevel
i Case CompiledClauses
cs
loops :: Arg Int
-> Case CompiledClauses
-> m CompiledClauses
loops :: Arg VerboseLevel -> Case CompiledClauses -> m CompiledClauses
loops Arg VerboseLevel
i cs :: Case CompiledClauses
cs@Branches{ projPatterns :: forall c. Case c -> Bool
projPatterns = Bool
comatch
, conBranches :: forall c. Case c -> Map QName (WithArity c)
conBranches = Map QName (WithArity CompiledClauses)
conMap
, etaBranch :: forall c. Case c -> Maybe (ConHead, WithArity c)
etaBranch = Maybe (ConHead, WithArity CompiledClauses)
eta
, litBranches :: forall c. Case c -> Map Literal c
litBranches = Map Literal CompiledClauses
litMap
, fallThrough :: forall c. Case c -> Maybe Bool
fallThrough = Maybe Bool
fT
, catchAllBranch :: forall c. Case c -> Maybe c
catchAllBranch = Maybe CompiledClauses
catchAll
, lazyMatch :: forall c. Case c -> Bool
lazyMatch = Bool
lazy } = do
Maybe CompiledClauses
catchAll <- (CompiledClauses -> m CompiledClauses)
-> Maybe CompiledClauses -> m (Maybe CompiledClauses)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse CompiledClauses -> m CompiledClauses
loop Maybe CompiledClauses
catchAll
Map Literal CompiledClauses
litMap <- (CompiledClauses -> m CompiledClauses)
-> Map Literal CompiledClauses -> m (Map Literal CompiledClauses)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse CompiledClauses -> m CompiledClauses
loop Map Literal CompiledClauses
litMap
(Map QName (WithArity CompiledClauses)
conMap, Maybe (ConHead, WithArity CompiledClauses)
eta) <- do
let noEtaCase :: m (Map QName (WithArity CompiledClauses),
Maybe (ConHead, WithArity CompiledClauses))
noEtaCase = (, Maybe (ConHead, WithArity CompiledClauses)
forall a. Maybe a
Nothing) (Map QName (WithArity CompiledClauses)
-> (Map QName (WithArity CompiledClauses),
Maybe (ConHead, WithArity CompiledClauses)))
-> m (Map QName (WithArity CompiledClauses))
-> m (Map QName (WithArity CompiledClauses),
Maybe (ConHead, WithArity CompiledClauses))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((WithArity CompiledClauses -> m (WithArity CompiledClauses))
-> Map QName (WithArity CompiledClauses)
-> m (Map QName (WithArity CompiledClauses))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((WithArity CompiledClauses -> m (WithArity CompiledClauses))
-> Map QName (WithArity CompiledClauses)
-> m (Map QName (WithArity CompiledClauses)))
-> ((CompiledClauses -> m CompiledClauses)
-> WithArity CompiledClauses -> m (WithArity CompiledClauses))
-> (CompiledClauses -> m CompiledClauses)
-> Map QName (WithArity CompiledClauses)
-> m (Map QName (WithArity CompiledClauses))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (CompiledClauses -> m CompiledClauses)
-> WithArity CompiledClauses -> m (WithArity CompiledClauses)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse) CompiledClauses -> m CompiledClauses
loop Map QName (WithArity CompiledClauses)
conMap
yesEtaCase :: WithArity CompiledClauses
-> ConHead
-> m (Map QName (WithArity CompiledClauses),
Maybe (ConHead, WithArity CompiledClauses))
yesEtaCase WithArity CompiledClauses
b ConHead
ch = (Map QName (WithArity CompiledClauses)
forall k a. Map k a
Map.empty,) (Maybe (ConHead, WithArity CompiledClauses)
-> (Map QName (WithArity CompiledClauses),
Maybe (ConHead, WithArity CompiledClauses)))
-> (WithArity CompiledClauses
-> Maybe (ConHead, WithArity CompiledClauses))
-> WithArity CompiledClauses
-> (Map QName (WithArity CompiledClauses),
Maybe (ConHead, WithArity CompiledClauses))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ConHead, WithArity CompiledClauses)
-> Maybe (ConHead, WithArity CompiledClauses)
forall a. a -> Maybe a
Just ((ConHead, WithArity CompiledClauses)
-> Maybe (ConHead, WithArity CompiledClauses))
-> (WithArity CompiledClauses
-> (ConHead, WithArity CompiledClauses))
-> WithArity CompiledClauses
-> Maybe (ConHead, WithArity CompiledClauses)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ConHead
ch,) (WithArity CompiledClauses
-> (Map QName (WithArity CompiledClauses),
Maybe (ConHead, WithArity CompiledClauses)))
-> m (WithArity CompiledClauses)
-> m (Map QName (WithArity CompiledClauses),
Maybe (ConHead, WithArity CompiledClauses))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (CompiledClauses -> m CompiledClauses)
-> WithArity CompiledClauses -> m (WithArity CompiledClauses)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse CompiledClauses -> m CompiledClauses
loop WithArity CompiledClauses
b
case Map QName (WithArity CompiledClauses)
-> [(QName, WithArity CompiledClauses)]
forall k a. Map k a -> [(k, a)]
Map.toList Map QName (WithArity CompiledClauses)
conMap of
[(QName, WithArity CompiledClauses)]
_ | Just (ConHead
ch, WithArity CompiledClauses
b) <- Maybe (ConHead, WithArity CompiledClauses)
eta -> WithArity CompiledClauses
-> ConHead
-> m (Map QName (WithArity CompiledClauses),
Maybe (ConHead, WithArity CompiledClauses))
yesEtaCase WithArity CompiledClauses
b ConHead
ch
[(QName
c, WithArity CompiledClauses
b)] | Bool -> Bool
not Bool
comatch ->
QName -> m ConstructorInfo
forall (m :: * -> *). HasConstInfo m => QName -> m ConstructorInfo
getConstructorInfo QName
c m ConstructorInfo
-> (ConstructorInfo
-> m (Map QName (WithArity CompiledClauses),
Maybe (ConHead, WithArity CompiledClauses)))
-> m (Map QName (WithArity CompiledClauses),
Maybe (ConHead, WithArity CompiledClauses))
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \ case
RecordCon PatternOrCopattern
pm HasEta
YesEta [Dom QName]
fs -> WithArity CompiledClauses
-> ConHead
-> m (Map QName (WithArity CompiledClauses),
Maybe (ConHead, WithArity CompiledClauses))
yesEtaCase WithArity CompiledClauses
b (ConHead
-> m (Map QName (WithArity CompiledClauses),
Maybe (ConHead, WithArity CompiledClauses)))
-> ConHead
-> m (Map QName (WithArity CompiledClauses),
Maybe (ConHead, WithArity CompiledClauses))
forall a b. (a -> b) -> a -> b
$
QName -> DataOrRecord -> Induction -> [Arg QName] -> ConHead
ConHead QName
c (PatternOrCopattern -> DataOrRecord
IsRecord PatternOrCopattern
pm) Induction
Inductive ((Dom QName -> Arg QName) -> [Dom QName] -> [Arg QName]
forall a b. (a -> b) -> [a] -> [b]
map Dom QName -> Arg QName
forall t a. Dom' t a -> Arg a
argFromDom [Dom QName]
fs)
ConstructorInfo
_ -> m (Map QName (WithArity CompiledClauses),
Maybe (ConHead, WithArity CompiledClauses))
noEtaCase
[(QName, WithArity CompiledClauses)]
_ -> m (Map QName (WithArity CompiledClauses),
Maybe (ConHead, WithArity CompiledClauses))
noEtaCase
CompiledClauses -> m CompiledClauses
forall (m :: * -> *) a. Monad m => a -> m a
return (CompiledClauses -> m CompiledClauses)
-> CompiledClauses -> m CompiledClauses
forall a b. (a -> b) -> a -> b
$ Arg VerboseLevel -> Case CompiledClauses -> CompiledClauses
forall a.
Arg VerboseLevel -> Case (CompiledClauses' a) -> CompiledClauses' a
Case Arg VerboseLevel
i Case CompiledClauses
cs{ conBranches :: Map QName (WithArity CompiledClauses)
conBranches = Map QName (WithArity CompiledClauses)
conMap
, etaBranch :: Maybe (ConHead, WithArity CompiledClauses)
etaBranch = Maybe (ConHead, WithArity CompiledClauses)
eta
, litBranches :: Map Literal CompiledClauses
litBranches = Map Literal CompiledClauses
litMap
, fallThrough :: Maybe Bool
fallThrough = Maybe Bool
fT
, catchAllBranch :: Maybe CompiledClauses
catchAllBranch = Maybe CompiledClauses
catchAll
}
recordExpressionsToCopatterns
:: (HasConstInfo m, MonadChange m)
=> CompiledClauses
-> m CompiledClauses
recordExpressionsToCopatterns :: CompiledClauses -> m CompiledClauses
recordExpressionsToCopatterns = \case
Case Arg VerboseLevel
i Case CompiledClauses
bs -> Arg VerboseLevel -> Case CompiledClauses -> CompiledClauses
forall a.
Arg VerboseLevel -> Case (CompiledClauses' a) -> CompiledClauses' a
Case Arg VerboseLevel
i (Case CompiledClauses -> CompiledClauses)
-> m (Case CompiledClauses) -> m CompiledClauses
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (CompiledClauses -> m CompiledClauses)
-> Case CompiledClauses -> m (Case CompiledClauses)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse CompiledClauses -> m CompiledClauses
forall (m :: * -> *).
(HasConstInfo m, MonadChange m) =>
CompiledClauses -> m CompiledClauses
recordExpressionsToCopatterns Case CompiledClauses
bs
cc :: CompiledClauses
cc@Fail{} -> CompiledClauses -> m CompiledClauses
forall (m :: * -> *) a. Monad m => a -> m a
return CompiledClauses
cc
cc :: CompiledClauses
cc@(Done [Arg VerboseKey]
xs (Con ConHead
c ConOrigin
ConORec Elims
es)) -> do
let vs :: [Term]
vs = (Arg Term -> Term) -> [Arg Term] -> [Term]
forall a b. (a -> b) -> [a] -> [b]
map Arg Term -> Term
forall e. Arg e -> e
unArg ([Arg Term] -> [Term]) -> [Arg Term] -> [Term]
forall a b. (a -> b) -> a -> b
$ [Arg Term] -> Maybe [Arg Term] -> [Arg Term]
forall a. a -> Maybe a -> a
fromMaybe [Arg Term]
forall a. HasCallStack => a
__IMPOSSIBLE__ (Maybe [Arg Term] -> [Arg Term]) -> Maybe [Arg Term] -> [Arg Term]
forall a b. (a -> b) -> a -> b
$ Elims -> Maybe [Arg Term]
forall a. [Elim' a] -> Maybe [Arg a]
allApplyElims Elims
es
Constructor{ conArity :: Defn -> VerboseLevel
conArity = VerboseLevel
ar } <- Definition -> Defn
theDef (Definition -> Defn) -> m Definition -> m Defn
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> QName -> m Definition
forall (m :: * -> *). HasConstInfo m => QName -> m Definition
getConstInfo (ConHead -> QName
conName ConHead
c)
Bool
irrProj <- PragmaOptions -> Bool
optIrrelevantProjections (PragmaOptions -> Bool) -> m PragmaOptions -> m Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m PragmaOptions
forall (m :: * -> *). HasOptions m => m PragmaOptions
pragmaOptions
QName -> m ConstructorInfo
forall (m :: * -> *). HasConstInfo m => QName -> m ConstructorInfo
getConstructorInfo (ConHead -> QName
conName ConHead
c) m ConstructorInfo
-> (ConstructorInfo -> m CompiledClauses) -> m CompiledClauses
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \ case
RecordCon PatternOrCopattern
CopatternMatching HasEta
YesEta [Dom QName]
fs
| VerboseLevel
ar <- [Dom QName] -> VerboseLevel
forall (t :: * -> *) a. Foldable t => t a -> VerboseLevel
length [Dom QName]
fs, VerboseLevel
ar VerboseLevel -> VerboseLevel -> Bool
forall a. Ord a => a -> a -> Bool
> VerboseLevel
0,
[Term] -> VerboseLevel
forall (t :: * -> *) a. Foldable t => t a -> VerboseLevel
length [Term]
vs VerboseLevel -> VerboseLevel -> Bool
forall a. Eq a => a -> a -> Bool
== VerboseLevel
ar,
Bool
irrProj Bool -> Bool -> Bool
|| Bool -> Bool
not ((Dom QName -> Bool) -> [Dom QName] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any Dom QName -> Bool
forall a. LensRelevance a => a -> Bool
isIrrelevant [Dom QName]
fs) -> do
m ()
forall (m :: * -> *). MonadChange m => m ()
tellDirty
Arg VerboseLevel -> Case CompiledClauses -> CompiledClauses
forall a.
Arg VerboseLevel -> Case (CompiledClauses' a) -> CompiledClauses' a
Case (VerboseLevel -> Arg VerboseLevel
forall a. a -> Arg a
defaultArg (VerboseLevel -> Arg VerboseLevel)
-> VerboseLevel -> Arg VerboseLevel
forall a b. (a -> b) -> a -> b
$ [Arg VerboseKey] -> VerboseLevel
forall (t :: * -> *) a. Foldable t => t a -> VerboseLevel
length [Arg VerboseKey]
xs) (Case CompiledClauses -> CompiledClauses)
-> m (Case CompiledClauses) -> m CompiledClauses
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> do
(CompiledClauses -> m CompiledClauses)
-> Case CompiledClauses -> m (Case CompiledClauses)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse CompiledClauses -> m CompiledClauses
forall (m :: * -> *).
(HasConstInfo m, MonadChange m) =>
CompiledClauses -> m CompiledClauses
recordExpressionsToCopatterns (Case CompiledClauses -> m (Case CompiledClauses))
-> Case CompiledClauses -> m (Case CompiledClauses)
forall a b. (a -> b) -> a -> b
$ Branches :: forall c.
Bool
-> Map QName (WithArity c)
-> Maybe (ConHead, WithArity c)
-> Map Literal c
-> Maybe c
-> Maybe Bool
-> Bool
-> Case c
Branches
{ projPatterns :: Bool
projPatterns = Bool
True
, conBranches :: Map QName (WithArity CompiledClauses)
conBranches = (WithArity CompiledClauses
-> WithArity CompiledClauses -> WithArity CompiledClauses)
-> [(QName, WithArity CompiledClauses)]
-> Map QName (WithArity CompiledClauses)
forall k a. Ord k => (a -> a -> a) -> [(k, a)] -> Map k a
Map.fromListWith WithArity CompiledClauses
-> WithArity CompiledClauses -> WithArity CompiledClauses
forall a. HasCallStack => a
__IMPOSSIBLE__ ([(QName, WithArity CompiledClauses)]
-> Map QName (WithArity CompiledClauses))
-> [(QName, WithArity CompiledClauses)]
-> Map QName (WithArity CompiledClauses)
forall a b. (a -> b) -> a -> b
$
(Dom QName -> Term -> (QName, WithArity CompiledClauses))
-> [Dom QName] -> [Term] -> [(QName, WithArity CompiledClauses)]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (\ Dom QName
f Term
v -> (Dom QName -> QName
forall t e. Dom' t e -> e
unDom Dom QName
f, VerboseLevel -> CompiledClauses -> WithArity CompiledClauses
forall c. VerboseLevel -> c -> WithArity c
WithArity VerboseLevel
0 (CompiledClauses -> WithArity CompiledClauses)
-> CompiledClauses -> WithArity CompiledClauses
forall a b. (a -> b) -> a -> b
$ [Arg VerboseKey] -> Term -> CompiledClauses
forall a. [Arg VerboseKey] -> a -> CompiledClauses' a
Done [Arg VerboseKey]
xs Term
v)) [Dom QName]
fs [Term]
vs
, etaBranch :: Maybe (ConHead, WithArity CompiledClauses)
etaBranch = Maybe (ConHead, WithArity CompiledClauses)
forall a. Maybe a
Nothing
, litBranches :: Map Literal CompiledClauses
litBranches = Map Literal CompiledClauses
forall k a. Map k a
Map.empty
, catchAllBranch :: Maybe CompiledClauses
catchAllBranch = Maybe CompiledClauses
forall a. Maybe a
Nothing
, fallThrough :: Maybe Bool
fallThrough = Maybe Bool
forall a. Maybe a
Nothing
, lazyMatch :: Bool
lazyMatch = Bool
False
}
ConstructorInfo
_ -> CompiledClauses -> m CompiledClauses
forall (m :: * -> *) a. Monad m => a -> m a
return CompiledClauses
cc
cc :: CompiledClauses
cc@Done{} -> CompiledClauses -> m CompiledClauses
forall (m :: * -> *) a. Monad m => a -> m a
return CompiledClauses
cc
translateSplitTree :: SplitTree -> TCM SplitTree
translateSplitTree :: SplitTree -> TCM SplitTree
translateSplitTree = ([Bool], SplitTree) -> SplitTree
forall a b. (a, b) -> b
snd (([Bool], SplitTree) -> SplitTree)
-> (SplitTree -> TCMT IO ([Bool], SplitTree))
-> SplitTree
-> TCM SplitTree
forall (m :: * -> *) b c a.
Functor m =>
(b -> c) -> (a -> m b) -> a -> m c
<.> SplitTree -> TCMT IO ([Bool], SplitTree)
loop
where
loop :: SplitTree -> TCM ([Bool], SplitTree)
loop :: SplitTree -> TCMT IO ([Bool], SplitTree)
loop = \case
SplittingDone VerboseLevel
n ->
([Bool], SplitTree) -> TCMT IO ([Bool], SplitTree)
forall (m :: * -> *) a. Monad m => a -> m a
return (VerboseLevel -> Bool -> [Bool]
forall a. VerboseLevel -> a -> [a]
replicate VerboseLevel
n Bool
True, VerboseLevel -> SplitTree
forall a. VerboseLevel -> SplitTree' a
SplittingDone VerboseLevel
n)
SplitAt Arg VerboseLevel
i LazySplit
lz SplitTrees' SplitTag
ts -> do
(Bool
x, [Bool]
xs, SplitTrees' SplitTag
ts) <- VerboseLevel
-> SplitTrees' SplitTag -> TCM (Bool, [Bool], SplitTrees' SplitTag)
loops (Arg VerboseLevel -> VerboseLevel
forall e. Arg e -> e
unArg Arg VerboseLevel
i) SplitTrees' SplitTag
ts
let t' :: SplitTree
t' = if Bool
x then
case SplitTrees' SplitTag
ts of
[(SplitTag
c,SplitTree
t)] -> SplitTree
t
SplitTrees' SplitTag
_ -> SplitTree
forall a. HasCallStack => a
__IMPOSSIBLE__
else Arg VerboseLevel -> LazySplit -> SplitTrees' SplitTag -> SplitTree
forall a.
Arg VerboseLevel -> LazySplit -> SplitTrees' a -> SplitTree' a
SplitAt Arg VerboseLevel
i LazySplit
lz SplitTrees' SplitTag
ts
([Bool], SplitTree) -> TCMT IO ([Bool], SplitTree)
forall (m :: * -> *) a. Monad m => a -> m a
return ([Bool]
xs, SplitTree
t')
loops :: Int -> SplitTrees -> TCM (Bool, [Bool], SplitTrees)
loops :: VerboseLevel
-> SplitTrees' SplitTag -> TCM (Bool, [Bool], SplitTrees' SplitTag)
loops VerboseLevel
i SplitTrees' SplitTag
ts = do
([Bool]
rs, [[Bool]]
xss, SplitTrees' SplitTag
ts) <- [(Bool, [Bool], (SplitTag, SplitTree))]
-> ([Bool], [[Bool]], SplitTrees' SplitTag)
forall a b c. [(a, b, c)] -> ([a], [b], [c])
unzip3 ([(Bool, [Bool], (SplitTag, SplitTree))]
-> ([Bool], [[Bool]], SplitTrees' SplitTag))
-> TCMT IO [(Bool, [Bool], (SplitTag, SplitTree))]
-> TCMT IO ([Bool], [[Bool]], SplitTrees' SplitTag)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> do
SplitTrees' SplitTag
-> ((SplitTag, SplitTree)
-> TCMT IO (Bool, [Bool], (SplitTag, SplitTree)))
-> TCMT IO [(Bool, [Bool], (SplitTag, SplitTree))]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM SplitTrees' SplitTag
ts (((SplitTag, SplitTree)
-> TCMT IO (Bool, [Bool], (SplitTag, SplitTree)))
-> TCMT IO [(Bool, [Bool], (SplitTag, SplitTree))])
-> ((SplitTag, SplitTree)
-> TCMT IO (Bool, [Bool], (SplitTag, SplitTree)))
-> TCMT IO [(Bool, [Bool], (SplitTag, SplitTree))]
forall a b. (a -> b) -> a -> b
$ \ (SplitTag
c, SplitTree
t) -> do
([Bool]
xs, SplitTree
t) <- SplitTree -> TCMT IO ([Bool], SplitTree)
loop SplitTree
t
(Bool
isRC, VerboseLevel
n) <- SplitTag -> TCM (Bool, VerboseLevel)
getEtaAndArity SplitTag
c
let ([Bool]
xs0, [Bool]
rest) = VerboseLevel -> [Bool] -> ([Bool], [Bool])
forall a. VerboseLevel -> [a] -> ([a], [a])
splitAt VerboseLevel
i [Bool]
xs
([Bool]
xs1, [Bool]
xs2) = VerboseLevel -> [Bool] -> ([Bool], [Bool])
forall a. VerboseLevel -> [a] -> ([a], [a])
splitAt VerboseLevel
n [Bool]
rest
x :: Bool
x = Bool
isRC Bool -> Bool -> Bool
&& [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
and [Bool]
xs1
xs' :: [Bool]
xs' = [Bool]
xs0 [Bool] -> [Bool] -> [Bool]
forall a. [a] -> [a] -> [a]
++ Bool
x Bool -> [Bool] -> [Bool]
forall a. a -> [a] -> [a]
: [Bool]
xs2
t' :: SplitTree
t' = if Bool
x then VerboseLevel -> VerboseLevel -> SplitTree -> SplitTree
forall a. DropFrom a => VerboseLevel -> VerboseLevel -> a -> a
dropFrom VerboseLevel
i (VerboseLevel
n VerboseLevel -> VerboseLevel -> VerboseLevel
forall a. Num a => a -> a -> a
- VerboseLevel
1) SplitTree
t else SplitTree
t
(Bool, [Bool], (SplitTag, SplitTree))
-> TCMT IO (Bool, [Bool], (SplitTag, SplitTree))
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool
x, [Bool]
xs', (SplitTag
c, SplitTree
t'))
let x :: Bool
x = [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
and [Bool]
rs
if Bool
x then Bool -> TCMT IO () -> TCMT IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless ([Bool]
rs [Bool] -> [Bool] -> Bool
forall a. Eq a => a -> a -> Bool
== [Bool
True]) TCMT IO ()
forall a. HasCallStack => a
__IMPOSSIBLE__
else Bool -> TCMT IO () -> TCMT IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when ([Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
or [Bool]
rs) TCMT IO ()
forall a. HasCallStack => a
__IMPOSSIBLE__
(Bool, [Bool], SplitTrees' SplitTag)
-> TCM (Bool, [Bool], SplitTrees' SplitTag)
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool
x, [[Bool]] -> [Bool]
conjColumns [[Bool]]
xss, SplitTrees' SplitTag
ts)
class DropFrom a where
dropFrom :: Int -> Int -> a -> a
instance DropFrom (SplitTree' c) where
dropFrom :: VerboseLevel -> VerboseLevel -> SplitTree' c -> SplitTree' c
dropFrom VerboseLevel
i VerboseLevel
n = \case
SplittingDone VerboseLevel
m -> VerboseLevel -> SplitTree' c
forall a. VerboseLevel -> SplitTree' a
SplittingDone (VerboseLevel
m VerboseLevel -> VerboseLevel -> VerboseLevel
forall a. Num a => a -> a -> a
- VerboseLevel
n)
SplitAt x :: Arg VerboseLevel
x@(Arg ArgInfo
ai VerboseLevel
j) LazySplit
lz SplitTrees' c
ts
| VerboseLevel
j VerboseLevel -> VerboseLevel -> Bool
forall a. Ord a => a -> a -> Bool
>= VerboseLevel
i VerboseLevel -> VerboseLevel -> VerboseLevel
forall a. Num a => a -> a -> a
+ VerboseLevel
n -> Arg VerboseLevel -> LazySplit -> SplitTrees' c -> SplitTree' c
forall a.
Arg VerboseLevel -> LazySplit -> SplitTrees' a -> SplitTree' a
SplitAt (ArgInfo -> VerboseLevel -> Arg VerboseLevel
forall e. ArgInfo -> e -> Arg e
Arg ArgInfo
ai (VerboseLevel -> Arg VerboseLevel)
-> VerboseLevel -> Arg VerboseLevel
forall a b. (a -> b) -> a -> b
$ VerboseLevel
j VerboseLevel -> VerboseLevel -> VerboseLevel
forall a. Num a => a -> a -> a
- VerboseLevel
n) LazySplit
lz (SplitTrees' c -> SplitTree' c) -> SplitTrees' c -> SplitTree' c
forall a b. (a -> b) -> a -> b
$ VerboseLevel -> VerboseLevel -> SplitTrees' c -> SplitTrees' c
forall a. DropFrom a => VerboseLevel -> VerboseLevel -> a -> a
dropFrom VerboseLevel
i VerboseLevel
n SplitTrees' c
ts
| VerboseLevel
j VerboseLevel -> VerboseLevel -> Bool
forall a. Ord a => a -> a -> Bool
< VerboseLevel
i -> Arg VerboseLevel -> LazySplit -> SplitTrees' c -> SplitTree' c
forall a.
Arg VerboseLevel -> LazySplit -> SplitTrees' a -> SplitTree' a
SplitAt Arg VerboseLevel
x LazySplit
lz (SplitTrees' c -> SplitTree' c) -> SplitTrees' c -> SplitTree' c
forall a b. (a -> b) -> a -> b
$ VerboseLevel -> VerboseLevel -> SplitTrees' c -> SplitTrees' c
forall a. DropFrom a => VerboseLevel -> VerboseLevel -> a -> a
dropFrom VerboseLevel
i VerboseLevel
n SplitTrees' c
ts
| Bool
otherwise -> SplitTree' c
forall a. HasCallStack => a
__IMPOSSIBLE__
instance DropFrom (c, SplitTree' c) where
dropFrom :: VerboseLevel
-> VerboseLevel -> (c, SplitTree' c) -> (c, SplitTree' c)
dropFrom VerboseLevel
i VerboseLevel
n (c
c, SplitTree' c
t) = (c
c, VerboseLevel -> VerboseLevel -> SplitTree' c -> SplitTree' c
forall a. DropFrom a => VerboseLevel -> VerboseLevel -> a -> a
dropFrom VerboseLevel
i VerboseLevel
n SplitTree' c
t)
instance DropFrom a => DropFrom [a] where
dropFrom :: VerboseLevel -> VerboseLevel -> [a] -> [a]
dropFrom VerboseLevel
i VerboseLevel
n [a]
ts = (a -> a) -> [a] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map (VerboseLevel -> VerboseLevel -> a -> a
forall a. DropFrom a => VerboseLevel -> VerboseLevel -> a -> a
dropFrom VerboseLevel
i VerboseLevel
n) [a]
ts
translateRecordPatterns :: Clause -> TCM Clause
translateRecordPatterns :: Clause -> TCM Clause
translateRecordPatterns Clause
clause = do
([NamedArg Pattern]
ps, [Term]
s, Changes
cs) <- RecPatM ([NamedArg Pattern], [Term], Changes)
-> TCM ([NamedArg Pattern], [Term], Changes)
forall a. RecPatM a -> TCM a
runRecPatM (RecPatM ([NamedArg Pattern], [Term], Changes)
-> TCM ([NamedArg Pattern], [Term], Changes))
-> RecPatM ([NamedArg Pattern], [Term], Changes)
-> TCM ([NamedArg Pattern], [Term], Changes)
forall a b. (a -> b) -> a -> b
$ [NamedArg Pattern] -> RecPatM ([NamedArg Pattern], [Term], Changes)
translatePatterns ([NamedArg Pattern]
-> RecPatM ([NamedArg Pattern], [Term], Changes))
-> [NamedArg Pattern]
-> RecPatM ([NamedArg Pattern], [Term], Changes)
forall a b. (a -> b) -> a -> b
$ [NamedArg DeBruijnPattern] -> [NamedArg Pattern]
forall a b. LabelPatVars a b => b -> a
unnumberPatVars ([NamedArg DeBruijnPattern] -> [NamedArg Pattern])
-> [NamedArg DeBruijnPattern] -> [NamedArg Pattern]
forall a b. (a -> b) -> a -> b
$ Clause -> [NamedArg DeBruijnPattern]
namedClausePats Clause
clause
let
noNewPatternVars :: VerboseLevel
noNewPatternVars = Changes -> VerboseLevel
forall a. Sized a => a -> VerboseLevel
size Changes
cs
s' :: [Term]
s' = [Term] -> [Term]
forall a. [a] -> [a]
reverse [Term]
s
mkSub :: [Term] -> Substitution' Term
mkSub [Term]
s = [Term]
s [Term] -> Substitution' Term -> Substitution' Term
forall a. DeBruijn a => [a] -> Substitution' a -> Substitution' a
++# VerboseLevel -> Substitution' Term
forall a. VerboseLevel -> Substitution' a
raiseS VerboseLevel
noNewPatternVars
rhsSubst :: Substitution' Term
rhsSubst = [Term] -> Substitution' Term
mkSub [Term]
s'
perm :: Permutation
perm = Permutation -> Maybe Permutation -> Permutation
forall a. a -> Maybe a -> a
fromMaybe Permutation
forall a. HasCallStack => a
__IMPOSSIBLE__ (Maybe Permutation -> Permutation)
-> Maybe Permutation -> Permutation
forall a b. (a -> b) -> a -> b
$ Clause -> Maybe Permutation
clausePerm Clause
clause
rhsSubst' :: Substitution' Term
rhsSubst' = [Term] -> Substitution' Term
mkSub ([Term] -> Substitution' Term) -> [Term] -> Substitution' Term
forall a b. (a -> b) -> a -> b
$ Permutation -> [Term] -> [Term]
forall a. Permutation -> [a] -> [a]
permute (Permutation -> Permutation
reverseP Permutation
perm) [Term]
s'
flattenedOldTel :: [(VerboseKey, Dom Type)]
flattenedOldTel =
Permutation -> [(VerboseKey, Dom Type)] -> [(VerboseKey, Dom Type)]
forall a. Permutation -> [a] -> [a]
permute (VerboseLevel -> Permutation -> Permutation
invertP VerboseLevel
forall a. HasCallStack => a
__IMPOSSIBLE__ (Permutation -> Permutation) -> Permutation -> Permutation
forall a b. (a -> b) -> a -> b
$ Permutation -> Permutation
compactP Permutation
perm) ([(VerboseKey, Dom Type)] -> [(VerboseKey, Dom Type)])
-> [(VerboseKey, Dom Type)] -> [(VerboseKey, Dom Type)]
forall a b. (a -> b) -> a -> b
$
[VerboseKey] -> [Dom Type] -> [(VerboseKey, Dom Type)]
forall a b. [a] -> [b] -> [(a, b)]
zip (Telescope -> [VerboseKey]
teleNames (Telescope -> [VerboseKey]) -> Telescope -> [VerboseKey]
forall a b. (a -> b) -> a -> b
$ Clause -> Telescope
clauseTel Clause
clause) ([Dom Type] -> [(VerboseKey, Dom Type)])
-> [Dom Type] -> [(VerboseKey, Dom Type)]
forall a b. (a -> b) -> a -> b
$
Telescope -> [Dom Type]
forall a. TermSubst a => Tele (Dom a) -> [Dom a]
flattenTel (Telescope -> [Dom Type]) -> Telescope -> [Dom Type]
forall a b. (a -> b) -> a -> b
$
Clause -> Telescope
clauseTel Clause
clause
substTel :: Substitution' (SubstArg (Dom Type))
-> [Maybe (d, Dom Type)] -> [Maybe (d, Dom Type)]
substTel = (Maybe (d, Dom Type) -> Maybe (d, Dom Type))
-> [Maybe (d, Dom Type)] -> [Maybe (d, Dom Type)]
forall a b. (a -> b) -> [a] -> [b]
map ((Maybe (d, Dom Type) -> Maybe (d, Dom Type))
-> [Maybe (d, Dom Type)] -> [Maybe (d, Dom Type)])
-> (Substitution' (SubstArg (Dom Type))
-> Maybe (d, Dom Type) -> Maybe (d, Dom Type))
-> Substitution' (SubstArg (Dom Type))
-> [Maybe (d, Dom Type)]
-> [Maybe (d, Dom Type)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((d, Dom Type) -> (d, Dom Type))
-> Maybe (d, Dom Type) -> Maybe (d, Dom Type)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (((d, Dom Type) -> (d, Dom Type))
-> Maybe (d, Dom Type) -> Maybe (d, Dom Type))
-> (Substitution' (SubstArg (Dom Type))
-> (d, Dom Type) -> (d, Dom Type))
-> Substitution' (SubstArg (Dom Type))
-> Maybe (d, Dom Type)
-> Maybe (d, Dom Type)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Dom Type -> Dom Type) -> (d, Dom Type) -> (d, Dom Type)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second ((Dom Type -> Dom Type) -> (d, Dom Type) -> (d, Dom Type))
-> (Substitution' (SubstArg (Dom Type)) -> Dom Type -> Dom Type)
-> Substitution' (SubstArg (Dom Type))
-> (d, Dom Type)
-> (d, Dom Type)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Substitution' (SubstArg (Dom Type)) -> Dom Type -> Dom Type
forall a. Subst a => Substitution' (SubstArg a) -> a -> a
applySubst
newTel' :: [Maybe (VerboseKey, Dom Type)]
newTel' =
Substitution' (SubstArg (Dom Type))
-> [Maybe (VerboseKey, Dom Type)] -> [Maybe (VerboseKey, Dom Type)]
forall d.
Substitution' (SubstArg (Dom Type))
-> [Maybe (d, Dom Type)] -> [Maybe (d, Dom Type)]
substTel Substitution' Term
Substitution' (SubstArg (Dom Type))
rhsSubst' ([Maybe (VerboseKey, Dom Type)] -> [Maybe (VerboseKey, Dom Type)])
-> [Maybe (VerboseKey, Dom Type)] -> [Maybe (VerboseKey, Dom Type)]
forall a b. (a -> b) -> a -> b
$
Changes
-> [(VerboseKey, Dom Type)] -> [Maybe (VerboseKey, Dom Type)]
translateTel Changes
cs ([(VerboseKey, Dom Type)] -> [Maybe (VerboseKey, Dom Type)])
-> [(VerboseKey, Dom Type)] -> [Maybe (VerboseKey, Dom Type)]
forall a b. (a -> b) -> a -> b
$
[(VerboseKey, Dom Type)]
flattenedOldTel
newPerm :: Permutation
newPerm = Permutation -> Permutation
adjustForDotPatterns (Permutation -> Permutation) -> Permutation -> Permutation
forall a b. (a -> b) -> a -> b
$
[Dom Type] -> Permutation
reorderTel_ ([Dom Type] -> Permutation) -> [Dom Type] -> Permutation
forall a b. (a -> b) -> a -> b
$ (Maybe (VerboseKey, Dom Type) -> Dom Type)
-> [Maybe (VerboseKey, Dom Type)] -> [Dom Type]
forall a b. (a -> b) -> [a] -> [b]
map (Dom Type
-> ((VerboseKey, Dom Type) -> Dom Type)
-> Maybe (VerboseKey, Dom Type)
-> Dom Type
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Dom Type
HasCallStack => Dom Type
__DUMMY_DOM__ (VerboseKey, Dom Type) -> Dom Type
forall a b. (a, b) -> b
snd) [Maybe (VerboseKey, Dom Type)]
newTel'
where
isDotP :: VerboseLevel -> Bool
isDotP VerboseLevel
n = case Changes -> VerboseLevel -> Change
forall i a. Integral i => [a] -> i -> a
List.genericIndex Changes
cs VerboseLevel
n of
Left DotP{} -> Bool
True
Change
_ -> Bool
False
adjustForDotPatterns :: Permutation -> Permutation
adjustForDotPatterns (Perm VerboseLevel
n [VerboseLevel]
is) =
VerboseLevel -> [VerboseLevel] -> Permutation
Perm VerboseLevel
n ((VerboseLevel -> Bool) -> [VerboseLevel] -> [VerboseLevel]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (VerboseLevel -> Bool) -> VerboseLevel -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VerboseLevel -> Bool
isDotP) [VerboseLevel]
is)
lhsSubst' :: Substitution' Term
lhsSubst' = Impossible -> Permutation -> Substitution' Term
forall a.
DeBruijn a =>
Impossible -> Permutation -> Substitution' a
renaming Impossible
HasCallStack => Impossible
impossible (Permutation -> Permutation
reverseP Permutation
newPerm)
lhsSubst :: Substitution' Term
lhsSubst = Substitution' (SubstArg (Substitution' Term))
-> Substitution' Term -> Substitution' Term
forall a. Subst a => Substitution' (SubstArg a) -> a -> a
applySubst Substitution' Term
Substitution' (SubstArg (Substitution' Term))
lhsSubst' Substitution' Term
rhsSubst'
newTel :: Telescope
newTel =
([VerboseKey] -> [Dom Type] -> Telescope)
-> ([VerboseKey], [Dom Type]) -> Telescope
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry [VerboseKey] -> [Dom Type] -> Telescope
unflattenTel (([VerboseKey], [Dom Type]) -> Telescope)
-> ([(VerboseKey, Dom Type)] -> ([VerboseKey], [Dom Type]))
-> [(VerboseKey, Dom Type)]
-> Telescope
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(VerboseKey, Dom Type)] -> ([VerboseKey], [Dom Type])
forall a b. [(a, b)] -> ([a], [b])
unzip ([(VerboseKey, Dom Type)] -> Telescope)
-> [(VerboseKey, Dom Type)] -> Telescope
forall a b. (a -> b) -> a -> b
$
(Maybe (VerboseKey, Dom Type) -> (VerboseKey, Dom Type))
-> [Maybe (VerboseKey, Dom Type)] -> [(VerboseKey, Dom Type)]
forall a b. (a -> b) -> [a] -> [b]
map ((VerboseKey, Dom Type)
-> Maybe (VerboseKey, Dom Type) -> (VerboseKey, Dom Type)
forall a. a -> Maybe a -> a
fromMaybe (VerboseKey, Dom Type)
forall a. HasCallStack => a
__IMPOSSIBLE__) ([Maybe (VerboseKey, Dom Type)] -> [(VerboseKey, Dom Type)])
-> [Maybe (VerboseKey, Dom Type)] -> [(VerboseKey, Dom Type)]
forall a b. (a -> b) -> a -> b
$
Permutation
-> [Maybe (VerboseKey, Dom Type)] -> [Maybe (VerboseKey, Dom Type)]
forall a. Permutation -> [a] -> [a]
permute Permutation
newPerm ([Maybe (VerboseKey, Dom Type)] -> [Maybe (VerboseKey, Dom Type)])
-> [Maybe (VerboseKey, Dom Type)] -> [Maybe (VerboseKey, Dom Type)]
forall a b. (a -> b) -> a -> b
$
Substitution' (SubstArg (Dom Type))
-> [Maybe (VerboseKey, Dom Type)] -> [Maybe (VerboseKey, Dom Type)]
forall d.
Substitution' (SubstArg (Dom Type))
-> [Maybe (d, Dom Type)] -> [Maybe (d, Dom Type)]
substTel Substitution' Term
Substitution' (SubstArg (Dom Type))
lhsSubst' ([Maybe (VerboseKey, Dom Type)] -> [Maybe (VerboseKey, Dom Type)])
-> [Maybe (VerboseKey, Dom Type)] -> [Maybe (VerboseKey, Dom Type)]
forall a b. (a -> b) -> a -> b
$
[Maybe (VerboseKey, Dom Type)]
newTel'
c :: Clause
c = Clause
clause
{ clauseTel :: Telescope
clauseTel = Telescope
newTel
, namedClausePats :: [NamedArg DeBruijnPattern]
namedClausePats = VerboseLevel
-> Permutation -> [NamedArg Pattern] -> [NamedArg DeBruijnPattern]
forall a b.
(LabelPatVars a b, PatVarLabel b ~ VerboseLevel) =>
VerboseLevel -> Permutation -> a -> b
numberPatVars VerboseLevel
forall a. HasCallStack => a
__IMPOSSIBLE__ Permutation
newPerm ([NamedArg Pattern] -> [NamedArg DeBruijnPattern])
-> [NamedArg Pattern] -> [NamedArg DeBruijnPattern]
forall a b. (a -> b) -> a -> b
$ Substitution' (SubstArg [NamedArg Pattern])
-> [NamedArg Pattern] -> [NamedArg Pattern]
forall a. Subst a => Substitution' (SubstArg a) -> a -> a
applySubst Substitution' Term
Substitution' (SubstArg [NamedArg Pattern])
lhsSubst [NamedArg Pattern]
ps
, clauseBody :: Maybe Term
clauseBody = Substitution' (SubstArg (Maybe Term)) -> Maybe Term -> Maybe Term
forall a. Subst a => Substitution' (SubstArg a) -> a -> a
applySubst Substitution' Term
Substitution' (SubstArg (Maybe Term))
lhsSubst (Maybe Term -> Maybe Term) -> Maybe Term -> Maybe Term
forall a b. (a -> b) -> a -> b
$ Clause -> Maybe Term
clauseBody Clause
clause
}
VerboseKey -> VerboseLevel -> TCM Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
VerboseKey -> VerboseLevel -> TCM Doc -> m ()
reportSDoc VerboseKey
"tc.lhs.recpat" VerboseLevel
20 (TCM Doc -> TCMT IO ()) -> TCM Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [TCM Doc] -> TCM Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCM Doc
"Original clause:"
, VerboseLevel -> TCM Doc -> TCM Doc
forall (m :: * -> *). Functor m => VerboseLevel -> m Doc -> m Doc
nest VerboseLevel
2 (TCM Doc -> TCM Doc) -> TCM Doc -> TCM Doc
forall a b. (a -> b) -> a -> b
$ TCM Doc -> TCM Doc
forall (tcm :: * -> *) a.
(MonadTCEnv tcm, ReadTCState tcm) =>
tcm a -> tcm a
inTopContext (TCM Doc -> TCM Doc) -> TCM Doc -> TCM Doc
forall a b. (a -> b) -> a -> b
$ [TCM Doc] -> TCM Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCM Doc
"delta =" TCM Doc -> TCM Doc -> TCM Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Telescope -> TCM Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM (Clause -> Telescope
clauseTel Clause
clause)
, TCM Doc
"pats =" TCM Doc -> TCM Doc -> TCM Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> VerboseKey -> TCM Doc
forall (m :: * -> *). Applicative m => VerboseKey -> m Doc
text ([Arg DeBruijnPattern] -> VerboseKey
forall a. Show a => a -> VerboseKey
show ([Arg DeBruijnPattern] -> VerboseKey)
-> [Arg DeBruijnPattern] -> VerboseKey
forall a b. (a -> b) -> a -> b
$ Clause -> [Arg DeBruijnPattern]
clausePats Clause
clause)
]
, TCM Doc
"Intermediate results:"
, VerboseLevel -> TCM Doc -> TCM Doc
forall (m :: * -> *). Functor m => VerboseLevel -> m Doc -> m Doc
nest VerboseLevel
2 (TCM Doc -> TCM Doc) -> TCM Doc -> TCM Doc
forall a b. (a -> b) -> a -> b
$ [TCM Doc] -> TCM Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCM Doc
"ps =" TCM Doc -> TCM Doc -> TCM Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> VerboseKey -> TCM Doc
forall (m :: * -> *). Applicative m => VerboseKey -> m Doc
text ([NamedArg Pattern] -> VerboseKey
forall a. Show a => a -> VerboseKey
show [NamedArg Pattern]
ps)
, TCM Doc
"s =" TCM Doc -> TCM Doc -> TCM Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> [Term] -> TCM Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM [Term]
s
, TCM Doc
"cs =" TCM Doc -> TCM Doc -> TCM Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Changes -> TCM Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Changes
cs
, TCM Doc
"flattenedOldTel =" TCM Doc -> TCM Doc -> TCM Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> (VerboseKey -> TCM Doc
forall (m :: * -> *). Applicative m => VerboseKey -> m Doc
text (VerboseKey -> TCM Doc)
-> ([(VerboseKey, Dom Type)] -> VerboseKey)
-> [(VerboseKey, Dom Type)]
-> TCM Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(VerboseKey, Dom Type)] -> VerboseKey
forall a. Show a => a -> VerboseKey
show) [(VerboseKey, Dom Type)]
flattenedOldTel
, TCM Doc
"newTel' =" TCM Doc -> TCM Doc -> TCM Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> (VerboseKey -> TCM Doc
forall (m :: * -> *). Applicative m => VerboseKey -> m Doc
text (VerboseKey -> TCM Doc)
-> ([Maybe (VerboseKey, Dom Type)] -> VerboseKey)
-> [Maybe (VerboseKey, Dom Type)]
-> TCM Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Maybe (VerboseKey, Dom Type)] -> VerboseKey
forall a. Show a => a -> VerboseKey
show) [Maybe (VerboseKey, Dom Type)]
newTel'
, TCM Doc
"newPerm =" TCM Doc -> TCM Doc -> TCM Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Permutation -> TCM Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Permutation
newPerm
]
]
VerboseKey -> VerboseLevel -> TCM Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
VerboseKey -> VerboseLevel -> TCM Doc -> m ()
reportSDoc VerboseKey
"tc.lhs.recpat" VerboseLevel
20 (TCM Doc -> TCMT IO ()) -> TCM Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [TCM Doc] -> TCM Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCM Doc
"lhsSubst' =" TCM Doc -> TCM Doc -> TCM Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> (VerboseKey -> TCM Doc
forall (m :: * -> *). Applicative m => VerboseKey -> m Doc
text (VerboseKey -> TCM Doc)
-> (Substitution' Term -> VerboseKey)
-> Substitution' Term
-> TCM Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Substitution' Term -> VerboseKey
forall a. Show a => a -> VerboseKey
show) Substitution' Term
lhsSubst'
, TCM Doc
"lhsSubst =" TCM Doc -> TCM Doc -> TCM Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> (VerboseKey -> TCM Doc
forall (m :: * -> *). Applicative m => VerboseKey -> m Doc
text (VerboseKey -> TCM Doc)
-> (Substitution' Term -> VerboseKey)
-> Substitution' Term
-> TCM Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Substitution' Term -> VerboseKey
forall a. Show a => a -> VerboseKey
show) Substitution' Term
lhsSubst
, TCM Doc
"newTel =" TCM Doc -> TCM Doc -> TCM Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Telescope -> TCM Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Telescope
newTel
]
VerboseKey -> VerboseLevel -> TCM Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
VerboseKey -> VerboseLevel -> TCM Doc -> m ()
reportSDoc VerboseKey
"tc.lhs.recpat" VerboseLevel
10 (TCM Doc -> TCMT IO ()) -> TCM Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$
Impossible -> VerboseLevel -> TCM Doc -> TCM Doc
forall (m :: * -> *) a.
MonadAddContext m =>
Impossible -> VerboseLevel -> m a -> m a
escapeContext Impossible
HasCallStack => Impossible
impossible (Telescope -> VerboseLevel
forall a. Sized a => a -> VerboseLevel
size (Telescope -> VerboseLevel) -> Telescope -> VerboseLevel
forall a b. (a -> b) -> a -> b
$ Clause -> Telescope
clauseTel Clause
clause) (TCM Doc -> TCM Doc) -> TCM Doc -> TCM Doc
forall a b. (a -> b) -> a -> b
$ [TCM Doc] -> TCM Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCM Doc
"Translated clause:"
, VerboseLevel -> TCM Doc -> TCM Doc
forall (m :: * -> *). Functor m => VerboseLevel -> m Doc -> m Doc
nest VerboseLevel
2 (TCM Doc -> TCM Doc) -> TCM Doc -> TCM Doc
forall a b. (a -> b) -> a -> b
$ [TCM Doc] -> TCM Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCM Doc
"delta =" TCM Doc -> TCM Doc -> TCM Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Telescope -> TCM Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM (Clause -> Telescope
clauseTel Clause
c)
, TCM Doc
"ps =" TCM Doc -> TCM Doc -> TCM Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> VerboseKey -> TCM Doc
forall (m :: * -> *). Applicative m => VerboseKey -> m Doc
text ([Arg DeBruijnPattern] -> VerboseKey
forall a. Show a => a -> VerboseKey
show ([Arg DeBruijnPattern] -> VerboseKey)
-> [Arg DeBruijnPattern] -> VerboseKey
forall a b. (a -> b) -> a -> b
$ Clause -> [Arg DeBruijnPattern]
clausePats Clause
c)
, TCM Doc
"body =" TCM Doc -> TCM Doc -> TCM Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> VerboseKey -> TCM Doc
forall (m :: * -> *). Applicative m => VerboseKey -> m Doc
text (Maybe Term -> VerboseKey
forall a. Show a => a -> VerboseKey
show (Maybe Term -> VerboseKey) -> Maybe Term -> VerboseKey
forall a b. (a -> b) -> a -> b
$ Clause -> Maybe Term
clauseBody Clause
c)
, TCM Doc
"body =" TCM Doc -> TCM Doc -> TCM Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Telescope -> TCM Doc -> TCM Doc
forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
addContext (Clause -> Telescope
clauseTel Clause
c) (TCM Doc -> (Term -> TCM Doc) -> Maybe Term -> TCM Doc
forall b a. b -> (a -> b) -> Maybe a -> b
maybe TCM Doc
"_|_" Term -> TCM Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM (Clause -> Maybe Term
clauseBody Clause
c))
]
]
Clause -> TCM Clause
forall (m :: * -> *) a. Monad m => a -> m a
return Clause
c
newtype RecPatM a = RecPatM (TCMT (ReaderT Nat (StateT Nat IO)) a)
deriving (a -> RecPatM b -> RecPatM a
(a -> b) -> RecPatM a -> RecPatM b
(forall a b. (a -> b) -> RecPatM a -> RecPatM b)
-> (forall a b. a -> RecPatM b -> RecPatM a) -> Functor RecPatM
forall a b. a -> RecPatM b -> RecPatM a
forall a b. (a -> b) -> RecPatM a -> RecPatM b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> RecPatM b -> RecPatM a
$c<$ :: forall a b. a -> RecPatM b -> RecPatM a
fmap :: (a -> b) -> RecPatM a -> RecPatM b
$cfmap :: forall a b. (a -> b) -> RecPatM a -> RecPatM b
Functor, Functor RecPatM
a -> RecPatM a
Functor RecPatM
-> (forall a. a -> RecPatM a)
-> (forall a b. RecPatM (a -> b) -> RecPatM a -> RecPatM b)
-> (forall a b c.
(a -> b -> c) -> RecPatM a -> RecPatM b -> RecPatM c)
-> (forall a b. RecPatM a -> RecPatM b -> RecPatM b)
-> (forall a b. RecPatM a -> RecPatM b -> RecPatM a)
-> Applicative RecPatM
RecPatM a -> RecPatM b -> RecPatM b
RecPatM a -> RecPatM b -> RecPatM a
RecPatM (a -> b) -> RecPatM a -> RecPatM b
(a -> b -> c) -> RecPatM a -> RecPatM b -> RecPatM c
forall a. a -> RecPatM a
forall a b. RecPatM a -> RecPatM b -> RecPatM a
forall a b. RecPatM a -> RecPatM b -> RecPatM b
forall a b. RecPatM (a -> b) -> RecPatM a -> RecPatM b
forall a b c. (a -> b -> c) -> RecPatM a -> RecPatM b -> RecPatM c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
<* :: RecPatM a -> RecPatM b -> RecPatM a
$c<* :: forall a b. RecPatM a -> RecPatM b -> RecPatM a
*> :: RecPatM a -> RecPatM b -> RecPatM b
$c*> :: forall a b. RecPatM a -> RecPatM b -> RecPatM b
liftA2 :: (a -> b -> c) -> RecPatM a -> RecPatM b -> RecPatM c
$cliftA2 :: forall a b c. (a -> b -> c) -> RecPatM a -> RecPatM b -> RecPatM c
<*> :: RecPatM (a -> b) -> RecPatM a -> RecPatM b
$c<*> :: forall a b. RecPatM (a -> b) -> RecPatM a -> RecPatM b
pure :: a -> RecPatM a
$cpure :: forall a. a -> RecPatM a
$cp1Applicative :: Functor RecPatM
Applicative, Applicative RecPatM
a -> RecPatM a
Applicative RecPatM
-> (forall a b. RecPatM a -> (a -> RecPatM b) -> RecPatM b)
-> (forall a b. RecPatM a -> RecPatM b -> RecPatM b)
-> (forall a. a -> RecPatM a)
-> Monad RecPatM
RecPatM a -> (a -> RecPatM b) -> RecPatM b
RecPatM a -> RecPatM b -> RecPatM b
forall a. a -> RecPatM a
forall a b. RecPatM a -> RecPatM b -> RecPatM b
forall a b. RecPatM a -> (a -> RecPatM b) -> RecPatM b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: a -> RecPatM a
$creturn :: forall a. a -> RecPatM a
>> :: RecPatM a -> RecPatM b -> RecPatM b
$c>> :: forall a b. RecPatM a -> RecPatM b -> RecPatM b
>>= :: RecPatM a -> (a -> RecPatM b) -> RecPatM b
$c>>= :: forall a b. RecPatM a -> (a -> RecPatM b) -> RecPatM b
$cp1Monad :: Applicative RecPatM
Monad,
Monad RecPatM
Monad RecPatM -> (forall a. IO a -> RecPatM a) -> MonadIO RecPatM
IO a -> RecPatM a
forall a. IO a -> RecPatM a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
liftIO :: IO a -> RecPatM a
$cliftIO :: forall a. IO a -> RecPatM a
$cp1MonadIO :: Monad RecPatM
MonadIO, Applicative RecPatM
MonadIO RecPatM
HasOptions RecPatM
MonadTCState RecPatM
MonadTCEnv RecPatM
Applicative RecPatM
-> MonadIO RecPatM
-> MonadTCEnv RecPatM
-> MonadTCState RecPatM
-> HasOptions RecPatM
-> (forall a. TCM a -> RecPatM a)
-> MonadTCM RecPatM
TCM a -> RecPatM a
forall a. TCM a -> RecPatM a
forall (tcm :: * -> *).
Applicative tcm
-> MonadIO tcm
-> MonadTCEnv tcm
-> MonadTCState tcm
-> HasOptions tcm
-> (forall a. TCM a -> tcm a)
-> MonadTCM tcm
liftTCM :: TCM a -> RecPatM a
$cliftTCM :: forall a. TCM a -> RecPatM a
$cp5MonadTCM :: HasOptions RecPatM
$cp4MonadTCM :: MonadTCState RecPatM
$cp3MonadTCM :: MonadTCEnv RecPatM
$cp2MonadTCM :: MonadIO RecPatM
$cp1MonadTCM :: Applicative RecPatM
MonadTCM, Monad RecPatM
Functor RecPatM
Applicative RecPatM
RecPatM PragmaOptions
RecPatM CommandLineOptions
Functor RecPatM
-> Applicative RecPatM
-> Monad RecPatM
-> RecPatM PragmaOptions
-> RecPatM CommandLineOptions
-> HasOptions RecPatM
forall (m :: * -> *).
Functor m
-> Applicative m
-> Monad m
-> m PragmaOptions
-> m CommandLineOptions
-> HasOptions m
commandLineOptions :: RecPatM CommandLineOptions
$ccommandLineOptions :: RecPatM CommandLineOptions
pragmaOptions :: RecPatM PragmaOptions
$cpragmaOptions :: RecPatM PragmaOptions
$cp3HasOptions :: Monad RecPatM
$cp2HasOptions :: Applicative RecPatM
$cp1HasOptions :: Functor RecPatM
HasOptions,
Monad RecPatM
RecPatM TCEnv
Monad RecPatM
-> RecPatM TCEnv
-> (forall a. (TCEnv -> TCEnv) -> RecPatM a -> RecPatM a)
-> MonadTCEnv RecPatM
(TCEnv -> TCEnv) -> RecPatM a -> RecPatM a
forall a. (TCEnv -> TCEnv) -> RecPatM a -> RecPatM a
forall (m :: * -> *).
Monad m
-> m TCEnv
-> (forall a. (TCEnv -> TCEnv) -> m a -> m a)
-> MonadTCEnv m
localTC :: (TCEnv -> TCEnv) -> RecPatM a -> RecPatM a
$clocalTC :: forall a. (TCEnv -> TCEnv) -> RecPatM a -> RecPatM a
askTC :: RecPatM TCEnv
$caskTC :: RecPatM TCEnv
$cp1MonadTCEnv :: Monad RecPatM
MonadTCEnv, Monad RecPatM
RecPatM TCState
Monad RecPatM
-> RecPatM TCState
-> (TCState -> RecPatM ())
-> ((TCState -> TCState) -> RecPatM ())
-> MonadTCState RecPatM
TCState -> RecPatM ()
(TCState -> TCState) -> RecPatM ()
forall (m :: * -> *).
Monad m
-> m TCState
-> (TCState -> m ())
-> ((TCState -> TCState) -> m ())
-> MonadTCState m
modifyTC :: (TCState -> TCState) -> RecPatM ()
$cmodifyTC :: (TCState -> TCState) -> RecPatM ()
putTC :: TCState -> RecPatM ()
$cputTC :: TCState -> RecPatM ()
getTC :: RecPatM TCState
$cgetTC :: RecPatM TCState
$cp1MonadTCState :: Monad RecPatM
MonadTCState)
runRecPatM :: RecPatM a -> TCM a
runRecPatM :: RecPatM a -> TCM a
runRecPatM (RecPatM TCMT (ReaderT VerboseLevel (StateT VerboseLevel IO)) a
m) =
(forall a1.
ReaderT VerboseLevel (StateT VerboseLevel IO) a1 -> IO a1)
-> TCMT (ReaderT VerboseLevel (StateT VerboseLevel IO)) a -> TCM a
forall (m :: * -> *) (n :: * -> *) a.
(forall a1. m a1 -> n a1) -> TCMT m a -> TCMT n a
mapTCMT (\ReaderT VerboseLevel (StateT VerboseLevel IO) a1
m -> do
(a1
x, VerboseLevel
noVars) <- ((a1, VerboseLevel) -> IO (a1, VerboseLevel))
-> IO (a1, VerboseLevel)
forall (m :: * -> *) a. MonadFix m => (a -> m a) -> m a
mfix (((a1, VerboseLevel) -> IO (a1, VerboseLevel))
-> IO (a1, VerboseLevel))
-> ((a1, VerboseLevel) -> IO (a1, VerboseLevel))
-> IO (a1, VerboseLevel)
forall a b. (a -> b) -> a -> b
$ \ ~(a1
_, VerboseLevel
noVars) ->
StateT VerboseLevel IO a1 -> VerboseLevel -> IO (a1, VerboseLevel)
forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
runStateT (ReaderT VerboseLevel (StateT VerboseLevel IO) a1
-> VerboseLevel -> StateT VerboseLevel IO a1
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT ReaderT VerboseLevel (StateT VerboseLevel IO) a1
m VerboseLevel
noVars) VerboseLevel
0
a1 -> IO a1
forall (m :: * -> *) a. Monad m => a -> m a
return a1
x)
TCMT (ReaderT VerboseLevel (StateT VerboseLevel IO)) a
m
nextVar :: RecPatM (Pattern, Term)
nextVar :: RecPatM (Pattern, Term)
nextVar = TCMT
(ReaderT VerboseLevel (StateT VerboseLevel IO)) (Pattern, Term)
-> RecPatM (Pattern, Term)
forall a.
TCMT (ReaderT VerboseLevel (StateT VerboseLevel IO)) a -> RecPatM a
RecPatM (TCMT
(ReaderT VerboseLevel (StateT VerboseLevel IO)) (Pattern, Term)
-> RecPatM (Pattern, Term))
-> TCMT
(ReaderT VerboseLevel (StateT VerboseLevel IO)) (Pattern, Term)
-> RecPatM (Pattern, Term)
forall a b. (a -> b) -> a -> b
$ do
VerboseLevel
n <- ReaderT VerboseLevel (StateT VerboseLevel IO) VerboseLevel
-> TCMT
(ReaderT VerboseLevel (StateT VerboseLevel IO)) VerboseLevel
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ReaderT VerboseLevel (StateT VerboseLevel IO) VerboseLevel
forall s (m :: * -> *). MonadState s m => m s
get
ReaderT VerboseLevel (StateT VerboseLevel IO) ()
-> TCMT (ReaderT VerboseLevel (StateT VerboseLevel IO)) ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT VerboseLevel (StateT VerboseLevel IO) ()
-> TCMT (ReaderT VerboseLevel (StateT VerboseLevel IO)) ())
-> ReaderT VerboseLevel (StateT VerboseLevel IO) ()
-> TCMT (ReaderT VerboseLevel (StateT VerboseLevel IO)) ()
forall a b. (a -> b) -> a -> b
$ VerboseLevel -> ReaderT VerboseLevel (StateT VerboseLevel IO) ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put (VerboseLevel -> ReaderT VerboseLevel (StateT VerboseLevel IO) ())
-> VerboseLevel -> ReaderT VerboseLevel (StateT VerboseLevel IO) ()
forall a b. (a -> b) -> a -> b
$ VerboseLevel -> VerboseLevel
forall a. Enum a => a -> a
succ VerboseLevel
n
VerboseLevel
noVars <- ReaderT VerboseLevel (StateT VerboseLevel IO) VerboseLevel
-> TCMT
(ReaderT VerboseLevel (StateT VerboseLevel IO)) VerboseLevel
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ReaderT VerboseLevel (StateT VerboseLevel IO) VerboseLevel
forall r (m :: * -> *). MonadReader r m => m r
ask
(Pattern, Term)
-> TCMT
(ReaderT VerboseLevel (StateT VerboseLevel IO)) (Pattern, Term)
forall (m :: * -> *) a. Monad m => a -> m a
return (VerboseKey -> Pattern
forall a. a -> Pattern' a
varP VerboseKey
"r", VerboseLevel -> Term
var (VerboseLevel -> Term) -> VerboseLevel -> Term
forall a b. (a -> b) -> a -> b
$ VerboseLevel
noVars VerboseLevel -> VerboseLevel -> VerboseLevel
forall a. Num a => a -> a -> a
- VerboseLevel
n VerboseLevel -> VerboseLevel -> VerboseLevel
forall a. Num a => a -> a -> a
- VerboseLevel
1)
data Kind = VarPat | DotPat
deriving Kind -> Kind -> Bool
(Kind -> Kind -> Bool) -> (Kind -> Kind -> Bool) -> Eq Kind
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Kind -> Kind -> Bool
$c/= :: Kind -> Kind -> Bool
== :: Kind -> Kind -> Bool
$c== :: Kind -> Kind -> Bool
Eq
type Change = Either Pattern (Kind -> Nat, ArgName, Dom Type)
type Changes = [Change]
instance Pretty (Kind -> Nat) where
pretty :: (Kind -> VerboseLevel) -> Doc
pretty Kind -> VerboseLevel
f =
(Doc
"(VarPat:" Doc -> Doc -> Doc
P.<+> VerboseKey -> Doc
P.text (VerboseLevel -> VerboseKey
forall a. Show a => a -> VerboseKey
show (VerboseLevel -> VerboseKey) -> VerboseLevel -> VerboseKey
forall a b. (a -> b) -> a -> b
$ Kind -> VerboseLevel
f Kind
VarPat) Doc -> Doc -> Doc
P.<+>
Doc
"DotPat:" Doc -> Doc -> Doc
P.<+> VerboseKey -> Doc
P.text (VerboseLevel -> VerboseKey
forall a. Show a => a -> VerboseKey
show (VerboseLevel -> VerboseKey) -> VerboseLevel -> VerboseKey
forall a b. (a -> b) -> a -> b
$ Kind -> VerboseLevel
f Kind
DotPat)) Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Doc
")"
instance PrettyTCM (Kind -> Nat) where
prettyTCM :: (Kind -> VerboseLevel) -> m Doc
prettyTCM = Doc -> m Doc
forall (m :: * -> *) a. Monad m => a -> m a
return (Doc -> m Doc)
-> ((Kind -> VerboseLevel) -> Doc)
-> (Kind -> VerboseLevel)
-> m Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Kind -> VerboseLevel) -> Doc
forall a. Pretty a => a -> Doc
pretty
instance PrettyTCM Change where
prettyTCM :: Change -> m Doc
prettyTCM (Left Pattern
p) = Pattern -> m Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Pattern
p
prettyTCM (Right (Kind -> VerboseLevel
f, VerboseKey
x, Dom Type
t)) = m Doc
"Change" m Doc -> m Doc -> m Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> (Kind -> VerboseLevel) -> m Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Kind -> VerboseLevel
f m Doc -> m Doc -> m Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> VerboseKey -> m Doc
forall (m :: * -> *). Applicative m => VerboseKey -> m Doc
text VerboseKey
x m Doc -> m Doc -> m Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Dom Type -> m Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Dom Type
t
data RecordTree
= Leaf Pattern
| RecCon (Arg Type) [(Term -> Term, RecordTree)]
projections :: RecordTree -> [(Term -> Term, Kind)]
projections :: RecordTree -> [(Term -> Term, Kind)]
projections (Leaf (DotP{})) = [(Term -> Term
forall a. a -> a
id, Kind
DotPat)]
projections (Leaf (VarP{})) = [(Term -> Term
forall a. a -> a
id, Kind
VarPat)]
projections (Leaf Pattern
_) = [(Term -> Term, Kind)]
forall a. HasCallStack => a
__IMPOSSIBLE__
projections (RecCon Arg Type
_ [(Term -> Term, RecordTree)]
args) =
((Term -> Term, RecordTree) -> [(Term -> Term, Kind)])
-> [(Term -> Term, RecordTree)] -> [(Term -> Term, Kind)]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\ (Term -> Term
p, RecordTree
t) -> ((Term -> Term, Kind) -> (Term -> Term, Kind))
-> [(Term -> Term, Kind)] -> [(Term -> Term, Kind)]
forall a b. (a -> b) -> [a] -> [b]
map (((Term -> Term) -> Term -> Term)
-> (Term -> Term, Kind) -> (Term -> Term, Kind)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first ((Term -> Term) -> (Term -> Term) -> Term -> Term
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Term -> Term
p)) ([(Term -> Term, Kind)] -> [(Term -> Term, Kind)])
-> [(Term -> Term, Kind)] -> [(Term -> Term, Kind)]
forall a b. (a -> b) -> a -> b
$ RecordTree -> [(Term -> Term, Kind)]
projections RecordTree
t)
[(Term -> Term, RecordTree)]
args
removeTree :: RecordTree -> RecPatM (Pattern, [Term], Changes)
removeTree :: RecordTree -> RecPatM (Pattern, [Term], Changes)
removeTree RecordTree
tree = do
(Pattern
pat, Term
x) <- RecPatM (Pattern, Term)
nextVar
let ps :: [(Term -> Term, Kind)]
ps = RecordTree -> [(Term -> Term, Kind)]
projections RecordTree
tree
s :: [Term]
s = ((Term -> Term, Kind) -> Term) -> [(Term -> Term, Kind)] -> [Term]
forall a b. (a -> b) -> [a] -> [b]
map (\(Term -> Term
p, Kind
_) -> Term -> Term
p Term
x) [(Term -> Term, Kind)]
ps
count :: Kind -> VerboseLevel
count Kind
k = [(Term -> Term, Kind)] -> VerboseLevel
forall (t :: * -> *) a. Foldable t => t a -> VerboseLevel
length ([(Term -> Term, Kind)] -> VerboseLevel)
-> [(Term -> Term, Kind)] -> VerboseLevel
forall a b. (a -> b) -> a -> b
$ ((Term -> Term, Kind) -> Bool)
-> [(Term -> Term, Kind)] -> [(Term -> Term, Kind)]
forall a. (a -> Bool) -> [a] -> [a]
filter ((Kind -> Kind -> Bool
forall a. Eq a => a -> a -> Bool
== Kind
k) (Kind -> Bool)
-> ((Term -> Term, Kind) -> Kind) -> (Term -> Term, Kind) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Term -> Term, Kind) -> Kind
forall a b. (a, b) -> b
snd) [(Term -> Term, Kind)]
ps
(Pattern, [Term], Changes) -> RecPatM (Pattern, [Term], Changes)
forall (m :: * -> *) a. Monad m => a -> m a
return ((Pattern, [Term], Changes) -> RecPatM (Pattern, [Term], Changes))
-> (Pattern, [Term], Changes) -> RecPatM (Pattern, [Term], Changes)
forall a b. (a -> b) -> a -> b
$ case RecordTree
tree of
Leaf Pattern
p -> (Pattern
p, [Term]
s, [Pattern -> Change
forall a b. a -> Either a b
Left Pattern
p])
RecCon Arg Type
t [(Term -> Term, RecordTree)]
_ -> (Pattern
pat, [Term]
s, [(Kind -> VerboseLevel, VerboseKey, Dom Type) -> Change
forall a b. b -> Either a b
Right (Kind -> VerboseLevel
count, VerboseKey
"r", Arg Type -> Dom Type
forall a. Arg a -> Dom a
domFromArg Arg Type
t)])
translatePattern :: Pattern -> RecPatM (Pattern, [Term], Changes)
translatePattern :: Pattern -> RecPatM (Pattern, [Term], Changes)
translatePattern p :: Pattern
p@(ConP ConHead
c ConPatternInfo
ci [NamedArg Pattern]
ps)
| ConPatternInfo -> Bool
conPRecord ConPatternInfo
ci , PatOrigin
PatOSystem <- PatternInfo -> PatOrigin
patOrigin (ConPatternInfo -> PatternInfo
conPInfo ConPatternInfo
ci) = do
Either (RecPatM (Pattern, [Term], Changes)) RecordTree
r <- Pattern
-> RecPatM (Either (RecPatM (Pattern, [Term], Changes)) RecordTree)
recordTree Pattern
p
case Either (RecPatM (Pattern, [Term], Changes)) RecordTree
r of
Left RecPatM (Pattern, [Term], Changes)
r -> RecPatM (Pattern, [Term], Changes)
r
Right RecordTree
t -> RecordTree -> RecPatM (Pattern, [Term], Changes)
removeTree RecordTree
t
| Bool
otherwise = do
([NamedArg Pattern]
ps, [Term]
s, Changes
cs) <- [NamedArg Pattern] -> RecPatM ([NamedArg Pattern], [Term], Changes)
translatePatterns [NamedArg Pattern]
ps
(Pattern, [Term], Changes) -> RecPatM (Pattern, [Term], Changes)
forall (m :: * -> *) a. Monad m => a -> m a
return (ConHead -> ConPatternInfo -> [NamedArg Pattern] -> Pattern
forall x.
ConHead -> ConPatternInfo -> [NamedArg (Pattern' x)] -> Pattern' x
ConP ConHead
c ConPatternInfo
ci [NamedArg Pattern]
ps, [Term]
s, Changes
cs)
translatePattern p :: Pattern
p@(DefP PatternInfo
o QName
q [NamedArg Pattern]
ps) = do
([NamedArg Pattern]
ps, [Term]
s, Changes
cs) <- [NamedArg Pattern] -> RecPatM ([NamedArg Pattern], [Term], Changes)
translatePatterns [NamedArg Pattern]
ps
(Pattern, [Term], Changes) -> RecPatM (Pattern, [Term], Changes)
forall (m :: * -> *) a. Monad m => a -> m a
return (PatternInfo -> QName -> [NamedArg Pattern] -> Pattern
forall x.
PatternInfo -> QName -> [NamedArg (Pattern' x)] -> Pattern' x
DefP PatternInfo
o QName
q [NamedArg Pattern]
ps, [Term]
s, Changes
cs)
translatePattern p :: Pattern
p@VarP{} = RecordTree -> RecPatM (Pattern, [Term], Changes)
removeTree (Pattern -> RecordTree
Leaf Pattern
p)
translatePattern p :: Pattern
p@DotP{} = RecordTree -> RecPatM (Pattern, [Term], Changes)
removeTree (Pattern -> RecordTree
Leaf Pattern
p)
translatePattern p :: Pattern
p@LitP{} = (Pattern, [Term], Changes) -> RecPatM (Pattern, [Term], Changes)
forall (m :: * -> *) a. Monad m => a -> m a
return (Pattern
p, [], [])
translatePattern p :: Pattern
p@ProjP{}= (Pattern, [Term], Changes) -> RecPatM (Pattern, [Term], Changes)
forall (m :: * -> *) a. Monad m => a -> m a
return (Pattern
p, [], [])
translatePattern p :: Pattern
p@IApplyP{}= (Pattern, [Term], Changes) -> RecPatM (Pattern, [Term], Changes)
forall (m :: * -> *) a. Monad m => a -> m a
return (Pattern
p, [], [])
translatePatterns :: [NamedArg Pattern] -> RecPatM ([NamedArg Pattern], [Term], Changes)
translatePatterns :: [NamedArg Pattern] -> RecPatM ([NamedArg Pattern], [Term], Changes)
translatePatterns [NamedArg Pattern]
ps = do
([Pattern]
ps', [[Term]]
ss, [Changes]
cs) <- [(Pattern, [Term], Changes)] -> ([Pattern], [[Term]], [Changes])
forall a b c. [(a, b, c)] -> ([a], [b], [c])
unzip3 ([(Pattern, [Term], Changes)] -> ([Pattern], [[Term]], [Changes]))
-> RecPatM [(Pattern, [Term], Changes)]
-> RecPatM ([Pattern], [[Term]], [Changes])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (NamedArg Pattern -> RecPatM (Pattern, [Term], Changes))
-> [NamedArg Pattern] -> RecPatM [(Pattern, [Term], Changes)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Pattern -> RecPatM (Pattern, [Term], Changes)
translatePattern (Pattern -> RecPatM (Pattern, [Term], Changes))
-> (NamedArg Pattern -> Pattern)
-> NamedArg Pattern
-> RecPatM (Pattern, [Term], Changes)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NamedArg Pattern -> Pattern
forall a. NamedArg a -> a
namedArg) [NamedArg Pattern]
ps
([NamedArg Pattern], [Term], Changes)
-> RecPatM ([NamedArg Pattern], [Term], Changes)
forall (m :: * -> *) a. Monad m => a -> m a
return ((Pattern -> NamedArg Pattern -> NamedArg Pattern)
-> [Pattern] -> [NamedArg Pattern] -> [NamedArg Pattern]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (\Pattern
p -> (Named NamedName Pattern -> Named NamedName Pattern)
-> NamedArg Pattern -> NamedArg Pattern
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Pattern
p Pattern -> Named NamedName Pattern -> Named NamedName Pattern
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$)) [Pattern]
ps' [NamedArg Pattern]
ps, [[Term]] -> [Term]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[Term]]
ss, [Changes] -> Changes
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [Changes]
cs)
recordTree ::
Pattern ->
RecPatM (Either (RecPatM (Pattern, [Term], Changes)) RecordTree)
recordTree :: Pattern
-> RecPatM (Either (RecPatM (Pattern, [Term], Changes)) RecordTree)
recordTree p :: Pattern
p@(ConP ConHead
c ConPatternInfo
ci [NamedArg Pattern]
ps) | ConPatternInfo -> Bool
conPRecord ConPatternInfo
ci , PatOrigin
PatOSystem <- PatternInfo -> PatOrigin
patOrigin (ConPatternInfo -> PatternInfo
conPInfo ConPatternInfo
ci) = do
let t :: Arg Type
t = Arg Type -> Maybe (Arg Type) -> Arg Type
forall a. a -> Maybe a -> a
fromMaybe Arg Type
forall a. HasCallStack => a
__IMPOSSIBLE__ (Maybe (Arg Type) -> Arg Type) -> Maybe (Arg Type) -> Arg Type
forall a b. (a -> b) -> a -> b
$ ConPatternInfo -> Maybe (Arg Type)
conPType ConPatternInfo
ci
[Either (RecPatM (Pattern, [Term], Changes)) RecordTree]
rs <- (NamedArg Pattern
-> RecPatM
(Either (RecPatM (Pattern, [Term], Changes)) RecordTree))
-> [NamedArg Pattern]
-> RecPatM [Either (RecPatM (Pattern, [Term], Changes)) RecordTree]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Pattern
-> RecPatM (Either (RecPatM (Pattern, [Term], Changes)) RecordTree)
recordTree (Pattern
-> RecPatM
(Either (RecPatM (Pattern, [Term], Changes)) RecordTree))
-> (NamedArg Pattern -> Pattern)
-> NamedArg Pattern
-> RecPatM (Either (RecPatM (Pattern, [Term], Changes)) RecordTree)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NamedArg Pattern -> Pattern
forall a. NamedArg a -> a
namedArg) [NamedArg Pattern]
ps
case [Either (RecPatM (Pattern, [Term], Changes)) RecordTree]
-> Maybe [RecordTree]
forall a b. [Either a b] -> Maybe [b]
allRight [Either (RecPatM (Pattern, [Term], Changes)) RecordTree]
rs of
Maybe [RecordTree]
Nothing ->
Either (RecPatM (Pattern, [Term], Changes)) RecordTree
-> RecPatM (Either (RecPatM (Pattern, [Term], Changes)) RecordTree)
forall (m :: * -> *) a. Monad m => a -> m a
return (Either (RecPatM (Pattern, [Term], Changes)) RecordTree
-> RecPatM
(Either (RecPatM (Pattern, [Term], Changes)) RecordTree))
-> Either (RecPatM (Pattern, [Term], Changes)) RecordTree
-> RecPatM (Either (RecPatM (Pattern, [Term], Changes)) RecordTree)
forall a b. (a -> b) -> a -> b
$ RecPatM (Pattern, [Term], Changes)
-> Either (RecPatM (Pattern, [Term], Changes)) RecordTree
forall a b. a -> Either a b
Left (RecPatM (Pattern, [Term], Changes)
-> Either (RecPatM (Pattern, [Term], Changes)) RecordTree)
-> RecPatM (Pattern, [Term], Changes)
-> Either (RecPatM (Pattern, [Term], Changes)) RecordTree
forall a b. (a -> b) -> a -> b
$ do
([Pattern]
ps', [[Term]]
ss, [Changes]
cs) <- [(Pattern, [Term], Changes)] -> ([Pattern], [[Term]], [Changes])
forall a b c. [(a, b, c)] -> ([a], [b], [c])
unzip3 ([(Pattern, [Term], Changes)] -> ([Pattern], [[Term]], [Changes]))
-> RecPatM [(Pattern, [Term], Changes)]
-> RecPatM ([Pattern], [[Term]], [Changes])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Either (RecPatM (Pattern, [Term], Changes)) RecordTree
-> RecPatM (Pattern, [Term], Changes))
-> [Either (RecPatM (Pattern, [Term], Changes)) RecordTree]
-> RecPatM [(Pattern, [Term], Changes)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM ((RecPatM (Pattern, [Term], Changes)
-> RecPatM (Pattern, [Term], Changes))
-> (RecordTree -> RecPatM (Pattern, [Term], Changes))
-> Either (RecPatM (Pattern, [Term], Changes)) RecordTree
-> RecPatM (Pattern, [Term], Changes)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either RecPatM (Pattern, [Term], Changes)
-> RecPatM (Pattern, [Term], Changes)
forall a. a -> a
id RecordTree -> RecPatM (Pattern, [Term], Changes)
removeTree) [Either (RecPatM (Pattern, [Term], Changes)) RecordTree]
rs
(Pattern, [Term], Changes) -> RecPatM (Pattern, [Term], Changes)
forall (m :: * -> *) a. Monad m => a -> m a
return (ConHead -> ConPatternInfo -> [NamedArg Pattern] -> Pattern
forall x.
ConHead -> ConPatternInfo -> [NamedArg (Pattern' x)] -> Pattern' x
ConP ConHead
c ConPatternInfo
ci ([Pattern]
ps' [Pattern] -> [NamedArg Pattern] -> [NamedArg Pattern]
forall a b. [a] -> [NamedArg b] -> [NamedArg a]
`withNamedArgsFrom` [NamedArg Pattern]
ps),
[[Term]] -> [Term]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[Term]]
ss, [Changes] -> Changes
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [Changes]
cs)
Just [RecordTree]
ts -> TCM (Either (RecPatM (Pattern, [Term], Changes)) RecordTree)
-> RecPatM (Either (RecPatM (Pattern, [Term], Changes)) RecordTree)
forall (tcm :: * -> *) a. MonadTCM tcm => TCM a -> tcm a
liftTCM (TCM (Either (RecPatM (Pattern, [Term], Changes)) RecordTree)
-> RecPatM
(Either (RecPatM (Pattern, [Term], Changes)) RecordTree))
-> TCM (Either (RecPatM (Pattern, [Term], Changes)) RecordTree)
-> RecPatM (Either (RecPatM (Pattern, [Term], Changes)) RecordTree)
forall a b. (a -> b) -> a -> b
$ do
Arg Type
t <- Arg Type -> TCMT IO (Arg Type)
forall a (m :: * -> *). (Reduce a, MonadReduce m) => a -> m a
reduce Arg Type
t
VerboseKey -> VerboseLevel -> TCM Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
VerboseKey -> VerboseLevel -> TCM Doc -> m ()
reportSDoc VerboseKey
"tc.rec" VerboseLevel
45 (TCM Doc -> TCMT IO ()) -> TCM Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [TCM Doc] -> TCM Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCM Doc
"recordTree: "
, VerboseLevel -> TCM Doc -> TCM Doc
forall (m :: * -> *). Functor m => VerboseLevel -> m Doc -> m Doc
nest VerboseLevel
2 (TCM Doc -> TCM Doc) -> TCM Doc -> TCM Doc
forall a b. (a -> b) -> a -> b
$ TCM Doc
"constructor pattern " TCM Doc -> TCM Doc -> TCM Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Pattern -> TCM Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Pattern
p TCM Doc -> TCM Doc -> TCM Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCM Doc
" has type " TCM Doc -> TCM Doc -> TCM Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Arg Type -> TCM Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Arg Type
t
]
[Dom QName]
fields <- Type -> TCM [Dom QName]
getRecordTypeFields (Type -> TCM [Dom QName]) -> TCMT IO Type -> TCM [Dom QName]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Type -> TCMT IO Type
forall a (m :: * -> *). (Reduce a, MonadReduce m) => a -> m a
reduce (Arg Type -> Type
forall e. Arg e -> e
unArg Arg Type
t)
let proj :: Dom' t QName -> t -> t
proj Dom' t QName
p = (t -> Elims -> t
forall t. Apply t => t -> Elims -> t
`applyE` [ProjOrigin -> QName -> Elim' Term
forall a. ProjOrigin -> QName -> Elim' a
Proj ProjOrigin
ProjSystem (QName -> Elim' Term) -> QName -> Elim' Term
forall a b. (a -> b) -> a -> b
$ Dom' t QName -> QName
forall t e. Dom' t e -> e
unDom Dom' t QName
p])
Either (RecPatM (Pattern, [Term], Changes)) RecordTree
-> TCM (Either (RecPatM (Pattern, [Term], Changes)) RecordTree)
forall (m :: * -> *) a. Monad m => a -> m a
return (Either (RecPatM (Pattern, [Term], Changes)) RecordTree
-> TCM (Either (RecPatM (Pattern, [Term], Changes)) RecordTree))
-> Either (RecPatM (Pattern, [Term], Changes)) RecordTree
-> TCM (Either (RecPatM (Pattern, [Term], Changes)) RecordTree)
forall a b. (a -> b) -> a -> b
$ RecordTree
-> Either (RecPatM (Pattern, [Term], Changes)) RecordTree
forall a b. b -> Either a b
Right (RecordTree
-> Either (RecPatM (Pattern, [Term], Changes)) RecordTree)
-> RecordTree
-> Either (RecPatM (Pattern, [Term], Changes)) RecordTree
forall a b. (a -> b) -> a -> b
$ Arg Type -> [(Term -> Term, RecordTree)] -> RecordTree
RecCon Arg Type
t ([(Term -> Term, RecordTree)] -> RecordTree)
-> [(Term -> Term, RecordTree)] -> RecordTree
forall a b. (a -> b) -> a -> b
$ [Term -> Term] -> [RecordTree] -> [(Term -> Term, RecordTree)]
forall a b. [a] -> [b] -> [(a, b)]
zip ((Dom QName -> Term -> Term) -> [Dom QName] -> [Term -> Term]
forall a b. (a -> b) -> [a] -> [b]
map Dom QName -> Term -> Term
forall t t. Apply t => Dom' t QName -> t -> t
proj [Dom QName]
fields) [RecordTree]
ts
recordTree p :: Pattern
p@(ConP ConHead
_ ConPatternInfo
ci [NamedArg Pattern]
_) = Either (RecPatM (Pattern, [Term], Changes)) RecordTree
-> RecPatM (Either (RecPatM (Pattern, [Term], Changes)) RecordTree)
forall (m :: * -> *) a. Monad m => a -> m a
return (Either (RecPatM (Pattern, [Term], Changes)) RecordTree
-> RecPatM
(Either (RecPatM (Pattern, [Term], Changes)) RecordTree))
-> Either (RecPatM (Pattern, [Term], Changes)) RecordTree
-> RecPatM (Either (RecPatM (Pattern, [Term], Changes)) RecordTree)
forall a b. (a -> b) -> a -> b
$ RecPatM (Pattern, [Term], Changes)
-> Either (RecPatM (Pattern, [Term], Changes)) RecordTree
forall a b. a -> Either a b
Left (RecPatM (Pattern, [Term], Changes)
-> Either (RecPatM (Pattern, [Term], Changes)) RecordTree)
-> RecPatM (Pattern, [Term], Changes)
-> Either (RecPatM (Pattern, [Term], Changes)) RecordTree
forall a b. (a -> b) -> a -> b
$ Pattern -> RecPatM (Pattern, [Term], Changes)
translatePattern Pattern
p
recordTree p :: Pattern
p@DefP{} = Either (RecPatM (Pattern, [Term], Changes)) RecordTree
-> RecPatM (Either (RecPatM (Pattern, [Term], Changes)) RecordTree)
forall (m :: * -> *) a. Monad m => a -> m a
return (Either (RecPatM (Pattern, [Term], Changes)) RecordTree
-> RecPatM
(Either (RecPatM (Pattern, [Term], Changes)) RecordTree))
-> Either (RecPatM (Pattern, [Term], Changes)) RecordTree
-> RecPatM (Either (RecPatM (Pattern, [Term], Changes)) RecordTree)
forall a b. (a -> b) -> a -> b
$ RecPatM (Pattern, [Term], Changes)
-> Either (RecPatM (Pattern, [Term], Changes)) RecordTree
forall a b. a -> Either a b
Left (RecPatM (Pattern, [Term], Changes)
-> Either (RecPatM (Pattern, [Term], Changes)) RecordTree)
-> RecPatM (Pattern, [Term], Changes)
-> Either (RecPatM (Pattern, [Term], Changes)) RecordTree
forall a b. (a -> b) -> a -> b
$ Pattern -> RecPatM (Pattern, [Term], Changes)
translatePattern Pattern
p
recordTree p :: Pattern
p@VarP{} = Either (RecPatM (Pattern, [Term], Changes)) RecordTree
-> RecPatM (Either (RecPatM (Pattern, [Term], Changes)) RecordTree)
forall (m :: * -> *) a. Monad m => a -> m a
return (RecordTree
-> Either (RecPatM (Pattern, [Term], Changes)) RecordTree
forall a b. b -> Either a b
Right (Pattern -> RecordTree
Leaf Pattern
p))
recordTree p :: Pattern
p@DotP{} = Either (RecPatM (Pattern, [Term], Changes)) RecordTree
-> RecPatM (Either (RecPatM (Pattern, [Term], Changes)) RecordTree)
forall (m :: * -> *) a. Monad m => a -> m a
return (RecordTree
-> Either (RecPatM (Pattern, [Term], Changes)) RecordTree
forall a b. b -> Either a b
Right (Pattern -> RecordTree
Leaf Pattern
p))
recordTree p :: Pattern
p@LitP{} = Either (RecPatM (Pattern, [Term], Changes)) RecordTree
-> RecPatM (Either (RecPatM (Pattern, [Term], Changes)) RecordTree)
forall (m :: * -> *) a. Monad m => a -> m a
return (Either (RecPatM (Pattern, [Term], Changes)) RecordTree
-> RecPatM
(Either (RecPatM (Pattern, [Term], Changes)) RecordTree))
-> Either (RecPatM (Pattern, [Term], Changes)) RecordTree
-> RecPatM (Either (RecPatM (Pattern, [Term], Changes)) RecordTree)
forall a b. (a -> b) -> a -> b
$ RecPatM (Pattern, [Term], Changes)
-> Either (RecPatM (Pattern, [Term], Changes)) RecordTree
forall a b. a -> Either a b
Left (RecPatM (Pattern, [Term], Changes)
-> Either (RecPatM (Pattern, [Term], Changes)) RecordTree)
-> RecPatM (Pattern, [Term], Changes)
-> Either (RecPatM (Pattern, [Term], Changes)) RecordTree
forall a b. (a -> b) -> a -> b
$ Pattern -> RecPatM (Pattern, [Term], Changes)
translatePattern Pattern
p
recordTree p :: Pattern
p@ProjP{}= Either (RecPatM (Pattern, [Term], Changes)) RecordTree
-> RecPatM (Either (RecPatM (Pattern, [Term], Changes)) RecordTree)
forall (m :: * -> *) a. Monad m => a -> m a
return (Either (RecPatM (Pattern, [Term], Changes)) RecordTree
-> RecPatM
(Either (RecPatM (Pattern, [Term], Changes)) RecordTree))
-> Either (RecPatM (Pattern, [Term], Changes)) RecordTree
-> RecPatM (Either (RecPatM (Pattern, [Term], Changes)) RecordTree)
forall a b. (a -> b) -> a -> b
$ RecPatM (Pattern, [Term], Changes)
-> Either (RecPatM (Pattern, [Term], Changes)) RecordTree
forall a b. a -> Either a b
Left (RecPatM (Pattern, [Term], Changes)
-> Either (RecPatM (Pattern, [Term], Changes)) RecordTree)
-> RecPatM (Pattern, [Term], Changes)
-> Either (RecPatM (Pattern, [Term], Changes)) RecordTree
forall a b. (a -> b) -> a -> b
$ Pattern -> RecPatM (Pattern, [Term], Changes)
translatePattern Pattern
p
recordTree p :: Pattern
p@IApplyP{}= Either (RecPatM (Pattern, [Term], Changes)) RecordTree
-> RecPatM (Either (RecPatM (Pattern, [Term], Changes)) RecordTree)
forall (m :: * -> *) a. Monad m => a -> m a
return (Either (RecPatM (Pattern, [Term], Changes)) RecordTree
-> RecPatM
(Either (RecPatM (Pattern, [Term], Changes)) RecordTree))
-> Either (RecPatM (Pattern, [Term], Changes)) RecordTree
-> RecPatM (Either (RecPatM (Pattern, [Term], Changes)) RecordTree)
forall a b. (a -> b) -> a -> b
$ RecPatM (Pattern, [Term], Changes)
-> Either (RecPatM (Pattern, [Term], Changes)) RecordTree
forall a b. a -> Either a b
Left (RecPatM (Pattern, [Term], Changes)
-> Either (RecPatM (Pattern, [Term], Changes)) RecordTree)
-> RecPatM (Pattern, [Term], Changes)
-> Either (RecPatM (Pattern, [Term], Changes)) RecordTree
forall a b. (a -> b) -> a -> b
$ Pattern -> RecPatM (Pattern, [Term], Changes)
translatePattern Pattern
p
translateTel
:: Changes
-> [(ArgName, Dom Type)]
-> [Maybe (ArgName, Dom Type)]
translateTel :: Changes
-> [(VerboseKey, Dom Type)] -> [Maybe (VerboseKey, Dom Type)]
translateTel (Left (DotP{}) : Changes
rest) [(VerboseKey, Dom Type)]
tel = Maybe (VerboseKey, Dom Type)
forall a. Maybe a
Nothing Maybe (VerboseKey, Dom Type)
-> [Maybe (VerboseKey, Dom Type)] -> [Maybe (VerboseKey, Dom Type)]
forall a. a -> [a] -> [a]
: Changes
-> [(VerboseKey, Dom Type)] -> [Maybe (VerboseKey, Dom Type)]
translateTel Changes
rest [(VerboseKey, Dom Type)]
tel
translateTel (Right (Kind -> VerboseLevel
n, VerboseKey
x, Dom Type
t) : Changes
rest) [(VerboseKey, Dom Type)]
tel = (VerboseKey, Dom Type) -> Maybe (VerboseKey, Dom Type)
forall a. a -> Maybe a
Just (VerboseKey
x, Dom Type
t) Maybe (VerboseKey, Dom Type)
-> [Maybe (VerboseKey, Dom Type)] -> [Maybe (VerboseKey, Dom Type)]
forall a. a -> [a] -> [a]
:
Changes
-> [(VerboseKey, Dom Type)] -> [Maybe (VerboseKey, Dom Type)]
translateTel Changes
rest
(VerboseLevel
-> [(VerboseKey, Dom Type)] -> [(VerboseKey, Dom Type)]
forall a. VerboseLevel -> [a] -> [a]
drop (Kind -> VerboseLevel
n Kind
VarPat) [(VerboseKey, Dom Type)]
tel)
translateTel (Left Pattern
_ : Changes
rest) ((VerboseKey, Dom Type)
t : [(VerboseKey, Dom Type)]
tel) = (VerboseKey, Dom Type) -> Maybe (VerboseKey, Dom Type)
forall a. a -> Maybe a
Just (VerboseKey, Dom Type)
t Maybe (VerboseKey, Dom Type)
-> [Maybe (VerboseKey, Dom Type)] -> [Maybe (VerboseKey, Dom Type)]
forall a. a -> [a] -> [a]
: Changes
-> [(VerboseKey, Dom Type)] -> [Maybe (VerboseKey, Dom Type)]
translateTel Changes
rest [(VerboseKey, Dom Type)]
tel
translateTel [] [] = []
translateTel (Left Pattern
_ : Changes
_) [] = [Maybe (VerboseKey, Dom Type)]
forall a. HasCallStack => a
__IMPOSSIBLE__
translateTel [] ((VerboseKey, Dom Type)
_ : [(VerboseKey, Dom Type)]
_) = [Maybe (VerboseKey, Dom Type)]
forall a. HasCallStack => a
__IMPOSSIBLE__