module Agda.TypeChecking.Coverage.Match
( Match(..), match, matchClause
, SplitPattern, SplitPatVar(..)
, fromSplitPattern, fromSplitPatterns, toSplitPatterns
, toSplitPSubst, applySplitPSubst
, isTrivialPattern
, BlockingVar(..), BlockingVars, BlockedOnResult(..)
, setBlockingVarOverlap
, ApplyOrIApply(..)
) where
import Control.Monad.State
import Prelude hiding ( null )
import Data.DList (DList)
import Data.Foldable (toList)
import qualified Data.List as List
import Data.Maybe (mapMaybe, fromMaybe)
import Data.Semigroup ( Semigroup, (<>))
import Agda.Syntax.Common
import Agda.Syntax.Internal
import Agda.Syntax.Literal
import Agda.Syntax.Position
import Agda.TypeChecking.Monad
import Agda.TypeChecking.Pretty ( PrettyTCM(..) )
import Agda.TypeChecking.Records
import Agda.TypeChecking.Reduce
import Agda.TypeChecking.Substitute
import Agda.Utils.Null
import Agda.Utils.Pretty ( Pretty(..), text, (<+>), cat , prettyList_ )
import Agda.Utils.Monad
import Agda.Utils.Singleton
import Agda.Utils.Impossible
data Match a
= Yes a
| No
| Block
{ forall a. Match a -> BlockedOnResult
blockedOnResult :: BlockedOnResult
, forall a. Match a -> BlockingVars
blockedOnVars :: BlockingVars
}
deriving (forall a b. a -> Match b -> Match a
forall a b. (a -> b) -> Match a -> Match b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Match b -> Match a
$c<$ :: forall a b. a -> Match b -> Match a
fmap :: forall a b. (a -> b) -> Match a -> Match b
$cfmap :: forall a b. (a -> b) -> Match a -> Match b
Functor)
data BlockedOnResult
= BlockedOnProj
{ BlockedOnResult -> Bool
blockedOnResultOverlap :: Bool
}
| BlockedOnApply
{ BlockedOnResult -> ApplyOrIApply
blockedOnResultIApply :: ApplyOrIApply
}
| NotBlockedOnResult
data ApplyOrIApply = IsApply | IsIApply
data BlockingVar = BlockingVar
{ BlockingVar -> Nat
blockingVarNo :: Nat
, BlockingVar -> [ConHead]
blockingVarCons :: [ConHead]
, BlockingVar -> [Literal]
blockingVarLits :: [Literal]
, BlockingVar -> Bool
blockingVarOverlap :: Bool
, BlockingVar -> Bool
blockingVarLazy :: Bool
} deriving (Nat -> BlockingVar -> ShowS
BlockingVars -> ShowS
BlockingVar -> String
forall a.
(Nat -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: BlockingVars -> ShowS
$cshowList :: BlockingVars -> ShowS
show :: BlockingVar -> String
$cshow :: BlockingVar -> String
showsPrec :: Nat -> BlockingVar -> ShowS
$cshowsPrec :: Nat -> BlockingVar -> ShowS
Show)
type BlockingVars = [BlockingVar]
type SplitInstantiation = [(Nat,SplitPattern)]
match :: PureTCM m
=> [Clause]
-> [NamedArg SplitPattern]
-> m (Match (Nat, SplitInstantiation))
match :: forall (m :: * -> *).
PureTCM m =>
[Clause]
-> [NamedArg SplitPattern] -> m (Match (Nat, SplitInstantiation))
match [Clause]
cs [NamedArg SplitPattern]
ps = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr forall (m :: * -> *) a.
Monad m =>
m (Match a) -> m (Match a) -> m (Match a)
choice (forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Match a
No) forall a b. (a -> b) -> a -> b
$ forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith forall (m :: * -> *).
PureTCM m =>
Nat -> Clause -> m (Match (Nat, SplitInstantiation))
matchIt [Nat
0..] [Clause]
cs
where
matchIt :: PureTCM m
=> Nat
-> Clause
-> m (Match (Nat, SplitInstantiation))
matchIt :: forall (m :: * -> *).
PureTCM m =>
Nat -> Clause -> m (Match (Nat, SplitInstantiation))
matchIt Nat
i Clause
c = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\DList (Nat, SplitPattern)
s -> (Nat
i, forall (t :: * -> *) a. Foldable t => t a -> [a]
toList DList (Nat, SplitPattern)
s)) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *).
PureTCM m =>
[NamedArg SplitPattern] -> Clause -> m MatchResult
matchClause [NamedArg SplitPattern]
ps Clause
c
data SplitPatVar = SplitPatVar
{ SplitPatVar -> String
splitPatVarName :: PatVarName
, SplitPatVar -> Nat
splitPatVarIndex :: Int
, SplitPatVar -> [Literal]
splitExcludedLits :: [Literal]
} deriving (Nat -> SplitPatVar -> ShowS
[SplitPatVar] -> ShowS
SplitPatVar -> String
forall a.
(Nat -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SplitPatVar] -> ShowS
$cshowList :: [SplitPatVar] -> ShowS
show :: SplitPatVar -> String
$cshow :: SplitPatVar -> String
showsPrec :: Nat -> SplitPatVar -> ShowS
$cshowsPrec :: Nat -> SplitPatVar -> ShowS
Show)
instance Pretty SplitPatVar where
prettyPrec :: Nat -> SplitPatVar -> Doc
prettyPrec Nat
_ SplitPatVar
x =
String -> Doc
text (ShowS
patVarNameToString (SplitPatVar -> String
splitPatVarName SplitPatVar
x)) forall a. Semigroup a => a -> a -> a
<>
String -> Doc
text (String
"@" forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show (SplitPatVar -> Nat
splitPatVarIndex SplitPatVar
x)) forall a. Semigroup a => a -> a -> a
<>
forall a b. Null a => a -> b -> (a -> b) -> b
ifNull (SplitPatVar -> [Literal]
splitExcludedLits SplitPatVar
x) forall a. Null a => a
empty (\[Literal]
lits ->
Doc
"\\{" forall a. Semigroup a => a -> a -> a
<> forall a. Pretty a => [a] -> Doc
prettyList_ [Literal]
lits forall a. Semigroup a => a -> a -> a
<> Doc
"}")
instance PrettyTCM SplitPatVar where
prettyTCM :: forall (m :: * -> *). MonadPretty m => SplitPatVar -> m Doc
prettyTCM = forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM forall b c a. (b -> c) -> (a -> b) -> a -> c
. Nat -> Term
var forall b c a. (b -> c) -> (a -> b) -> a -> c
. SplitPatVar -> Nat
splitPatVarIndex
type SplitPattern = Pattern' SplitPatVar
toSplitVar :: DBPatVar -> SplitPatVar
toSplitVar :: DBPatVar -> SplitPatVar
toSplitVar DBPatVar
x = String -> Nat -> [Literal] -> SplitPatVar
SplitPatVar (DBPatVar -> String
dbPatVarName DBPatVar
x) (DBPatVar -> Nat
dbPatVarIndex DBPatVar
x) []
fromSplitVar :: SplitPatVar -> DBPatVar
fromSplitVar :: SplitPatVar -> DBPatVar
fromSplitVar SplitPatVar
x = String -> Nat -> DBPatVar
DBPatVar (SplitPatVar -> String
splitPatVarName SplitPatVar
x) (SplitPatVar -> Nat
splitPatVarIndex SplitPatVar
x)
instance DeBruijn SplitPatVar where
deBruijnView :: SplitPatVar -> Maybe Nat
deBruijnView SplitPatVar
x = forall a. DeBruijn a => a -> Maybe Nat
deBruijnView (SplitPatVar -> DBPatVar
fromSplitVar SplitPatVar
x)
debruijnNamedVar :: String -> Nat -> SplitPatVar
debruijnNamedVar String
n Nat
i = DBPatVar -> SplitPatVar
toSplitVar (forall a. DeBruijn a => String -> Nat -> a
debruijnNamedVar String
n Nat
i)
toSplitPatterns :: [NamedArg DeBruijnPattern] -> [NamedArg SplitPattern]
toSplitPatterns :: [NamedArg DeBruijnPattern] -> [NamedArg SplitPattern]
toSplitPatterns = (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap) DBPatVar -> SplitPatVar
toSplitVar
fromSplitPattern :: NamedArg SplitPattern -> NamedArg DeBruijnPattern
fromSplitPattern :: NamedArg SplitPattern -> NamedArg DeBruijnPattern
fromSplitPattern = (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap) SplitPatVar -> DBPatVar
fromSplitVar
fromSplitPatterns :: [NamedArg SplitPattern] -> [NamedArg DeBruijnPattern]
fromSplitPatterns :: [NamedArg SplitPattern] -> [NamedArg DeBruijnPattern]
fromSplitPatterns = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap NamedArg SplitPattern -> NamedArg DeBruijnPattern
fromSplitPattern
type SplitPSubstitution = Substitution' SplitPattern
toSplitPSubst :: PatternSubstitution -> SplitPSubstitution
toSplitPSubst :: PatternSubstitution -> SplitPSubstitution
toSplitPSubst = (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap) DBPatVar -> SplitPatVar
toSplitVar
fromSplitPSubst :: SplitPSubstitution -> PatternSubstitution
fromSplitPSubst :: SplitPSubstitution -> PatternSubstitution
fromSplitPSubst = (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap) SplitPatVar -> DBPatVar
fromSplitVar
applySplitPSubst :: TermSubst a => SplitPSubstitution -> a -> a
applySplitPSubst :: forall a. TermSubst a => SplitPSubstitution -> a -> a
applySplitPSubst = forall a. TermSubst a => PatternSubstitution -> a -> a
applyPatSubst forall b c a. (b -> c) -> (a -> b) -> a -> c
. SplitPSubstitution -> PatternSubstitution
fromSplitPSubst
instance Subst SplitPattern where
type SubstArg SplitPattern = SplitPattern
applySubst :: Substitution' (SubstArg SplitPattern)
-> SplitPattern -> SplitPattern
applySubst Substitution' (SubstArg SplitPattern)
IdS = forall a. a -> a
id
applySubst Substitution' (SubstArg SplitPattern)
rho = \case
VarP PatternInfo
i SplitPatVar
x ->
forall a. PatternInfo -> Pattern' a -> Pattern' a
usePatternInfo PatternInfo
i forall a b. (a -> b) -> a -> b
$
String -> SplitPattern -> SplitPattern
useName (SplitPatVar -> String
splitPatVarName SplitPatVar
x) forall a b. (a -> b) -> a -> b
$
[Literal] -> SplitPattern -> SplitPattern
useExcludedLits (SplitPatVar -> [Literal]
splitExcludedLits SplitPatVar
x) forall a b. (a -> b) -> a -> b
$
forall a. EndoSubst a => Substitution' a -> Nat -> a
lookupS Substitution' (SubstArg SplitPattern)
rho forall a b. (a -> b) -> a -> b
$ SplitPatVar -> Nat
splitPatVarIndex SplitPatVar
x
DotP PatternInfo
i Term
u -> forall x. PatternInfo -> Term -> Pattern' x
DotP PatternInfo
i forall a b. (a -> b) -> a -> b
$ forall a. TermSubst a => SplitPSubstitution -> a -> a
applySplitPSubst Substitution' (SubstArg SplitPattern)
rho Term
u
ConP ConHead
c ConPatternInfo
ci [NamedArg SplitPattern]
ps -> forall x.
ConHead -> ConPatternInfo -> [NamedArg (Pattern' x)] -> Pattern' x
ConP ConHead
c ConPatternInfo
ci forall a b. (a -> b) -> a -> b
$ forall a. Subst a => Substitution' (SubstArg a) -> a -> a
applySubst Substitution' (SubstArg SplitPattern)
rho [NamedArg SplitPattern]
ps
DefP PatternInfo
i QName
q [NamedArg SplitPattern]
ps -> forall x.
PatternInfo -> QName -> [NamedArg (Pattern' x)] -> Pattern' x
DefP PatternInfo
i QName
q forall a b. (a -> b) -> a -> b
$ forall a. Subst a => Substitution' (SubstArg a) -> a -> a
applySubst Substitution' (SubstArg SplitPattern)
rho [NamedArg SplitPattern]
ps
p :: SplitPattern
p@LitP{} -> SplitPattern
p
p :: SplitPattern
p@ProjP{} -> SplitPattern
p
IApplyP PatternInfo
i Term
l Term
r SplitPatVar
x ->
Term -> Term -> SplitPattern -> SplitPattern
useEndPoints (forall a. TermSubst a => SplitPSubstitution -> a -> a
applySplitPSubst Substitution' (SubstArg SplitPattern)
rho Term
l) (forall a. TermSubst a => SplitPSubstitution -> a -> a
applySplitPSubst Substitution' (SubstArg SplitPattern)
rho Term
r) forall a b. (a -> b) -> a -> b
$
forall a. PatternInfo -> Pattern' a -> Pattern' a
usePatternInfo PatternInfo
i forall a b. (a -> b) -> a -> b
$
String -> SplitPattern -> SplitPattern
useName (SplitPatVar -> String
splitPatVarName SplitPatVar
x) forall a b. (a -> b) -> a -> b
$
[Literal] -> SplitPattern -> SplitPattern
useExcludedLits (SplitPatVar -> [Literal]
splitExcludedLits SplitPatVar
x) forall a b. (a -> b) -> a -> b
$
forall a. EndoSubst a => Substitution' a -> Nat -> a
lookupS Substitution' (SubstArg SplitPattern)
rho forall a b. (a -> b) -> a -> b
$ SplitPatVar -> Nat
splitPatVarIndex SplitPatVar
x
where
useEndPoints :: Term -> Term -> SplitPattern -> SplitPattern
useEndPoints :: Term -> Term -> SplitPattern -> SplitPattern
useEndPoints Term
l Term
r (VarP PatternInfo
o SplitPatVar
x) = forall x. PatternInfo -> Term -> Term -> x -> Pattern' x
IApplyP PatternInfo
o Term
l Term
r SplitPatVar
x
useEndPoints Term
l Term
r (IApplyP PatternInfo
o Term
_ Term
_ SplitPatVar
x) = forall x. PatternInfo -> Term -> Term -> x -> Pattern' x
IApplyP PatternInfo
o Term
l Term
r SplitPatVar
x
useEndPoints Term
l Term
r SplitPattern
x = forall a. HasCallStack => a
__IMPOSSIBLE__
useName :: PatVarName -> SplitPattern -> SplitPattern
useName :: String -> SplitPattern -> SplitPattern
useName String
n (VarP PatternInfo
o SplitPatVar
x)
| forall a. Underscore a => a -> Bool
isUnderscore (SplitPatVar -> String
splitPatVarName SplitPatVar
x)
= forall x. PatternInfo -> x -> Pattern' x
VarP PatternInfo
o forall a b. (a -> b) -> a -> b
$ SplitPatVar
x { splitPatVarName :: String
splitPatVarName = String
n }
useName String
_ SplitPattern
x = SplitPattern
x
useExcludedLits :: [Literal] -> SplitPattern -> SplitPattern
useExcludedLits :: [Literal] -> SplitPattern -> SplitPattern
useExcludedLits [Literal]
lits = \case
(VarP PatternInfo
o SplitPatVar
x) -> forall x. PatternInfo -> x -> Pattern' x
VarP PatternInfo
o forall a b. (a -> b) -> a -> b
$ SplitPatVar
x
{ splitExcludedLits :: [Literal]
splitExcludedLits = [Literal]
lits forall a. [a] -> [a] -> [a]
++ SplitPatVar -> [Literal]
splitExcludedLits SplitPatVar
x }
SplitPattern
p -> SplitPattern
p
isTrivialPattern :: (HasConstInfo m) => Pattern' a -> m Bool
isTrivialPattern :: forall (m :: * -> *) a. HasConstInfo m => Pattern' a -> m Bool
isTrivialPattern = \case
VarP{} -> forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
DotP{} -> forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
ConP ConHead
c ConPatternInfo
i [NamedArg (Pattern' a)]
ps -> forall (f :: * -> *) (m :: * -> *).
(Foldable f, Monad m) =>
f (m Bool) -> m Bool
andM forall a b. (a -> b) -> a -> b
$ ((ConPatternInfo -> Bool
conPLazy ConPatternInfo
i Bool -> Bool -> Bool
||) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). HasConstInfo m => QName -> m Bool
isEtaCon (ConHead -> QName
conName ConHead
c))
forall a. a -> [a] -> [a]
: (forall a b. (a -> b) -> [a] -> [b]
map (forall (m :: * -> *) a. HasConstInfo m => Pattern' a -> m Bool
isTrivialPattern forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. NamedArg a -> a
namedArg) [NamedArg (Pattern' a)]
ps)
DefP{} -> forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
LitP{} -> forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
ProjP{} -> forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
IApplyP{} -> forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
type MatchResult = Match (DList (Nat, SplitPattern))
instance Pretty BlockingVar where
pretty :: BlockingVar -> Doc
pretty (BlockingVar Nat
i [ConHead]
cs [Literal]
ls Bool
o Bool
l) = [Doc] -> Doc
cat
[ String -> Doc
text (String
"variable " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show Nat
i)
, if forall a. Null a => a -> Bool
null [ConHead]
cs then forall a. Null a => a
empty else Doc
" blocked on constructors" Doc -> Doc -> Doc
<+> forall a. Pretty a => a -> Doc
pretty [ConHead]
cs
, if forall a. Null a => a -> Bool
null [Literal]
ls then forall a. Null a => a
empty else Doc
" blocked on literals" Doc -> Doc -> Doc
<+> forall a. Pretty a => a -> Doc
pretty [Literal]
ls
, if Bool
o then Doc
" (overlapping)" else forall a. Null a => a
empty
, if Bool
l then Doc
" (lazy)" else forall a. Null a => a
empty
]
yes :: Monad m => a -> m (Match a)
yes :: forall (m :: * -> *) a. Monad m => a -> m (Match a)
yes = forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Match a
Yes
no :: Monad m => m (Match a)
no :: forall (m :: * -> *) a. Monad m => m (Match a)
no = forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Match a
No
blockedOnConstructor :: Monad m => Nat -> ConHead -> ConPatternInfo -> m (Match a)
blockedOnConstructor :: forall (m :: * -> *) a.
Monad m =>
Nat -> ConHead -> ConPatternInfo -> m (Match a)
blockedOnConstructor Nat
i ConHead
c ConPatternInfo
ci = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. BlockedOnResult -> BlockingVars -> Match a
Block BlockedOnResult
NotBlockedOnResult [Nat -> [ConHead] -> [Literal] -> Bool -> Bool -> BlockingVar
BlockingVar Nat
i [ConHead
c] [] Bool
False forall a b. (a -> b) -> a -> b
$ ConPatternInfo -> Bool
conPLazy ConPatternInfo
ci]
blockedOnLiteral :: Monad m => Nat -> Literal -> m (Match a)
blockedOnLiteral :: forall (m :: * -> *) a. Monad m => Nat -> Literal -> m (Match a)
blockedOnLiteral Nat
i Literal
l = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. BlockedOnResult -> BlockingVars -> Match a
Block BlockedOnResult
NotBlockedOnResult [Nat -> [ConHead] -> [Literal] -> Bool -> Bool -> BlockingVar
BlockingVar Nat
i [] [Literal
l] Bool
False Bool
False]
blockedOnProjection :: Monad m => m (Match a)
blockedOnProjection :: forall (m :: * -> *) a. Monad m => m (Match a)
blockedOnProjection = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. BlockedOnResult -> BlockingVars -> Match a
Block (Bool -> BlockedOnResult
BlockedOnProj Bool
False) []
blockedOnApplication :: Monad m => ApplyOrIApply -> m (Match a)
blockedOnApplication :: forall (m :: * -> *) a. Monad m => ApplyOrIApply -> m (Match a)
blockedOnApplication ApplyOrIApply
b = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. BlockedOnResult -> BlockingVars -> Match a
Block (ApplyOrIApply -> BlockedOnResult
BlockedOnApply ApplyOrIApply
b) []
setBlockingVarOverlap :: BlockingVar -> BlockingVar
setBlockingVarOverlap :: BlockingVar -> BlockingVar
setBlockingVarOverlap = \BlockingVar
x -> BlockingVar
x { blockingVarOverlap :: Bool
blockingVarOverlap = Bool
True }
overlapping :: BlockingVars -> BlockingVars
overlapping :: BlockingVars -> BlockingVars
overlapping = forall a b. (a -> b) -> [a] -> [b]
map BlockingVar -> BlockingVar
setBlockingVarOverlap
zipBlockingVars :: BlockingVars -> BlockingVars -> BlockingVars
zipBlockingVars :: BlockingVars -> BlockingVars -> BlockingVars
zipBlockingVars BlockingVars
xs BlockingVars
ys = forall a b. (a -> b) -> [a] -> [b]
map BlockingVar -> BlockingVar
upd BlockingVars
xs
where
upd :: BlockingVar -> BlockingVar
upd (BlockingVar Nat
x [ConHead]
cons [Literal]
lits Bool
o Bool
l) = case forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
List.find ((Nat
x forall a. Eq a => a -> a -> Bool
==) forall b c a. (b -> c) -> (a -> b) -> a -> c
. BlockingVar -> Nat
blockingVarNo) BlockingVars
ys of
Just (BlockingVar Nat
_ [ConHead]
cons' [Literal]
lits' Bool
o' Bool
l') -> Nat -> [ConHead] -> [Literal] -> Bool -> Bool -> BlockingVar
BlockingVar Nat
x ([ConHead]
cons forall a. [a] -> [a] -> [a]
++ [ConHead]
cons') ([Literal]
lits forall a. [a] -> [a] -> [a]
++ [Literal]
lits') (Bool
o Bool -> Bool -> Bool
|| Bool
o') (Bool
l Bool -> Bool -> Bool
|| Bool
l')
Maybe BlockingVar
Nothing -> Nat -> [ConHead] -> [Literal] -> Bool -> Bool -> BlockingVar
BlockingVar Nat
x [ConHead]
cons [Literal]
lits Bool
True Bool
l
setBlockedOnResultOverlap :: BlockedOnResult -> BlockedOnResult
setBlockedOnResultOverlap :: BlockedOnResult -> BlockedOnResult
setBlockedOnResultOverlap BlockedOnResult
b = case BlockedOnResult
b of
BlockedOnProj{} -> BlockedOnResult
b { blockedOnResultOverlap :: Bool
blockedOnResultOverlap = Bool
True }
BlockedOnApply{} -> BlockedOnResult
b
NotBlockedOnResult{} -> BlockedOnResult
b
anyBlockedOnResult :: BlockedOnResult -> BlockedOnResult -> BlockedOnResult
anyBlockedOnResult :: BlockedOnResult -> BlockedOnResult -> BlockedOnResult
anyBlockedOnResult BlockedOnResult
b1 BlockedOnResult
b2 = case (BlockedOnResult
b1,BlockedOnResult
b2) of
(BlockedOnResult
NotBlockedOnResult , BlockedOnResult
b2 ) -> BlockedOnResult
b2
(BlockedOnResult
b1 , BlockedOnResult
NotBlockedOnResult) -> BlockedOnResult
b1
(BlockedOnResult
_ , BlockedOnResult
_ ) -> forall a. HasCallStack => a
__IMPOSSIBLE__
choiceBlockedOnResult :: BlockedOnResult -> BlockedOnResult -> BlockedOnResult
choiceBlockedOnResult :: BlockedOnResult -> BlockedOnResult -> BlockedOnResult
choiceBlockedOnResult BlockedOnResult
b1 BlockedOnResult
b2 = case (BlockedOnResult
b1,BlockedOnResult
b2) of
(BlockedOnResult
NotBlockedOnResult , BlockedOnResult
_ ) -> BlockedOnResult
NotBlockedOnResult
(BlockedOnProj Bool
o1 , BlockedOnProj Bool
o2 ) -> Bool -> BlockedOnResult
BlockedOnProj (Bool
o1 Bool -> Bool -> Bool
|| Bool
o2)
(BlockedOnProj Bool
_ , BlockedOnResult
_ ) -> Bool -> BlockedOnResult
BlockedOnProj Bool
True
(BlockedOnApply ApplyOrIApply
b , BlockedOnResult
_ ) -> ApplyOrIApply -> BlockedOnResult
BlockedOnApply ApplyOrIApply
b
choice :: Monad m => m (Match a) -> m (Match a) -> m (Match a)
choice :: forall (m :: * -> *) a.
Monad m =>
m (Match a) -> m (Match a) -> m (Match a)
choice m (Match a)
m m (Match a)
m' = m (Match a)
m forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Yes a
a -> forall (m :: * -> *) a. Monad m => a -> m (Match a)
yes a
a
Block BlockedOnResult
r BlockingVars
xs -> m (Match a)
m' forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Block BlockedOnResult
s BlockingVars
ys -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. BlockedOnResult -> BlockingVars -> Match a
Block (BlockedOnResult -> BlockedOnResult -> BlockedOnResult
choiceBlockedOnResult BlockedOnResult
r BlockedOnResult
s) forall a b. (a -> b) -> a -> b
$ BlockingVars -> BlockingVars -> BlockingVars
zipBlockingVars BlockingVars
xs BlockingVars
ys
Yes a
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. BlockedOnResult -> BlockingVars -> Match a
Block (BlockedOnResult -> BlockedOnResult
setBlockedOnResultOverlap BlockedOnResult
r) forall a b. (a -> b) -> a -> b
$ BlockingVars -> BlockingVars
overlapping BlockingVars
xs
Match a
No -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. BlockedOnResult -> BlockingVars -> Match a
Block BlockedOnResult
r BlockingVars
xs
Match a
No -> m (Match a)
m'
matchClause
:: PureTCM m
=> [NamedArg SplitPattern]
-> Clause
-> m MatchResult
matchClause :: forall (m :: * -> *).
PureTCM m =>
[NamedArg SplitPattern] -> Clause -> m MatchResult
matchClause [NamedArg SplitPattern]
qs Clause
c = forall (m :: * -> *) a.
(PureTCM m, DeBruijn a) =>
[NamedArg (Pattern' a)] -> [NamedArg SplitPattern] -> m MatchResult
matchPats (Clause -> [NamedArg DeBruijnPattern]
namedClausePats Clause
c) [NamedArg SplitPattern]
qs
matchPats
:: (PureTCM m, DeBruijn a)
=> [NamedArg (Pattern' a)]
-> [NamedArg SplitPattern]
-> m MatchResult
matchPats :: forall (m :: * -> *) a.
(PureTCM m, DeBruijn a) =>
[NamedArg (Pattern' a)] -> [NamedArg SplitPattern] -> m MatchResult
matchPats [] [] = forall (m :: * -> *) a. Monad m => a -> m (Match a)
yes forall a. Monoid a => a
mempty
matchPats (NamedArg (Pattern' a)
p:[NamedArg (Pattern' a)]
ps) (NamedArg SplitPattern
q:[NamedArg SplitPattern]
qs) =
forall (m :: * -> *) a.
(PureTCM m, DeBruijn a) =>
Pattern' a -> SplitPattern -> m MatchResult
matchPat (forall a. NamedArg a -> a
namedArg NamedArg (Pattern' a)
p) (forall a. NamedArg a -> a
namedArg NamedArg SplitPattern
q) forall (m :: * -> *) a.
(Monad m, Semigroup a) =>
m (Match a) -> m (Match a) -> m (Match a)
`combine` forall (m :: * -> *) a.
(PureTCM m, DeBruijn a) =>
[NamedArg (Pattern' a)] -> [NamedArg SplitPattern] -> m MatchResult
matchPats [NamedArg (Pattern' a)]
ps [NamedArg SplitPattern]
qs
matchPats [] qs :: [NamedArg SplitPattern]
qs@(NamedArg SplitPattern
_:[NamedArg SplitPattern]
_) = case forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe forall a. IsProjP a => a -> Maybe (ProjOrigin, AmbiguousQName)
isProjP [NamedArg SplitPattern]
qs of
[] -> forall (m :: * -> *) a. Monad m => a -> m (Match a)
yes forall a. Monoid a => a
mempty
[(ProjOrigin, AmbiguousQName)]
_ -> forall (m :: * -> *) a. Monad m => m (Match a)
no
matchPats (NamedArg (Pattern' a)
p:[NamedArg (Pattern' a)]
ps) [] = case forall a. IsProjP a => a -> Maybe (ProjOrigin, AmbiguousQName)
isProjP NamedArg (Pattern' a)
p of
Just{} -> forall (m :: * -> *) a. Monad m => m (Match a)
blockedOnProjection
Maybe (ProjOrigin, AmbiguousQName)
Nothing -> forall (m :: * -> *) a. Monad m => ApplyOrIApply -> m (Match a)
blockedOnApplication (case forall a. NamedArg a -> a
namedArg NamedArg (Pattern' a)
p of IApplyP{} -> ApplyOrIApply
IsIApply; Pattern' a
_ -> ApplyOrIApply
IsApply)
combine :: (Monad m, Semigroup a) => m (Match a) -> m (Match a) -> m (Match a)
combine :: forall (m :: * -> *) a.
(Monad m, Semigroup a) =>
m (Match a) -> m (Match a) -> m (Match a)
combine m (Match a)
m m (Match a)
m' = m (Match a)
m forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Yes a
a -> m (Match a)
m' forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Yes a
b -> forall (m :: * -> *) a. Monad m => a -> m (Match a)
yes (a
a forall a. Semigroup a => a -> a -> a
<> a
b)
Match a
y -> forall (m :: * -> *) a. Monad m => a -> m a
return Match a
y
Match a
No -> forall (m :: * -> *) a. Monad m => m (Match a)
no
x :: Match a
x@(Block BlockedOnResult
r BlockingVars
xs) -> m (Match a)
m' forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Match a
No -> forall (m :: * -> *) a. Monad m => m (Match a)
no
Block BlockedOnResult
s BlockingVars
ys -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. BlockedOnResult -> BlockingVars -> Match a
Block (BlockedOnResult -> BlockedOnResult -> BlockedOnResult
anyBlockedOnResult BlockedOnResult
r BlockedOnResult
s) (BlockingVars
xs forall a. [a] -> [a] -> [a]
++ BlockingVars
ys)
Yes{} -> forall (m :: * -> *) a. Monad m => a -> m a
return Match a
x
matchPat
:: (PureTCM m, DeBruijn a)
=> Pattern' a
-> SplitPattern
-> m MatchResult
matchPat :: forall (m :: * -> *) a.
(PureTCM m, DeBruijn a) =>
Pattern' a -> SplitPattern -> m MatchResult
matchPat Pattern' a
p SplitPattern
q = case Pattern' a
p of
VarP PatternInfo
_ a
x ->
forall (m :: * -> *) a. Monad m => a -> m (Match a)
yes forall a b. (a -> b) -> a -> b
$ forall el coll. Singleton el coll => el -> coll
singleton (forall a. a -> Maybe a -> a
fromMaybe forall a. HasCallStack => a
__IMPOSSIBLE__ (forall a. DeBruijn a => a -> Maybe Nat
deBruijnView a
x), SplitPattern
q)
DotP{} -> forall (m :: * -> *) a. Monad m => a -> m (Match a)
yes forall a. Monoid a => a
mempty
p :: Pattern' a
p@(LitP PatternInfo
_ Literal
l) -> case SplitPattern
q of
VarP PatternInfo
_ SplitPatVar
x -> if Literal
l forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` SplitPatVar -> [Literal]
splitExcludedLits SplitPatVar
x
then forall (m :: * -> *) a. Monad m => m (Match a)
no
else forall (m :: * -> *) a. Monad m => Nat -> Literal -> m (Match a)
blockedOnLiteral (SplitPatVar -> Nat
splitPatVarIndex SplitPatVar
x) Literal
l
SplitPattern
_ -> forall (m :: * -> *) a.
PureTCM m =>
Pattern' a -> m (Maybe Literal)
isLitP SplitPattern
q forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Just Literal
l' -> if Literal
l forall a. Eq a => a -> a -> Bool
== Literal
l' then forall (m :: * -> *) a. Monad m => a -> m (Match a)
yes forall a. Monoid a => a
mempty else forall (m :: * -> *) a. Monad m => m (Match a)
no
Maybe Literal
Nothing -> forall (m :: * -> *) a. Monad m => m (Match a)
no
ProjP ProjOrigin
_ QName
d -> case SplitPattern
q of
ProjP ProjOrigin
_ QName
d' -> do
QName
d <- forall (m :: * -> *). HasConstInfo m => QName -> m QName
getOriginalProjection QName
d
if QName
d forall a. Eq a => a -> a -> Bool
== QName
d' then forall (m :: * -> *) a. Monad m => a -> m (Match a)
yes forall a. Monoid a => a
mempty else forall (m :: * -> *) a. Monad m => m (Match a)
no
SplitPattern
_ -> forall a. HasCallStack => a
__IMPOSSIBLE__
IApplyP PatternInfo
_ Term
_ Term
_ a
x ->
forall (m :: * -> *) a. Monad m => a -> m (Match a)
yes forall a b. (a -> b) -> a -> b
$ forall el coll. Singleton el coll => el -> coll
singleton (forall a. a -> Maybe a -> a
fromMaybe forall a. HasCallStack => a
__IMPOSSIBLE__ (forall a. DeBruijn a => a -> Maybe Nat
deBruijnView a
x), SplitPattern
q)
ConP ConHead
c ConPatternInfo
ci [NamedArg (Pattern' a)]
ps -> forall (m :: * -> *) a.
(MonadReduce m, DeBruijn a) =>
Pattern' a -> m (Pattern' a)
unDotP SplitPattern
q forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
HasBuiltins m =>
Pattern' a -> m (Pattern' a)
unLitP forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
VarP PatternInfo
_ SplitPatVar
x -> forall (m :: * -> *) a.
Monad m =>
Nat -> ConHead -> ConPatternInfo -> m (Match a)
blockedOnConstructor (SplitPatVar -> Nat
splitPatVarIndex SplitPatVar
x) ConHead
c ConPatternInfo
ci
ConP ConHead
c' ConPatternInfo
i [NamedArg SplitPattern]
qs
| ConHead
c forall a. Eq a => a -> a -> Bool
== ConHead
c' -> forall (m :: * -> *) a.
(PureTCM m, DeBruijn a) =>
[NamedArg (Pattern' a)] -> [NamedArg SplitPattern] -> m MatchResult
matchPats [NamedArg (Pattern' a)]
ps [NamedArg SplitPattern]
qs
| Bool
otherwise -> forall (m :: * -> *) a. Monad m => m (Match a)
no
DotP PatternInfo
o Term
t -> forall (m :: * -> *) a. Monad m => m (Match a)
no
DefP{} -> forall (m :: * -> *) a. Monad m => m (Match a)
no
LitP{} -> forall a. HasCallStack => a
__IMPOSSIBLE__
ProjP{} -> forall a. HasCallStack => a
__IMPOSSIBLE__
IApplyP PatternInfo
_ Term
_ Term
_ SplitPatVar
x -> forall (m :: * -> *) a.
Monad m =>
Nat -> ConHead -> ConPatternInfo -> m (Match a)
blockedOnConstructor (SplitPatVar -> Nat
splitPatVarIndex SplitPatVar
x) ConHead
c ConPatternInfo
ci
DefP PatternInfo
o QName
c [NamedArg (Pattern' a)]
ps -> forall (m :: * -> *) a.
(MonadReduce m, DeBruijn a) =>
Pattern' a -> m (Pattern' a)
unDotP SplitPattern
q forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
VarP PatternInfo
_ SplitPatVar
x -> forall (m :: * -> *) a. Monad m => m (Match a)
no
ConP ConHead
c' ConPatternInfo
i [NamedArg SplitPattern]
qs -> forall (m :: * -> *) a. Monad m => m (Match a)
no
DotP PatternInfo
o Term
t -> forall (m :: * -> *) a. Monad m => m (Match a)
no
LitP{} -> forall (m :: * -> *) a. Monad m => m (Match a)
no
DefP PatternInfo
o QName
c' [NamedArg SplitPattern]
qs
| QName
c forall a. Eq a => a -> a -> Bool
== QName
c' -> forall (m :: * -> *) a.
(PureTCM m, DeBruijn a) =>
[NamedArg (Pattern' a)] -> [NamedArg SplitPattern] -> m MatchResult
matchPats [NamedArg (Pattern' a)]
ps [NamedArg SplitPattern]
qs
| Bool
otherwise -> forall (m :: * -> *) a. Monad m => m (Match a)
no
ProjP{} -> forall a. HasCallStack => a
__IMPOSSIBLE__
IApplyP PatternInfo
_ Term
_ Term
_ SplitPatVar
x -> forall a. HasCallStack => a
__IMPOSSIBLE__
unDotP :: (MonadReduce m, DeBruijn a) => Pattern' a -> m (Pattern' a)
unDotP :: forall (m :: * -> *) a.
(MonadReduce m, DeBruijn a) =>
Pattern' a -> m (Pattern' a)
unDotP (DotP PatternInfo
o Term
v) = forall a (m :: * -> *). (Reduce a, MonadReduce m) => a -> m a
reduce Term
v forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Var Nat
i [] -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. DeBruijn a => Nat -> a
deBruijnVar Nat
i
Con ConHead
c ConInfo
_ [Elim]
vs -> do
let ps :: [Arg (Named NamedName (Pattern' a))]
ps = forall a b. (a -> b) -> [a] -> [b]
map (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (a -> b) -> a -> b
$ forall a name. a -> Named name a
unnamed forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall x. PatternInfo -> Term -> Pattern' x
DotP PatternInfo
o) forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a -> a
fromMaybe forall a. HasCallStack => a
__IMPOSSIBLE__ forall a b. (a -> b) -> a -> b
$ forall a. [Elim' a] -> Maybe [Arg a]
allApplyElims [Elim]
vs
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall x.
ConHead -> ConPatternInfo -> [NamedArg (Pattern' x)] -> Pattern' x
ConP ConHead
c ConPatternInfo
noConPatternInfo [Arg (Named NamedName (Pattern' a))]
ps
Lit Literal
l -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall x. PatternInfo -> Literal -> Pattern' x
LitP (PatOrigin -> [Name] -> PatternInfo
PatternInfo PatOrigin
PatODot []) Literal
l
Term
v -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. Term -> Pattern' a
dotP Term
v
unDotP Pattern' a
p = forall (m :: * -> *) a. Monad m => a -> m a
return Pattern' a
p
isLitP :: PureTCM m => Pattern' a -> m (Maybe Literal)
isLitP :: forall (m :: * -> *) a.
PureTCM m =>
Pattern' a -> m (Maybe Literal)
isLitP (LitP PatternInfo
_ Literal
l) = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a
Just Literal
l
isLitP (DotP PatternInfo
_ Term
u) = forall a (m :: * -> *). (Reduce a, MonadReduce m) => a -> m a
reduce Term
u forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Lit Literal
l -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a
Just Literal
l
Term
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. Maybe a
Nothing
isLitP (ConP ConHead
c ConPatternInfo
ci []) = do
Con ConHead
zero ConInfo
_ [] <- forall a. a -> Maybe a -> a
fromMaybe forall a. HasCallStack => a
__IMPOSSIBLE__ forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). HasBuiltins m => String -> m (Maybe Term)
getBuiltin' String
builtinZero
if ConHead
c forall a. Eq a => a -> a -> Bool
== ConHead
zero
then forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Integer -> Literal
LitNat Integer
0
else forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing
isLitP (ConP ConHead
c ConPatternInfo
ci [NamedArg (Pattern' a)
a]) | forall a. LensHiding a => a -> Bool
visible NamedArg (Pattern' a)
a Bool -> Bool -> Bool
&& forall a. LensRelevance a => a -> Bool
isRelevant NamedArg (Pattern' a)
a = do
Con ConHead
suc ConInfo
_ [] <- forall a. a -> Maybe a -> a
fromMaybe forall a. HasCallStack => a
__IMPOSSIBLE__ forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). HasBuiltins m => String -> m (Maybe Term)
getBuiltin' String
builtinSuc
if ConHead
c forall a. Eq a => a -> a -> Bool
== ConHead
suc
then forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Literal -> Literal
inc forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a.
PureTCM m =>
Pattern' a -> m (Maybe Literal)
isLitP (forall a. NamedArg a -> a
namedArg NamedArg (Pattern' a)
a)
else forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing
where
inc :: Literal -> Literal
inc :: Literal -> Literal
inc (LitNat Integer
n) = Integer -> Literal
LitNat forall a b. (a -> b) -> a -> b
$ Integer
n forall a. Num a => a -> a -> a
+ Integer
1
inc Literal
_ = forall a. HasCallStack => a
__IMPOSSIBLE__
isLitP Pattern' a
_ = forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing
unLitP :: HasBuiltins m => Pattern' a -> m (Pattern' a)
unLitP :: forall (m :: * -> *) a.
HasBuiltins m =>
Pattern' a -> m (Pattern' a)
unLitP (LitP PatternInfo
info l :: Literal
l@(LitNat Integer
n)) | Integer
n forall a. Ord a => a -> a -> Bool
>= Integer
0 = do
Con ConHead
c ConInfo
ci [Elim]
es <- forall (m :: * -> *).
Applicative m =>
m Term -> m Term -> Term -> m Term
constructorForm' (forall a. a -> Maybe a -> a
fromMaybe forall a. HasCallStack => a
__IMPOSSIBLE__ forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). HasBuiltins m => String -> m (Maybe Term)
getBuiltin' String
builtinZero)
(forall a. a -> Maybe a -> a
fromMaybe forall a. HasCallStack => a
__IMPOSSIBLE__ forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). HasBuiltins m => String -> m (Maybe Term)
getBuiltin' String
builtinSuc)
(Literal -> Term
Lit Literal
l)
let toP :: Elim -> Arg (Pattern' a)
toP (Apply (Arg ArgInfo
i (Lit Literal
l))) = forall e. ArgInfo -> e -> Arg e
Arg ArgInfo
i (forall x. PatternInfo -> Literal -> Pattern' x
LitP PatternInfo
info Literal
l)
toP Elim
_ = forall a. HasCallStack => a
__IMPOSSIBLE__
cpi :: ConPatternInfo
cpi = ConPatternInfo
noConPatternInfo { conPInfo :: PatternInfo
conPInfo = PatternInfo
info }
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall x.
ConHead -> ConPatternInfo -> [NamedArg (Pattern' x)] -> Pattern' x
ConP ConHead
c ConPatternInfo
cpi forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a name. a -> Named name a
unnamed forall b c a. (b -> c) -> (a -> b) -> a -> c
. Elim -> Arg (Pattern' a)
toP) [Elim]
es
unLitP Pattern' a
p = forall (m :: * -> *) a. Monad m => a -> m a
return Pattern' a
p