module Agda.Syntax.Internal.Elim where
import Control.DeepSeq
import Agda.Syntax.Common
import Agda.Syntax.Concrete.Pretty ()
import Agda.Syntax.Position
import Agda.Syntax.Abstract.Name
import Agda.Utils.Pretty
import Agda.Utils.Empty
import Agda.Utils.Maybe
import Agda.Utils.Tuple
data Elim' a
= Apply (Arg a)
| Proj ProjOrigin QName
| IApply a a a
deriving (Int -> Elim' a -> ShowS
forall a. Show a => Int -> Elim' a -> ShowS
forall a. Show a => [Elim' a] -> ShowS
forall a. Show a => Elim' a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Elim' a] -> ShowS
$cshowList :: forall a. Show a => [Elim' a] -> ShowS
show :: Elim' a -> String
$cshow :: forall a. Show a => Elim' a -> String
showsPrec :: Int -> Elim' a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> Elim' a -> ShowS
Show, forall a b. a -> Elim' b -> Elim' a
forall a b. (a -> b) -> Elim' a -> Elim' 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 -> Elim' b -> Elim' a
$c<$ :: forall a b. a -> Elim' b -> Elim' a
fmap :: forall a b. (a -> b) -> Elim' a -> Elim' b
$cfmap :: forall a b. (a -> b) -> Elim' a -> Elim' b
Functor, forall a. Eq a => a -> Elim' a -> Bool
forall a. Num a => Elim' a -> a
forall a. Ord a => Elim' a -> a
forall m. Monoid m => Elim' m -> m
forall a. Elim' a -> Bool
forall a. Elim' a -> Int
forall a. Elim' a -> [a]
forall a. (a -> a -> a) -> Elim' a -> a
forall m a. Monoid m => (a -> m) -> Elim' a -> m
forall b a. (b -> a -> b) -> b -> Elim' a -> b
forall a b. (a -> b -> b) -> b -> Elim' a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: forall a. Num a => Elim' a -> a
$cproduct :: forall a. Num a => Elim' a -> a
sum :: forall a. Num a => Elim' a -> a
$csum :: forall a. Num a => Elim' a -> a
minimum :: forall a. Ord a => Elim' a -> a
$cminimum :: forall a. Ord a => Elim' a -> a
maximum :: forall a. Ord a => Elim' a -> a
$cmaximum :: forall a. Ord a => Elim' a -> a
elem :: forall a. Eq a => a -> Elim' a -> Bool
$celem :: forall a. Eq a => a -> Elim' a -> Bool
length :: forall a. Elim' a -> Int
$clength :: forall a. Elim' a -> Int
null :: forall a. Elim' a -> Bool
$cnull :: forall a. Elim' a -> Bool
toList :: forall a. Elim' a -> [a]
$ctoList :: forall a. Elim' a -> [a]
foldl1 :: forall a. (a -> a -> a) -> Elim' a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Elim' a -> a
foldr1 :: forall a. (a -> a -> a) -> Elim' a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> Elim' a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> Elim' a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Elim' a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Elim' a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Elim' a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Elim' a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Elim' a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Elim' a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> Elim' a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> Elim' a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Elim' a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Elim' a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Elim' a -> m
fold :: forall m. Monoid m => Elim' m -> m
$cfold :: forall m. Monoid m => Elim' m -> m
Foldable, Functor Elim'
Foldable Elim'
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => Elim' (m a) -> m (Elim' a)
forall (f :: * -> *) a. Applicative f => Elim' (f a) -> f (Elim' a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Elim' a -> m (Elim' b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Elim' a -> f (Elim' b)
sequence :: forall (m :: * -> *) a. Monad m => Elim' (m a) -> m (Elim' a)
$csequence :: forall (m :: * -> *) a. Monad m => Elim' (m a) -> m (Elim' a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Elim' a -> m (Elim' b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Elim' a -> m (Elim' b)
sequenceA :: forall (f :: * -> *) a. Applicative f => Elim' (f a) -> f (Elim' a)
$csequenceA :: forall (f :: * -> *) a. Applicative f => Elim' (f a) -> f (Elim' a)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Elim' a -> f (Elim' b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Elim' a -> f (Elim' b)
Traversable)
instance LensOrigin (Elim' a) where
getOrigin :: Elim' a -> Origin
getOrigin (Apply Arg a
a) = forall a. LensOrigin a => a -> Origin
getOrigin Arg a
a
getOrigin Proj{} = Origin
UserWritten
getOrigin IApply{} = Origin
UserWritten
mapOrigin :: (Origin -> Origin) -> Elim' a -> Elim' a
mapOrigin Origin -> Origin
f (Apply Arg a
a) = forall a. Arg a -> Elim' a
Apply forall a b. (a -> b) -> a -> b
$ forall a. LensOrigin a => (Origin -> Origin) -> a -> a
mapOrigin Origin -> Origin
f Arg a
a
mapOrigin Origin -> Origin
f e :: Elim' a
e@Proj{} = Elim' a
e
mapOrigin Origin -> Origin
f e :: Elim' a
e@IApply{} = Elim' a
e
isApplyElim :: Elim' a -> Maybe (Arg a)
isApplyElim :: forall a. Elim' a -> Maybe (Arg a)
isApplyElim (Apply Arg a
u) = forall a. a -> Maybe a
Just Arg a
u
isApplyElim Proj{} = forall a. Maybe a
Nothing
isApplyElim (IApply a
_ a
_ a
r) = forall a. a -> Maybe a
Just (forall a. a -> Arg a
defaultArg a
r)
isApplyElim' :: Empty -> Elim' a -> Arg a
isApplyElim' :: forall a. Empty -> Elim' a -> Arg a
isApplyElim' Empty
e = forall a. a -> Maybe a -> a
fromMaybe (forall a. Empty -> a
absurd Empty
e) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Elim' a -> Maybe (Arg a)
isApplyElim
isProperApplyElim :: Elim' a -> Bool
isProperApplyElim :: forall a. Elim' a -> Bool
isProperApplyElim = \case
Apply Arg a
_ -> Bool
True
IApply{} -> Bool
False
Proj{} -> Bool
False
allApplyElims :: [Elim' a] -> Maybe [Arg a]
allApplyElims :: forall a. [Elim' a] -> Maybe [Arg a]
allApplyElims = forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM forall a. Elim' a -> Maybe (Arg a)
isApplyElim
splitApplyElims :: [Elim' a] -> ([Arg a], [Elim' a])
splitApplyElims :: forall a. [Elim' a] -> ([Arg a], [Elim' a])
splitApplyElims (Apply Arg a
u : [Elim' a]
es) = forall a c b. (a -> c) -> (a, b) -> (c, b)
mapFst (Arg a
u forall a. a -> [a] -> [a]
:) forall a b. (a -> b) -> a -> b
$ forall a. [Elim' a] -> ([Arg a], [Elim' a])
splitApplyElims [Elim' a]
es
splitApplyElims [Elim' a]
es = ([], [Elim' a]
es)
class IsProjElim e where
isProjElim :: e -> Maybe (ProjOrigin, QName)
instance IsProjElim (Elim' a) where
isProjElim :: Elim' a -> Maybe (ProjOrigin, QName)
isProjElim (Proj ProjOrigin
o QName
d) = forall a. a -> Maybe a
Just (ProjOrigin
o, QName
d)
isProjElim Apply{} = forall a. Maybe a
Nothing
isProjElim IApply{} = forall a. Maybe a
Nothing
argsFromElims :: [Elim' t] -> [Arg t]
argsFromElims :: forall t. [Elim' t] -> [Arg t]
argsFromElims = forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe forall a. Elim' a -> Maybe (Arg a)
isApplyElim
allProjElims :: [Elim' t] -> Maybe [(ProjOrigin, QName)]
allProjElims :: forall t. [Elim' t] -> Maybe [(ProjOrigin, QName)]
allProjElims = forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM forall e. IsProjElim e => e -> Maybe (ProjOrigin, QName)
isProjElim
instance KillRange a => KillRange (Elim' a) where
killRange :: KillRangeT (Elim' a)
killRange = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. KillRange a => KillRangeT a
killRange
instance Pretty tm => Pretty (Elim' tm) where
prettyPrec :: Int -> Elim' tm -> Doc
prettyPrec Int
p (Apply Arg tm
v) = forall a. Pretty a => Int -> a -> Doc
prettyPrec Int
p Arg tm
v
prettyPrec Int
_ (Proj ProjOrigin
_o QName
x) = String -> Doc
text (String
"." forall a. [a] -> [a] -> [a]
++ forall a. Pretty a => a -> String
prettyShow QName
x)
prettyPrec Int
p (IApply tm
x tm
y tm
r) = forall a. Pretty a => Int -> a -> Doc
prettyPrec Int
p tm
r
instance NFData a => NFData (Elim' a) where
rnf :: Elim' a -> ()
rnf (Apply Arg a
x) = forall a. NFData a => a -> ()
rnf Arg a
x
rnf Proj{} = ()
rnf (IApply a
x a
y a
r) = forall a. NFData a => a -> ()
rnf a
x seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf a
y seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf a
r