module Agda.TypeChecking.Monad.Builtin
  ( module Agda.TypeChecking.Monad.Builtin
  , module Agda.Syntax.Builtin  -- The names are defined here.
  ) where

import qualified Control.Monad.Fail as Fail

import Control.Monad.Reader
import Control.Monad.State
import Control.Monad.Trans.Maybe
import Control.Monad.Writer

import qualified Data.Map as Map
import Data.Function ( on )

import Agda.Syntax.Common
import Agda.Syntax.Position
import Agda.Syntax.Literal
import Agda.Syntax.Builtin
import Agda.Syntax.Internal as I
import Agda.TypeChecking.Monad.Base
-- import Agda.TypeChecking.Functions  -- LEADS TO IMPORT CYCLE
import Agda.TypeChecking.Substitute

import Agda.Utils.Except
import Agda.Utils.ListT
import Agda.Utils.Monad
import Agda.Utils.Maybe
import Agda.Utils.Tuple

import Agda.Utils.Impossible

class ( Functor m
      , Applicative m
      , Fail.MonadFail m
      ) => HasBuiltins m where
  getBuiltinThing :: String -> m (Maybe (Builtin PrimFun))

instance HasBuiltins m => HasBuiltins (MaybeT m) where
  getBuiltinThing :: String -> MaybeT m (Maybe (Builtin PrimFun))
getBuiltinThing String
b = m (Maybe (Builtin PrimFun)) -> MaybeT m (Maybe (Builtin PrimFun))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Maybe (Builtin PrimFun)) -> MaybeT m (Maybe (Builtin PrimFun)))
-> m (Maybe (Builtin PrimFun))
-> MaybeT m (Maybe (Builtin PrimFun))
forall a b. (a -> b) -> a -> b
$ String -> m (Maybe (Builtin PrimFun))
forall (m :: * -> *).
HasBuiltins m =>
String -> m (Maybe (Builtin PrimFun))
getBuiltinThing String
b

instance HasBuiltins m => HasBuiltins (ExceptT e m) where
  getBuiltinThing :: String -> ExceptT e m (Maybe (Builtin PrimFun))
getBuiltinThing String
b = m (Maybe (Builtin PrimFun))
-> ExceptT e m (Maybe (Builtin PrimFun))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Maybe (Builtin PrimFun))
 -> ExceptT e m (Maybe (Builtin PrimFun)))
-> m (Maybe (Builtin PrimFun))
-> ExceptT e m (Maybe (Builtin PrimFun))
forall a b. (a -> b) -> a -> b
$ String -> m (Maybe (Builtin PrimFun))
forall (m :: * -> *).
HasBuiltins m =>
String -> m (Maybe (Builtin PrimFun))
getBuiltinThing String
b

instance HasBuiltins m => HasBuiltins (ListT m) where
  getBuiltinThing :: String -> ListT m (Maybe (Builtin PrimFun))
getBuiltinThing String
b = m (Maybe (Builtin PrimFun)) -> ListT m (Maybe (Builtin PrimFun))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Maybe (Builtin PrimFun)) -> ListT m (Maybe (Builtin PrimFun)))
-> m (Maybe (Builtin PrimFun)) -> ListT m (Maybe (Builtin PrimFun))
forall a b. (a -> b) -> a -> b
$ String -> m (Maybe (Builtin PrimFun))
forall (m :: * -> *).
HasBuiltins m =>
String -> m (Maybe (Builtin PrimFun))
getBuiltinThing String
b

instance HasBuiltins m => HasBuiltins (ReaderT e m) where
  getBuiltinThing :: String -> ReaderT e m (Maybe (Builtin PrimFun))
getBuiltinThing String
b = m (Maybe (Builtin PrimFun))
-> ReaderT e m (Maybe (Builtin PrimFun))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Maybe (Builtin PrimFun))
 -> ReaderT e m (Maybe (Builtin PrimFun)))
-> m (Maybe (Builtin PrimFun))
-> ReaderT e m (Maybe (Builtin PrimFun))
forall a b. (a -> b) -> a -> b
$ String -> m (Maybe (Builtin PrimFun))
forall (m :: * -> *).
HasBuiltins m =>
String -> m (Maybe (Builtin PrimFun))
getBuiltinThing String
b

instance HasBuiltins m => HasBuiltins (StateT s m) where
  getBuiltinThing :: String -> StateT s m (Maybe (Builtin PrimFun))
getBuiltinThing String
b = m (Maybe (Builtin PrimFun)) -> StateT s m (Maybe (Builtin PrimFun))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Maybe (Builtin PrimFun))
 -> StateT s m (Maybe (Builtin PrimFun)))
-> m (Maybe (Builtin PrimFun))
-> StateT s m (Maybe (Builtin PrimFun))
forall a b. (a -> b) -> a -> b
$ String -> m (Maybe (Builtin PrimFun))
forall (m :: * -> *).
HasBuiltins m =>
String -> m (Maybe (Builtin PrimFun))
getBuiltinThing String
b

instance (HasBuiltins m, Monoid w) => HasBuiltins (WriterT w m) where
  getBuiltinThing :: String -> WriterT w m (Maybe (Builtin PrimFun))
getBuiltinThing String
b = m (Maybe (Builtin PrimFun))
-> WriterT w m (Maybe (Builtin PrimFun))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Maybe (Builtin PrimFun))
 -> WriterT w m (Maybe (Builtin PrimFun)))
-> m (Maybe (Builtin PrimFun))
-> WriterT w m (Maybe (Builtin PrimFun))
forall a b. (a -> b) -> a -> b
$ String -> m (Maybe (Builtin PrimFun))
forall (m :: * -> *).
HasBuiltins m =>
String -> m (Maybe (Builtin PrimFun))
getBuiltinThing String
b

-- If Agda is changed so that the type of a literal can belong to an
-- inductive family (with at least one index), then the implementation
-- of split' in Agda.TypeChecking.Coverage should be changed.

litType
  :: (HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m)
  => Literal -> m Type
litType :: Literal -> m Type
litType Literal
l = case Literal
l of
  LitNat Range
_ Integer
n    -> do
    Term
_ <- m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primZero
    Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Integer
n Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
> Integer
0) (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$ m Term -> m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (m Term -> m ()) -> m Term -> m ()
forall a b. (a -> b) -> a -> b
$ m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primSuc
    Term -> Type
forall a. a -> Type'' Term a
el (Term -> Type) -> m Term -> m Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primNat
  LitWord64 Range
_ Word64
_ -> Term -> Type
forall a. a -> Type'' Term a
el (Term -> Type) -> m Term -> m Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primWord64
  LitFloat Range
_ Double
_  -> Term -> Type
forall a. a -> Type'' Term a
el (Term -> Type) -> m Term -> m Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primFloat
  LitChar Range
_ Char
_   -> Term -> Type
forall a. a -> Type'' Term a
el (Term -> Type) -> m Term -> m Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primChar
  LitString Range
_ String
_ -> Term -> Type
forall a. a -> Type'' Term a
el (Term -> Type) -> m Term -> m Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primString
  LitQName Range
_ QName
_  -> Term -> Type
forall a. a -> Type'' Term a
el (Term -> Type) -> m Term -> m Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primQName
  LitMeta Range
_ AbsolutePath
_ MetaId
_ -> Term -> Type
forall a. a -> Type'' Term a
el (Term -> Type) -> m Term -> m Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primAgdaMeta
  where
    el :: a -> Type'' Term a
el a
t = Sort' Term -> a -> Type'' Term a
forall t a. Sort' t -> a -> Type'' t a
El (Integer -> Sort' Term
mkType Integer
0) a
t

instance MonadIO m => HasBuiltins (TCMT m) where
  getBuiltinThing :: String -> TCMT m (Maybe (Builtin PrimFun))
getBuiltinThing String
b = (Maybe (Builtin PrimFun)
 -> Maybe (Builtin PrimFun) -> Maybe (Builtin PrimFun))
-> TCMT m (Maybe (Builtin PrimFun))
-> TCMT m (Maybe (Builtin PrimFun))
-> TCMT m (Maybe (Builtin PrimFun))
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 Maybe (Builtin PrimFun)
-> Maybe (Builtin PrimFun) -> Maybe (Builtin PrimFun)
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
mplus (String -> Map String (Builtin PrimFun) -> Maybe (Builtin PrimFun)
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup String
b (Map String (Builtin PrimFun) -> Maybe (Builtin PrimFun))
-> TCMT m (Map String (Builtin PrimFun))
-> TCMT m (Maybe (Builtin PrimFun))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Lens' (Map String (Builtin PrimFun)) TCState
-> TCMT m (Map String (Builtin PrimFun))
forall (m :: * -> *) a. ReadTCState m => Lens' a TCState -> m a
useTC Lens' (Map String (Builtin PrimFun)) TCState
stLocalBuiltins)
                      (String -> Map String (Builtin PrimFun) -> Maybe (Builtin PrimFun)
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup String
b (Map String (Builtin PrimFun) -> Maybe (Builtin PrimFun))
-> TCMT m (Map String (Builtin PrimFun))
-> TCMT m (Maybe (Builtin PrimFun))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Lens' (Map String (Builtin PrimFun)) TCState
-> TCMT m (Map String (Builtin PrimFun))
forall (m :: * -> *) a. ReadTCState m => Lens' a TCState -> m a
useTC Lens' (Map String (Builtin PrimFun)) TCState
stImportedBuiltins)

setBuiltinThings :: BuiltinThings PrimFun -> TCM ()
setBuiltinThings :: Map String (Builtin PrimFun) -> TCM ()
setBuiltinThings Map String (Builtin PrimFun)
b = Lens' (Map String (Builtin PrimFun)) TCState
stLocalBuiltins Lens' (Map String (Builtin PrimFun)) TCState
-> Map String (Builtin PrimFun) -> TCM ()
forall (m :: * -> *) a.
MonadTCState m =>
Lens' a TCState -> a -> m ()
`setTCLens` Map String (Builtin PrimFun)
b

bindBuiltinName :: String -> Term -> TCM ()
bindBuiltinName :: String -> Term -> TCM ()
bindBuiltinName String
b Term
x = do
  Maybe (Builtin PrimFun)
builtin <- String -> TCMT IO (Maybe (Builtin PrimFun))
forall (m :: * -> *).
HasBuiltins m =>
String -> m (Maybe (Builtin PrimFun))
getBuiltinThing String
b
  case Maybe (Builtin PrimFun)
builtin of
    Just (Builtin Term
y) -> TypeError -> TCM ()
forall (m :: * -> *) a.
(MonadTCEnv m, ReadTCState m, MonadError TCErr m) =>
TypeError -> m a
typeError (TypeError -> TCM ()) -> TypeError -> TCM ()
forall a b. (a -> b) -> a -> b
$ String -> Term -> Term -> TypeError
DuplicateBuiltinBinding String
b Term
y Term
x
    Just (Prim PrimFun
_)    -> TypeError -> TCM ()
forall (m :: * -> *) a.
(MonadTCEnv m, ReadTCState m, MonadError TCErr m) =>
TypeError -> m a
typeError (TypeError -> TCM ()) -> TypeError -> TCM ()
forall a b. (a -> b) -> a -> b
$ String -> TypeError
NoSuchBuiltinName String
b
    Maybe (Builtin PrimFun)
Nothing          -> Lens' (Map String (Builtin PrimFun)) TCState
stLocalBuiltins Lens' (Map String (Builtin PrimFun)) TCState
-> (Map String (Builtin PrimFun) -> Map String (Builtin PrimFun))
-> TCM ()
forall (m :: * -> *) a.
MonadTCState m =>
Lens' a TCState -> (a -> a) -> m ()
`modifyTCLens` String
-> Builtin PrimFun
-> Map String (Builtin PrimFun)
-> Map String (Builtin PrimFun)
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert String
b (Term -> Builtin PrimFun
forall pf. Term -> Builtin pf
Builtin Term
x)

bindPrimitive :: String -> PrimFun -> TCM ()
bindPrimitive :: String -> PrimFun -> TCM ()
bindPrimitive String
b PrimFun
pf = do
  Maybe (Builtin PrimFun)
builtin <- String -> TCMT IO (Maybe (Builtin PrimFun))
forall (m :: * -> *).
HasBuiltins m =>
String -> m (Maybe (Builtin PrimFun))
getBuiltinThing String
b
  case Maybe (Builtin PrimFun)
builtin of
    Just (Builtin Term
_) -> TypeError -> TCM ()
forall (m :: * -> *) a.
(MonadTCEnv m, ReadTCState m, MonadError TCErr m) =>
TypeError -> m a
typeError (TypeError -> TCM ()) -> TypeError -> TCM ()
forall a b. (a -> b) -> a -> b
$ String -> TypeError
NoSuchPrimitiveFunction String
b
    Just (Prim PrimFun
x)    -> TypeError -> TCM ()
forall (m :: * -> *) a.
(MonadTCEnv m, ReadTCState m, MonadError TCErr m) =>
TypeError -> m a
typeError (TypeError -> TCM ()) -> TypeError -> TCM ()
forall a b. (a -> b) -> a -> b
$ (String -> QName -> QName -> TypeError
DuplicatePrimitiveBinding String
b (QName -> QName -> TypeError)
-> (PrimFun -> QName) -> PrimFun -> PrimFun -> TypeError
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` PrimFun -> QName
primFunName) PrimFun
x PrimFun
pf
    Maybe (Builtin PrimFun)
Nothing          -> Lens' (Map String (Builtin PrimFun)) TCState
stLocalBuiltins Lens' (Map String (Builtin PrimFun)) TCState
-> (Map String (Builtin PrimFun) -> Map String (Builtin PrimFun))
-> TCM ()
forall (m :: * -> *) a.
MonadTCState m =>
Lens' a TCState -> (a -> a) -> m ()
`modifyTCLens` String
-> Builtin PrimFun
-> Map String (Builtin PrimFun)
-> Map String (Builtin PrimFun)
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert String
b (PrimFun -> Builtin PrimFun
forall pf. pf -> Builtin pf
Prim PrimFun
pf)

getBuiltin :: (HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m)
           => String -> m Term
getBuiltin :: String -> m Term
getBuiltin String
x =
  m Term -> m (Maybe Term) -> m Term
forall (m :: * -> *) a. Monad m => m a -> m (Maybe a) -> m a
fromMaybeM (TypeError -> m Term
forall (m :: * -> *) a.
(MonadTCEnv m, ReadTCState m, MonadError TCErr m) =>
TypeError -> m a
typeError (TypeError -> m Term) -> TypeError -> m Term
forall a b. (a -> b) -> a -> b
$ String -> TypeError
NoBindingForBuiltin String
x) (m (Maybe Term) -> m Term) -> m (Maybe Term) -> m Term
forall a b. (a -> b) -> a -> b
$ String -> m (Maybe Term)
forall (m :: * -> *). HasBuiltins m => String -> m (Maybe Term)
getBuiltin' String
x

getBuiltin' :: HasBuiltins m => String -> m (Maybe Term)
getBuiltin' :: String -> m (Maybe Term)
getBuiltin' String
x = do
    Maybe (Builtin PrimFun)
builtin <- String -> m (Maybe (Builtin PrimFun))
forall (m :: * -> *).
HasBuiltins m =>
String -> m (Maybe (Builtin PrimFun))
getBuiltinThing String
x
    case Maybe (Builtin PrimFun)
builtin of
        Just (Builtin Term
t) -> Maybe Term -> m (Maybe Term)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Term -> m (Maybe Term)) -> Maybe Term -> m (Maybe Term)
forall a b. (a -> b) -> a -> b
$ Term -> Maybe Term
forall a. a -> Maybe a
Just (Term -> Maybe Term) -> Term -> Maybe Term
forall a b. (a -> b) -> a -> b
$ KillRangeT Term
forall a. KillRange a => KillRangeT a
killRange Term
t
        Maybe (Builtin PrimFun)
_                -> Maybe Term -> m (Maybe Term)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Term
forall a. Maybe a
Nothing

getPrimitive' :: HasBuiltins m => String -> m (Maybe PrimFun)
getPrimitive' :: String -> m (Maybe PrimFun)
getPrimitive' String
x = (Builtin PrimFun -> Maybe PrimFun
forall a. Builtin a -> Maybe a
getPrim (Builtin PrimFun -> Maybe PrimFun)
-> Maybe (Builtin PrimFun) -> Maybe PrimFun
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<) (Maybe (Builtin PrimFun) -> Maybe PrimFun)
-> m (Maybe (Builtin PrimFun)) -> m (Maybe PrimFun)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> m (Maybe (Builtin PrimFun))
forall (m :: * -> *).
HasBuiltins m =>
String -> m (Maybe (Builtin PrimFun))
getBuiltinThing String
x
  where
    getPrim :: Builtin a -> Maybe a
getPrim (Prim a
pf) = a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return a
pf
    getPrim Builtin a
_         = Maybe a
forall a. Maybe a
Nothing

getPrimitive :: (HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m)
             => String -> m PrimFun
getPrimitive :: String -> m PrimFun
getPrimitive String
x =
  m PrimFun -> m (Maybe PrimFun) -> m PrimFun
forall (m :: * -> *) a. Monad m => m a -> m (Maybe a) -> m a
fromMaybeM (TypeError -> m PrimFun
forall (m :: * -> *) a.
(MonadTCEnv m, ReadTCState m, MonadError TCErr m) =>
TypeError -> m a
typeError (TypeError -> m PrimFun) -> TypeError -> m PrimFun
forall a b. (a -> b) -> a -> b
$ String -> TypeError
NoSuchPrimitiveFunction String
x) (m (Maybe PrimFun) -> m PrimFun) -> m (Maybe PrimFun) -> m PrimFun
forall a b. (a -> b) -> a -> b
$ String -> m (Maybe PrimFun)
forall (m :: * -> *). HasBuiltins m => String -> m (Maybe PrimFun)
getPrimitive' String
x

getPrimitiveTerm :: (HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m)
                 => String -> m Term
getPrimitiveTerm :: String -> m Term
getPrimitiveTerm String
x = (QName -> Elims -> Term
`Def` []) (QName -> Term) -> (PrimFun -> QName) -> PrimFun -> Term
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PrimFun -> QName
primFunName (PrimFun -> Term) -> m PrimFun -> m Term
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> m PrimFun
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m PrimFun
getPrimitive String
x

getPrimitiveTerm' :: HasBuiltins m => String -> m (Maybe Term)
getPrimitiveTerm' :: String -> m (Maybe Term)
getPrimitiveTerm' String
x = (QName -> Term) -> Maybe QName -> Maybe Term
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (QName -> Elims -> Term
`Def` []) (Maybe QName -> Maybe Term) -> m (Maybe QName) -> m (Maybe Term)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> m (Maybe QName)
forall (m :: * -> *). HasBuiltins m => String -> m (Maybe QName)
getPrimitiveName' String
x

getTerm' :: HasBuiltins m => String -> m (Maybe Term)
getTerm' :: String -> m (Maybe Term)
getTerm' String
x = Maybe Term -> Maybe Term -> Maybe Term
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
mplus (Maybe Term -> Maybe Term -> Maybe Term)
-> m (Maybe Term) -> m (Maybe Term -> Maybe Term)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> m (Maybe Term)
forall (m :: * -> *). HasBuiltins m => String -> m (Maybe Term)
getBuiltin' String
x m (Maybe Term -> Maybe Term) -> m (Maybe Term) -> m (Maybe Term)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> m (Maybe Term)
forall (m :: * -> *). HasBuiltins m => String -> m (Maybe Term)
getPrimitiveTerm' String
x

getName' :: HasBuiltins m => String -> m (Maybe QName)
getName' :: String -> m (Maybe QName)
getName' String
x = Maybe QName -> Maybe QName -> Maybe QName
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
mplus (Maybe QName -> Maybe QName -> Maybe QName)
-> m (Maybe QName) -> m (Maybe QName -> Maybe QName)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> m (Maybe QName)
forall (m :: * -> *). HasBuiltins m => String -> m (Maybe QName)
getBuiltinName' String
x m (Maybe QName -> Maybe QName)
-> m (Maybe QName) -> m (Maybe QName)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> m (Maybe QName)
forall (m :: * -> *). HasBuiltins m => String -> m (Maybe QName)
getPrimitiveName' String
x

-- | @getTerm use name@ looks up @name@ as a primitive or builtin, and
-- throws an error otherwise.
-- The @use@ argument describes how the name is used for the sake of
-- the error message.
getTerm :: (HasBuiltins m) => String -> String -> m Term
getTerm :: String -> String -> m Term
getTerm String
use String
name = (m Term -> m (Maybe Term) -> m Term)
-> m (Maybe Term) -> m Term -> m Term
forall a b c. (a -> b -> c) -> b -> a -> c
flip m Term -> m (Maybe Term) -> m Term
forall (m :: * -> *) a. Monad m => m a -> m (Maybe a) -> m a
fromMaybeM (String -> m (Maybe Term)
forall (m :: * -> *). HasBuiltins m => String -> m (Maybe Term)
getTerm' String
name) (m Term -> m Term) -> m Term -> m Term
forall a b. (a -> b) -> a -> b
$
  Term -> m Term
forall (m :: * -> *) a. Monad m => a -> m a
return (Term -> m Term) -> Term -> m Term
forall a b. (a -> b) -> a -> b
$! (Impossible -> Term
forall a. Impossible -> a
throwImpossible (Impossible -> Term) -> Impossible -> Term
forall a b. (a -> b) -> a -> b
$ [String] -> String -> Impossible
ImpMissingDefinitions [String
name] String
use)


-- | Rewrite a literal to constructor form if possible.
constructorForm :: (HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m)
                => Term -> m Term
constructorForm :: Term -> m Term
constructorForm Term
v = m Term -> m Term -> Term -> m Term
forall (m :: * -> *).
Applicative m =>
m Term -> m Term -> Term -> m Term
constructorForm' m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primZero m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primSuc Term
v

constructorForm' :: Applicative m => m Term -> m Term -> Term -> m Term
constructorForm' :: m Term -> m Term -> Term -> m Term
constructorForm' m Term
pZero m Term
pSuc Term
v =
  case Term
v of
    Lit (LitNat Range
r Integer
n)
      | Integer
n Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== Integer
0    -> m Term
pZero
      | Integer
n Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
> Integer
0     -> (Term -> KillRangeT Term
forall t. Apply t => t -> Term -> t
`apply1` Literal -> Term
Lit (Range -> Integer -> Literal
LitNat Range
r (Integer -> Literal) -> Integer -> Literal
forall a b. (a -> b) -> a -> b
$ Integer
n Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
- Integer
1)) KillRangeT Term -> m Term -> m Term
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Term
pSuc
      | Bool
otherwise -> Term -> m Term
forall (f :: * -> *) a. Applicative f => a -> f a
pure Term
v
    Term
_ -> Term -> m Term
forall (f :: * -> *) a. Applicative f => a -> f a
pure Term
v

---------------------------------------------------------------------------
-- * The names of built-in things
---------------------------------------------------------------------------

primInteger, primIntegerPos, primIntegerNegSuc,
    primFloat, primChar, primString, primUnit, primUnitUnit, primBool, primTrue, primFalse,
    primSigma,
    primList, primNil, primCons, primIO, primNat, primSuc, primZero,
    primPath, primPathP, primInterval, primIZero, primIOne, primPartial, primPartialP,
    primIMin, primIMax, primINeg,
    primIsOne, primItIsOne, primIsOne1, primIsOne2, primIsOneEmpty,
    primSub, primSubIn, primSubOut,
    primTrans, primHComp,
    primId, primConId, primIdElim,
    primEquiv, primEquivFun, primEquivProof,
    primTranspProof,
    primGlue, prim_glue, prim_unglue,
    prim_glueU, prim_unglueU,
    primFaceForall,
    primNatPlus, primNatMinus, primNatTimes, primNatDivSucAux, primNatModSucAux,
    primNatEquality, primNatLess,
    -- Machine words
    primWord64,
    primSizeUniv, primSize, primSizeLt, primSizeSuc, primSizeInf, primSizeMax,
    primInf, primSharp, primFlat,
    primEquality, primRefl,
    primRewrite, -- Name of rewrite relation
    primLevel, primLevelZero, primLevelSuc, primLevelMax,
    primSetOmega,
    primFromNat, primFromNeg, primFromString,
    -- builtins for reflection:
    primQName, primArgInfo, primArgArgInfo, primArg, primArgArg, primAbs, primAbsAbs, primAgdaTerm, primAgdaTermVar,
    primAgdaTermLam, primAgdaTermExtLam, primAgdaTermDef, primAgdaTermCon, primAgdaTermPi,
    primAgdaTermSort, primAgdaTermLit, primAgdaTermUnsupported, primAgdaTermMeta,
    primAgdaErrorPart, primAgdaErrorPartString, primAgdaErrorPartTerm, primAgdaErrorPartName,
    primHiding, primHidden, primInstance, primVisible,
    primRelevance, primRelevant, primIrrelevant,
    primAssoc, primAssocLeft, primAssocRight, primAssocNon,
    primPrecedence, primPrecRelated, primPrecUnrelated,
    primFixity, primFixityFixity,
    primAgdaLiteral, primAgdaLitNat, primAgdaLitWord64, primAgdaLitFloat, primAgdaLitString, primAgdaLitChar, primAgdaLitQName, primAgdaLitMeta,
    primAgdaSort, primAgdaSortSet, primAgdaSortLit, primAgdaSortUnsupported,
    primAgdaDefinition, primAgdaDefinitionFunDef, primAgdaDefinitionDataDef, primAgdaDefinitionRecordDef,
    primAgdaDefinitionPostulate, primAgdaDefinitionPrimitive, primAgdaDefinitionDataConstructor,
    primAgdaClause, primAgdaClauseClause, primAgdaClauseAbsurd,
    primAgdaPattern, primAgdaPatCon, primAgdaPatVar, primAgdaPatDot,
    primAgdaPatLit, primAgdaPatProj,
    primAgdaPatAbsurd,
    primAgdaMeta,
    primAgdaTCM, primAgdaTCMReturn, primAgdaTCMBind, primAgdaTCMUnify,
    primAgdaTCMTypeError, primAgdaTCMInferType, primAgdaTCMCheckType,
    primAgdaTCMNormalise, primAgdaTCMReduce,
    primAgdaTCMCatchError, primAgdaTCMGetContext, primAgdaTCMExtendContext, primAgdaTCMInContext,
    primAgdaTCMFreshName, primAgdaTCMDeclareDef, primAgdaTCMDeclarePostulate, primAgdaTCMDefineFun,
    primAgdaTCMGetType, primAgdaTCMGetDefinition,
    primAgdaTCMQuoteTerm, primAgdaTCMUnquoteTerm,
    primAgdaTCMBlockOnMeta, primAgdaTCMCommit, primAgdaTCMIsMacro,
    primAgdaTCMWithNormalisation, primAgdaTCMDebugPrint,
    primAgdaTCMNoConstraints,
    primAgdaTCMRunSpeculative
    :: (HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) => m Term

primInteger :: m Term
primInteger                           = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinInteger
primIntegerPos :: m Term
primIntegerPos                        = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinIntegerPos
primIntegerNegSuc :: m Term
primIntegerNegSuc                     = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinIntegerNegSuc
primFloat :: m Term
primFloat                             = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinFloat
primChar :: m Term
primChar                              = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinChar
primString :: m Term
primString                            = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinString
primBool :: m Term
primBool                              = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinBool
primSigma :: m Term
primSigma                             = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinSigma
primUnit :: m Term
primUnit                              = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinUnit
primUnitUnit :: m Term
primUnitUnit                          = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinUnitUnit
primTrue :: m Term
primTrue                              = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinTrue
primFalse :: m Term
primFalse                             = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinFalse
primList :: m Term
primList                              = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinList
primNil :: m Term
primNil                               = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinNil
primCons :: m Term
primCons                              = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinCons
primIO :: m Term
primIO                                = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinIO
primId :: m Term
primId                                = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinId
primConId :: m Term
primConId                             = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinConId
primIdElim :: m Term
primIdElim                            = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getPrimitiveTerm String
builtinIdElim
primPath :: m Term
primPath                              = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinPath
primPathP :: m Term
primPathP                             = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinPathP
primInterval :: m Term
primInterval                          = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinInterval
primIZero :: m Term
primIZero                             = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinIZero
primIOne :: m Term
primIOne                              = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinIOne
primIMin :: m Term
primIMin                              = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getPrimitiveTerm String
builtinIMin
primIMax :: m Term
primIMax                              = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getPrimitiveTerm String
builtinIMax
primINeg :: m Term
primINeg                              = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getPrimitiveTerm String
builtinINeg
primPartial :: m Term
primPartial                           = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getPrimitiveTerm String
"primPartial"
primPartialP :: m Term
primPartialP                          = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getPrimitiveTerm String
"primPartialP"
primIsOne :: m Term
primIsOne                             = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinIsOne
primItIsOne :: m Term
primItIsOne                           = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinItIsOne
primTrans :: m Term
primTrans                             = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getPrimitiveTerm String
builtinTrans
primHComp :: m Term
primHComp                             = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getPrimitiveTerm String
builtinHComp
primEquiv :: m Term
primEquiv                             = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinEquiv
primEquivFun :: m Term
primEquivFun                          = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinEquivFun
primEquivProof :: m Term
primEquivProof                        = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinEquivProof
primTranspProof :: m Term
primTranspProof                       = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinTranspProof
prim_glueU :: m Term
prim_glueU                            = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getPrimitiveTerm String
builtin_glueU
prim_unglueU :: m Term
prim_unglueU                          = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getPrimitiveTerm String
builtin_unglueU
primGlue :: m Term
primGlue                              = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getPrimitiveTerm String
builtinGlue
prim_glue :: m Term
prim_glue                             = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getPrimitiveTerm String
builtin_glue
prim_unglue :: m Term
prim_unglue                           = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getPrimitiveTerm String
builtin_unglue
primFaceForall :: m Term
primFaceForall                        = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getPrimitiveTerm String
builtinFaceForall
primIsOne1 :: m Term
primIsOne1                            = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinIsOne1
primIsOne2 :: m Term
primIsOne2                            = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinIsOne2
primIsOneEmpty :: m Term
primIsOneEmpty                        = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinIsOneEmpty
primSub :: m Term
primSub                               = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinSub
primSubIn :: m Term
primSubIn                             = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinSubIn
primSubOut :: m Term
primSubOut                            = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getPrimitiveTerm String
builtinSubOut
primNat :: m Term
primNat                               = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinNat
primSuc :: m Term
primSuc                               = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinSuc
primZero :: m Term
primZero                              = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinZero
primNatPlus :: m Term
primNatPlus                           = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinNatPlus
primNatMinus :: m Term
primNatMinus                          = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinNatMinus
primNatTimes :: m Term
primNatTimes                          = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinNatTimes
primNatDivSucAux :: m Term
primNatDivSucAux                      = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinNatDivSucAux
primNatModSucAux :: m Term
primNatModSucAux                      = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinNatModSucAux
primNatEquality :: m Term
primNatEquality                       = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinNatEquals
primNatLess :: m Term
primNatLess                           = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinNatLess
primWord64 :: m Term
primWord64                            = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinWord64
primSizeUniv :: m Term
primSizeUniv                          = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinSizeUniv
primSize :: m Term
primSize                              = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinSize
primSizeLt :: m Term
primSizeLt                            = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinSizeLt
primSizeSuc :: m Term
primSizeSuc                           = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinSizeSuc
primSizeInf :: m Term
primSizeInf                           = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinSizeInf
primSizeMax :: m Term
primSizeMax                           = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinSizeMax
primInf :: m Term
primInf                               = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinInf
primSharp :: m Term
primSharp                             = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinSharp
primFlat :: m Term
primFlat                              = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinFlat
primEquality :: m Term
primEquality                          = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinEquality
primRefl :: m Term
primRefl                              = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinRefl
primRewrite :: m Term
primRewrite                           = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinRewrite
primLevel :: m Term
primLevel                             = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinLevel
primLevelZero :: m Term
primLevelZero                         = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinLevelZero
primLevelSuc :: m Term
primLevelSuc                          = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinLevelSuc
primLevelMax :: m Term
primLevelMax                          = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinLevelMax
primSetOmega :: m Term
primSetOmega                          = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinSetOmega
primFromNat :: m Term
primFromNat                           = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinFromNat
primFromNeg :: m Term
primFromNeg                           = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinFromNeg
primFromString :: m Term
primFromString                        = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinFromString
primQName :: m Term
primQName                             = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinQName
primArg :: m Term
primArg                               = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinArg
primArgArg :: m Term
primArgArg                            = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinArgArg
primAbs :: m Term
primAbs                               = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAbs
primAbsAbs :: m Term
primAbsAbs                            = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAbsAbs
primAgdaSort :: m Term
primAgdaSort                          = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaSort
primHiding :: m Term
primHiding                            = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinHiding
primHidden :: m Term
primHidden                            = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinHidden
primInstance :: m Term
primInstance                          = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinInstance
primVisible :: m Term
primVisible                           = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinVisible
primRelevance :: m Term
primRelevance                         = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinRelevance
primRelevant :: m Term
primRelevant                          = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinRelevant
primIrrelevant :: m Term
primIrrelevant                        = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinIrrelevant
primAssoc :: m Term
primAssoc                             = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAssoc
primAssocLeft :: m Term
primAssocLeft                         = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAssocLeft
primAssocRight :: m Term
primAssocRight                        = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAssocRight
primAssocNon :: m Term
primAssocNon                          = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAssocNon
primPrecedence :: m Term
primPrecedence                        = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinPrecedence
primPrecRelated :: m Term
primPrecRelated                       = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinPrecRelated
primPrecUnrelated :: m Term
primPrecUnrelated                     = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinPrecUnrelated
primFixity :: m Term
primFixity                            = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinFixity
primFixityFixity :: m Term
primFixityFixity                      = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinFixityFixity
primArgInfo :: m Term
primArgInfo                           = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinArgInfo
primArgArgInfo :: m Term
primArgArgInfo                        = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinArgArgInfo
primAgdaSortSet :: m Term
primAgdaSortSet                       = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaSortSet
primAgdaSortLit :: m Term
primAgdaSortLit                       = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaSortLit
primAgdaSortUnsupported :: m Term
primAgdaSortUnsupported               = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaSortUnsupported
primAgdaTerm :: m Term
primAgdaTerm                          = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTerm
primAgdaTermVar :: m Term
primAgdaTermVar                       = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTermVar
primAgdaTermLam :: m Term
primAgdaTermLam                       = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTermLam
primAgdaTermExtLam :: m Term
primAgdaTermExtLam                    = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTermExtLam
primAgdaTermDef :: m Term
primAgdaTermDef                       = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTermDef
primAgdaTermCon :: m Term
primAgdaTermCon                       = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTermCon
primAgdaTermPi :: m Term
primAgdaTermPi                        = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTermPi
primAgdaTermSort :: m Term
primAgdaTermSort                      = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTermSort
primAgdaTermLit :: m Term
primAgdaTermLit                       = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTermLit
primAgdaTermUnsupported :: m Term
primAgdaTermUnsupported               = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTermUnsupported
primAgdaTermMeta :: m Term
primAgdaTermMeta                      = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTermMeta
primAgdaErrorPart :: m Term
primAgdaErrorPart                     = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaErrorPart
primAgdaErrorPartString :: m Term
primAgdaErrorPartString               = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaErrorPartString
primAgdaErrorPartTerm :: m Term
primAgdaErrorPartTerm                 = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaErrorPartTerm
primAgdaErrorPartName :: m Term
primAgdaErrorPartName                 = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaErrorPartName
primAgdaLiteral :: m Term
primAgdaLiteral                       = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaLiteral
primAgdaLitNat :: m Term
primAgdaLitNat                        = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaLitNat
primAgdaLitWord64 :: m Term
primAgdaLitWord64                     = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaLitWord64
primAgdaLitFloat :: m Term
primAgdaLitFloat                      = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaLitFloat
primAgdaLitChar :: m Term
primAgdaLitChar                       = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaLitChar
primAgdaLitString :: m Term
primAgdaLitString                     = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaLitString
primAgdaLitQName :: m Term
primAgdaLitQName                      = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaLitQName
primAgdaLitMeta :: m Term
primAgdaLitMeta                       = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaLitMeta
primAgdaPattern :: m Term
primAgdaPattern                       = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaPattern
primAgdaPatCon :: m Term
primAgdaPatCon                        = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaPatCon
primAgdaPatVar :: m Term
primAgdaPatVar                        = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaPatVar
primAgdaPatDot :: m Term
primAgdaPatDot                        = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaPatDot
primAgdaPatLit :: m Term
primAgdaPatLit                        = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaPatLit
primAgdaPatProj :: m Term
primAgdaPatProj                       = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaPatProj
primAgdaPatAbsurd :: m Term
primAgdaPatAbsurd                     = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaPatAbsurd
primAgdaClause :: m Term
primAgdaClause                        = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaClause
primAgdaClauseClause :: m Term
primAgdaClauseClause                  = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaClauseClause
primAgdaClauseAbsurd :: m Term
primAgdaClauseAbsurd                  = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaClauseAbsurd
primAgdaDefinitionFunDef :: m Term
primAgdaDefinitionFunDef              = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaDefinitionFunDef
primAgdaDefinitionDataDef :: m Term
primAgdaDefinitionDataDef             = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaDefinitionDataDef
primAgdaDefinitionRecordDef :: m Term
primAgdaDefinitionRecordDef           = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaDefinitionRecordDef
primAgdaDefinitionDataConstructor :: m Term
primAgdaDefinitionDataConstructor     = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaDefinitionDataConstructor
primAgdaDefinitionPostulate :: m Term
primAgdaDefinitionPostulate           = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaDefinitionPostulate
primAgdaDefinitionPrimitive :: m Term
primAgdaDefinitionPrimitive           = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaDefinitionPrimitive
primAgdaDefinition :: m Term
primAgdaDefinition                    = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaDefinition
primAgdaMeta :: m Term
primAgdaMeta                          = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaMeta
primAgdaTCM :: m Term
primAgdaTCM                           = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTCM
primAgdaTCMReturn :: m Term
primAgdaTCMReturn                     = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTCMReturn
primAgdaTCMBind :: m Term
primAgdaTCMBind                       = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTCMBind
primAgdaTCMUnify :: m Term
primAgdaTCMUnify                      = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTCMUnify
primAgdaTCMTypeError :: m Term
primAgdaTCMTypeError                  = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTCMTypeError
primAgdaTCMInferType :: m Term
primAgdaTCMInferType                  = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTCMInferType
primAgdaTCMCheckType :: m Term
primAgdaTCMCheckType                  = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTCMCheckType
primAgdaTCMNormalise :: m Term
primAgdaTCMNormalise                  = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTCMNormalise
primAgdaTCMReduce :: m Term
primAgdaTCMReduce                     = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTCMReduce
primAgdaTCMCatchError :: m Term
primAgdaTCMCatchError                 = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTCMCatchError
primAgdaTCMGetContext :: m Term
primAgdaTCMGetContext                 = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTCMGetContext
primAgdaTCMExtendContext :: m Term
primAgdaTCMExtendContext              = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTCMExtendContext
primAgdaTCMInContext :: m Term
primAgdaTCMInContext                  = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTCMInContext
primAgdaTCMFreshName :: m Term
primAgdaTCMFreshName                  = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTCMFreshName
primAgdaTCMDeclareDef :: m Term
primAgdaTCMDeclareDef                 = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTCMDeclareDef
primAgdaTCMDeclarePostulate :: m Term
primAgdaTCMDeclarePostulate           = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTCMDeclarePostulate
primAgdaTCMDefineFun :: m Term
primAgdaTCMDefineFun                  = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTCMDefineFun
primAgdaTCMGetType :: m Term
primAgdaTCMGetType                    = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTCMGetType
primAgdaTCMGetDefinition :: m Term
primAgdaTCMGetDefinition              = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTCMGetDefinition
primAgdaTCMQuoteTerm :: m Term
primAgdaTCMQuoteTerm                  = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTCMQuoteTerm
primAgdaTCMUnquoteTerm :: m Term
primAgdaTCMUnquoteTerm                = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTCMUnquoteTerm
primAgdaTCMBlockOnMeta :: m Term
primAgdaTCMBlockOnMeta                = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTCMBlockOnMeta
primAgdaTCMCommit :: m Term
primAgdaTCMCommit                     = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTCMCommit
primAgdaTCMIsMacro :: m Term
primAgdaTCMIsMacro                    = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTCMIsMacro
primAgdaTCMWithNormalisation :: m Term
primAgdaTCMWithNormalisation          = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTCMWithNormalisation
primAgdaTCMDebugPrint :: m Term
primAgdaTCMDebugPrint                 = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTCMDebugPrint
primAgdaTCMNoConstraints :: m Term
primAgdaTCMNoConstraints              = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTCMNoConstraints
primAgdaTCMRunSpeculative :: m Term
primAgdaTCMRunSpeculative             = String -> m Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
String -> m Term
getBuiltin String
builtinAgdaTCMRunSpeculative

-- | The coinductive primitives.

data CoinductionKit = CoinductionKit
  { CoinductionKit -> QName
nameOfInf   :: QName
  , CoinductionKit -> QName
nameOfSharp :: QName
  , CoinductionKit -> QName
nameOfFlat  :: QName
  }

-- | Tries to build a 'CoinductionKit'.

coinductionKit' :: TCM CoinductionKit
coinductionKit' :: TCM CoinductionKit
coinductionKit' = do
  Def QName
inf   Elims
_ <- TCMT IO Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primInf
  Def QName
sharp Elims
_ <- TCMT IO Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primSharp
  Def QName
flat  Elims
_ <- TCMT IO Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primFlat
  CoinductionKit -> TCM CoinductionKit
forall (m :: * -> *) a. Monad m => a -> m a
return (CoinductionKit -> TCM CoinductionKit)
-> CoinductionKit -> TCM CoinductionKit
forall a b. (a -> b) -> a -> b
$ CoinductionKit :: QName -> QName -> QName -> CoinductionKit
CoinductionKit
    { nameOfInf :: QName
nameOfInf   = QName
inf
    , nameOfSharp :: QName
nameOfSharp = QName
sharp
    , nameOfFlat :: QName
nameOfFlat  = QName
flat
    }

coinductionKit :: TCM (Maybe CoinductionKit)
coinductionKit :: TCM (Maybe CoinductionKit)
coinductionKit = TCM CoinductionKit -> TCM (Maybe CoinductionKit)
forall e (m :: * -> *) a.
(MonadError e m, Functor m) =>
m a -> m (Maybe a)
tryMaybe TCM CoinductionKit
coinductionKit'


------------------------------------------------------------------------
-- * Path equality
------------------------------------------------------------------------

getPrimName :: Term -> QName
getPrimName :: Term -> QName
getPrimName Term
ty = do
  let lamV :: Term -> ([Hiding], Term)
lamV (Lam ArgInfo
i Abs Term
b)  = ([Hiding] -> [Hiding]) -> ([Hiding], Term) -> ([Hiding], Term)
forall a c b. (a -> c) -> (a, b) -> (c, b)
mapFst (ArgInfo -> Hiding
forall a. LensHiding a => a -> Hiding
getHiding ArgInfo
i Hiding -> [Hiding] -> [Hiding]
forall a. a -> [a] -> [a]
:) (([Hiding], Term) -> ([Hiding], Term))
-> ([Hiding], Term) -> ([Hiding], Term)
forall a b. (a -> b) -> a -> b
$ Term -> ([Hiding], Term)
lamV (Abs Term -> Term
forall a. Abs a -> a
unAbs Abs Term
b)
      lamV (Pi Dom Type
_ Abs Type
b)   = Term -> ([Hiding], Term)
lamV (Type -> Term
forall t a. Type'' t a -> a
unEl (Type -> Term) -> Type -> Term
forall a b. (a -> b) -> a -> b
$ Abs Type -> Type
forall a. Abs a -> a
unAbs Abs Type
b)
      lamV Term
v          = ([], Term
v)
  case Term -> ([Hiding], Term)
lamV Term
ty of
            ([Hiding]
_, Def QName
path Elims
_) -> QName
path
            ([Hiding]
_, Con ConHead
nm ConInfo
_ Elims
_)   -> ConHead -> QName
conName ConHead
nm
            ([Hiding]
_, Term
_)          -> QName
forall a. HasCallStack => a
__IMPOSSIBLE__

getBuiltinName', getPrimitiveName' :: HasBuiltins m => String -> m (Maybe QName)
getBuiltinName' :: String -> m (Maybe QName)
getBuiltinName' String
n = (Term -> QName) -> Maybe Term -> Maybe QName
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Term -> QName
getPrimName (Maybe Term -> Maybe QName) -> m (Maybe Term) -> m (Maybe QName)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> m (Maybe Term)
forall (m :: * -> *). HasBuiltins m => String -> m (Maybe Term)
getBuiltin' String
n
getPrimitiveName' :: String -> m (Maybe QName)
getPrimitiveName' String
n = (PrimFun -> QName) -> Maybe PrimFun -> Maybe QName
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap PrimFun -> QName
primFunName (Maybe PrimFun -> Maybe QName)
-> m (Maybe PrimFun) -> m (Maybe QName)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> m (Maybe PrimFun)
forall (m :: * -> *). HasBuiltins m => String -> m (Maybe PrimFun)
getPrimitive' String
n

isPrimitive :: HasBuiltins m => String -> QName -> m Bool
isPrimitive :: String -> QName -> m Bool
isPrimitive String
n QName
q = (QName -> Maybe QName
forall a. a -> Maybe a
Just QName
q Maybe QName -> Maybe QName -> Bool
forall a. Eq a => a -> a -> Bool
==) (Maybe QName -> Bool) -> m (Maybe QName) -> m Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> m (Maybe QName)
forall (m :: * -> *). HasBuiltins m => String -> m (Maybe QName)
getPrimitiveName' String
n

intervalView' :: HasBuiltins m => m (Term -> IntervalView)
intervalView' :: m (Term -> IntervalView)
intervalView' = do
  Maybe QName
iz <- String -> m (Maybe QName)
forall (m :: * -> *). HasBuiltins m => String -> m (Maybe QName)
getBuiltinName' String
builtinIZero
  Maybe QName
io <- String -> m (Maybe QName)
forall (m :: * -> *). HasBuiltins m => String -> m (Maybe QName)
getBuiltinName' String
builtinIOne
  Maybe QName
imax <- String -> m (Maybe QName)
forall (m :: * -> *). HasBuiltins m => String -> m (Maybe QName)
getPrimitiveName' String
"primIMax"
  Maybe QName
imin <- String -> m (Maybe QName)
forall (m :: * -> *). HasBuiltins m => String -> m (Maybe QName)
getPrimitiveName' String
"primIMin"
  Maybe QName
ineg <- String -> m (Maybe QName)
forall (m :: * -> *). HasBuiltins m => String -> m (Maybe QName)
getPrimitiveName' String
"primINeg"
  (Term -> IntervalView) -> m (Term -> IntervalView)
forall (m :: * -> *) a. Monad m => a -> m a
return ((Term -> IntervalView) -> m (Term -> IntervalView))
-> (Term -> IntervalView) -> m (Term -> IntervalView)
forall a b. (a -> b) -> a -> b
$ \ Term
t ->
    case Term
t of
      Def QName
q Elims
es ->
        case Elims
es of
          [Apply Arg Term
x,Apply Arg Term
y] | QName -> Maybe QName
forall a. a -> Maybe a
Just QName
q Maybe QName -> Maybe QName -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe QName
imin -> Arg Term -> Arg Term -> IntervalView
IMin Arg Term
x Arg Term
y
          [Apply Arg Term
x,Apply Arg Term
y] | QName -> Maybe QName
forall a. a -> Maybe a
Just QName
q Maybe QName -> Maybe QName -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe QName
imax -> Arg Term -> Arg Term -> IntervalView
IMax Arg Term
x Arg Term
y
          [Apply Arg Term
x]         | QName -> Maybe QName
forall a. a -> Maybe a
Just QName
q Maybe QName -> Maybe QName -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe QName
ineg -> Arg Term -> IntervalView
INeg Arg Term
x
          Elims
_                 -> Term -> IntervalView
OTerm Term
t
      Con ConHead
q ConInfo
_ [] | QName -> Maybe QName
forall a. a -> Maybe a
Just (ConHead -> QName
conName ConHead
q) Maybe QName -> Maybe QName -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe QName
iz -> IntervalView
IZero
                 | QName -> Maybe QName
forall a. a -> Maybe a
Just (ConHead -> QName
conName ConHead
q) Maybe QName -> Maybe QName -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe QName
io -> IntervalView
IOne
      Term
_ -> Term -> IntervalView
OTerm Term
t

intervalView :: HasBuiltins m => Term -> m IntervalView
intervalView :: Term -> m IntervalView
intervalView Term
t = do
  Term -> IntervalView
f <- m (Term -> IntervalView)
forall (m :: * -> *). HasBuiltins m => m (Term -> IntervalView)
intervalView'
  IntervalView -> m IntervalView
forall (m :: * -> *) a. Monad m => a -> m a
return (Term -> IntervalView
f Term
t)

intervalUnview :: HasBuiltins m => IntervalView -> m Term
intervalUnview :: IntervalView -> m Term
intervalUnview IntervalView
t = do
  IntervalView -> Term
f <- m (IntervalView -> Term)
forall (m :: * -> *). HasBuiltins m => m (IntervalView -> Term)
intervalUnview'
  Term -> m Term
forall (m :: * -> *) a. Monad m => a -> m a
return (IntervalView -> Term
f IntervalView
t)

intervalUnview' :: HasBuiltins m => m (IntervalView -> Term)
intervalUnview' :: m (IntervalView -> Term)
intervalUnview' = do
  Term
iz <- Term -> Maybe Term -> Term
forall a. a -> Maybe a -> a
fromMaybe Term
forall a. HasCallStack => a
__IMPOSSIBLE__ (Maybe Term -> Term) -> m (Maybe Term) -> m Term
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> m (Maybe Term)
forall (m :: * -> *). HasBuiltins m => String -> m (Maybe Term)
getBuiltin' String
builtinIZero -- should it be a type error instead?
  Term
io <- Term -> Maybe Term -> Term
forall a. a -> Maybe a -> a
fromMaybe Term
forall a. HasCallStack => a
__IMPOSSIBLE__ (Maybe Term -> Term) -> m (Maybe Term) -> m Term
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> m (Maybe Term)
forall (m :: * -> *). HasBuiltins m => String -> m (Maybe Term)
getBuiltin' String
builtinIOne
  Term
imin <- (QName -> Elims -> Term
`Def` []) (QName -> Term) -> (Maybe QName -> QName) -> Maybe QName -> Term
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> QName -> Maybe QName -> QName
forall a. a -> Maybe a -> a
fromMaybe QName
forall a. HasCallStack => a
__IMPOSSIBLE__ (Maybe QName -> Term) -> m (Maybe QName) -> m Term
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> m (Maybe QName)
forall (m :: * -> *). HasBuiltins m => String -> m (Maybe QName)
getPrimitiveName' String
"primIMin"
  Term
imax <- (QName -> Elims -> Term
`Def` []) (QName -> Term) -> (Maybe QName -> QName) -> Maybe QName -> Term
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> QName -> Maybe QName -> QName
forall a. a -> Maybe a -> a
fromMaybe QName
forall a. HasCallStack => a
__IMPOSSIBLE__ (Maybe QName -> Term) -> m (Maybe QName) -> m Term
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> m (Maybe QName)
forall (m :: * -> *). HasBuiltins m => String -> m (Maybe QName)
getPrimitiveName' String
"primIMax"
  Term
ineg <- (QName -> Elims -> Term
`Def` []) (QName -> Term) -> (Maybe QName -> QName) -> Maybe QName -> Term
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> QName -> Maybe QName -> QName
forall a. a -> Maybe a -> a
fromMaybe QName
forall a. HasCallStack => a
__IMPOSSIBLE__ (Maybe QName -> Term) -> m (Maybe QName) -> m Term
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> m (Maybe QName)
forall (m :: * -> *). HasBuiltins m => String -> m (Maybe QName)
getPrimitiveName' String
"primINeg"
  (IntervalView -> Term) -> m (IntervalView -> Term)
forall (m :: * -> *) a. Monad m => a -> m a
return ((IntervalView -> Term) -> m (IntervalView -> Term))
-> (IntervalView -> Term) -> m (IntervalView -> Term)
forall a b. (a -> b) -> a -> b
$ \ IntervalView
v -> case IntervalView
v of
             IntervalView
IZero -> Term
iz
             IntervalView
IOne  -> Term
io
             IMin Arg Term
x Arg Term
y -> Term -> Args -> Term
forall t. Apply t => t -> Args -> t
apply Term
imin [Arg Term
x,Arg Term
y]
             IMax Arg Term
x Arg Term
y -> Term -> Args -> Term
forall t. Apply t => t -> Args -> t
apply Term
imax [Arg Term
x,Arg Term
y]
             INeg Arg Term
x   -> Term -> Args -> Term
forall t. Apply t => t -> Args -> t
apply Term
ineg [Arg Term
x]
             OTerm Term
t -> Term
t

------------------------------------------------------------------------
-- * Path equality
------------------------------------------------------------------------

-- | Check whether the type is actually an path (lhs ≡ rhs)
--   and extract lhs, rhs, and their type.
--
--   Precondition: type is reduced.

pathView :: HasBuiltins m => Type -> m PathView
pathView :: Type -> m PathView
pathView Type
t0 = do
  Type -> PathView
view <- m (Type -> PathView)
forall (m :: * -> *). HasBuiltins m => m (Type -> PathView)
pathView'
  PathView -> m PathView
forall (m :: * -> *) a. Monad m => a -> m a
return (PathView -> m PathView) -> PathView -> m PathView
forall a b. (a -> b) -> a -> b
$ Type -> PathView
view Type
t0

pathView' :: HasBuiltins m => m (Type -> PathView)
pathView' :: m (Type -> PathView)
pathView' = do
 Maybe QName
mpath  <- String -> m (Maybe QName)
forall (m :: * -> *). HasBuiltins m => String -> m (Maybe QName)
getBuiltinName' String
builtinPath
 Maybe QName
mpathp <- String -> m (Maybe QName)
forall (m :: * -> *). HasBuiltins m => String -> m (Maybe QName)
getBuiltinName' String
builtinPathP
 (Type -> PathView) -> m (Type -> PathView)
forall (m :: * -> *) a. Monad m => a -> m a
return ((Type -> PathView) -> m (Type -> PathView))
-> (Type -> PathView) -> m (Type -> PathView)
forall a b. (a -> b) -> a -> b
$ \ t0 :: Type
t0@(El Sort' Term
s Term
t) ->
  case Term
t of
    Def QName
path' [ Apply Arg Term
level , Apply Arg Term
typ , Apply Arg Term
lhs , Apply Arg Term
rhs ]
      | QName -> Maybe QName
forall a. a -> Maybe a
Just QName
path' Maybe QName -> Maybe QName -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe QName
mpath, Just QName
path <- Maybe QName
mpathp -> Sort' Term
-> QName
-> Arg Term
-> Arg Term
-> Arg Term
-> Arg Term
-> PathView
PathType Sort' Term
s QName
path Arg Term
level (KillRangeT Term
lam_i KillRangeT Term -> Arg Term -> Arg Term
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Arg Term
typ) Arg Term
lhs Arg Term
rhs
      where lam_i :: KillRangeT Term
lam_i = ArgInfo -> Abs Term -> Term
Lam ArgInfo
defaultArgInfo (Abs Term -> Term) -> (Term -> Abs Term) -> KillRangeT Term
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Term -> Abs Term
forall a. String -> a -> Abs a
NoAbs String
"_"
    Def QName
path' [ Apply Arg Term
level , Apply Arg Term
typ , Apply Arg Term
lhs , Apply Arg Term
rhs ]
      | QName -> Maybe QName
forall a. a -> Maybe a
Just QName
path' Maybe QName -> Maybe QName -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe QName
mpathp, Just QName
path <- Maybe QName
mpathp -> Sort' Term
-> QName
-> Arg Term
-> Arg Term
-> Arg Term
-> Arg Term
-> PathView
PathType Sort' Term
s QName
path Arg Term
level Arg Term
typ Arg Term
lhs Arg Term
rhs
    Term
_ -> Type -> PathView
OType Type
t0

-- | Non dependent Path
idViewAsPath :: HasBuiltins m => Type -> m PathView
idViewAsPath :: Type -> m PathView
idViewAsPath t0 :: Type
t0@(El Sort' Term
s Term
t) = do
  Maybe QName
mid <- (Term -> QName) -> Maybe Term -> Maybe QName
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Term -> QName
getPrimName (Maybe Term -> Maybe QName) -> m (Maybe Term) -> m (Maybe QName)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> m (Maybe Term)
forall (m :: * -> *). HasBuiltins m => String -> m (Maybe Term)
getBuiltin' String
builtinId
  Maybe QName
mpath <- (Term -> QName) -> Maybe Term -> Maybe QName
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Term -> QName
getPrimName (Maybe Term -> Maybe QName) -> m (Maybe Term) -> m (Maybe QName)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> m (Maybe Term)
forall (m :: * -> *). HasBuiltins m => String -> m (Maybe Term)
getBuiltin' String
builtinPath
  case Maybe QName
mid of
   Just QName
path | Maybe QName -> Bool
forall a. Maybe a -> Bool
isJust Maybe QName
mpath -> case Term
t of
    Def QName
path' [ Apply Arg Term
level , Apply Arg Term
typ , Apply Arg Term
lhs , Apply Arg Term
rhs ]
      | QName
path' QName -> QName -> Bool
forall a. Eq a => a -> a -> Bool
== QName
path -> PathView -> m PathView
forall (m :: * -> *) a. Monad m => a -> m a
return (PathView -> m PathView) -> PathView -> m PathView
forall a b. (a -> b) -> a -> b
$ Sort' Term
-> QName
-> Arg Term
-> Arg Term
-> Arg Term
-> Arg Term
-> PathView
PathType Sort' Term
s (Maybe QName -> QName
forall a. HasCallStack => Maybe a -> a
fromJust Maybe QName
mpath) Arg Term
level Arg Term
typ Arg Term
lhs Arg Term
rhs
    Term
_ -> PathView -> m PathView
forall (m :: * -> *) a. Monad m => a -> m a
return (PathView -> m PathView) -> PathView -> m PathView
forall a b. (a -> b) -> a -> b
$ Type -> PathView
OType Type
t0
   Maybe QName
_ -> PathView -> m PathView
forall (m :: * -> *) a. Monad m => a -> m a
return (PathView -> m PathView) -> PathView -> m PathView
forall a b. (a -> b) -> a -> b
$ Type -> PathView
OType Type
t0

boldPathView :: Type -> PathView
boldPathView :: Type -> PathView
boldPathView t0 :: Type
t0@(El Sort' Term
s Term
t) = do
  case Term
t of
    Def QName
path' [ Apply Arg Term
level , Apply Arg Term
typ , Apply Arg Term
lhs , Apply Arg Term
rhs ]
      -> Sort' Term
-> QName
-> Arg Term
-> Arg Term
-> Arg Term
-> Arg Term
-> PathView
PathType Sort' Term
s QName
path' Arg Term
level Arg Term
typ Arg Term
lhs Arg Term
rhs
    Term
_ -> Type -> PathView
OType Type
t0

-- | Revert the 'PathView'.
--
--   Postcondition: type is reduced.

pathUnview :: PathView -> Type
pathUnview :: PathView -> Type
pathUnview (OType Type
t) = Type
t
pathUnview (PathType Sort' Term
s QName
path Arg Term
l Arg Term
t Arg Term
lhs Arg Term
rhs) =
  Sort' Term -> Term -> Type
forall t a. Sort' t -> a -> Type'' t a
El Sort' Term
s (Term -> Type) -> Term -> Type
forall a b. (a -> b) -> a -> b
$ QName -> Elims -> Term
Def QName
path (Elims -> Term) -> Elims -> Term
forall a b. (a -> b) -> a -> b
$ (Arg Term -> Elim' Term) -> Args -> Elims
forall a b. (a -> b) -> [a] -> [b]
map Arg Term -> Elim' Term
forall a. Arg a -> Elim' a
Apply [Arg Term
l, Arg Term
t, Arg Term
lhs, Arg Term
rhs]

------------------------------------------------------------------------
-- * Builtin equality
------------------------------------------------------------------------

-- | Get the name of the equality type.
primEqualityName :: TCM QName
-- primEqualityName = getDef =<< primEquality  -- LEADS TO IMPORT CYCLE
primEqualityName :: TCM QName
primEqualityName = do
  Term
eq <- TCMT IO Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primEquality
  -- Andreas, 2014-05-17 moved this here from TC.Rules.Def
  -- Don't know why up to 2 hidden lambdas need to be stripped,
  -- but I left the code in place.
  -- Maybe it was intended that equality could be declared
  -- in three different ways:
  -- 1. universe and type polymorphic
  -- 2. type polymorphic only
  -- 3. monomorphic.
  let lamV :: Term -> ([Hiding], Term)
lamV (Lam ArgInfo
i Abs Term
b)  = ([Hiding] -> [Hiding]) -> ([Hiding], Term) -> ([Hiding], Term)
forall a c b. (a -> c) -> (a, b) -> (c, b)
mapFst (ArgInfo -> Hiding
forall a. LensHiding a => a -> Hiding
getHiding ArgInfo
i Hiding -> [Hiding] -> [Hiding]
forall a. a -> [a] -> [a]
:) (([Hiding], Term) -> ([Hiding], Term))
-> ([Hiding], Term) -> ([Hiding], Term)
forall a b. (a -> b) -> a -> b
$ Term -> ([Hiding], Term)
lamV (Abs Term -> Term
forall a. Abs a -> a
unAbs Abs Term
b)
      lamV Term
v          = ([], Term
v)
  QName -> TCM QName
forall (m :: * -> *) a. Monad m => a -> m a
return (QName -> TCM QName) -> QName -> TCM QName
forall a b. (a -> b) -> a -> b
$ case Term -> ([Hiding], Term)
lamV Term
eq of
    ([Hiding]
_, Def QName
equality Elims
_) -> QName
equality
    ([Hiding], Term)
_                   -> QName
forall a. HasCallStack => a
__IMPOSSIBLE__

-- | Check whether the type is actually an equality (lhs ≡ rhs)
--   and extract lhs, rhs, and their type.
--
--   Precondition: type is reduced.

equalityView :: Type -> TCM EqualityView
equalityView :: Type -> TCM EqualityView
equalityView t0 :: Type
t0@(El Sort' Term
s Term
t) = do
  QName
equality <- TCM QName
primEqualityName
  case Term
t of
    Def QName
equality' Elims
es | QName
equality' QName -> QName -> Bool
forall a. Eq a => a -> a -> Bool
== QName
equality -> do
      let vs :: Args
vs = Args -> Maybe Args -> Args
forall a. a -> Maybe a -> a
fromMaybe Args
forall a. HasCallStack => a
__IMPOSSIBLE__ (Maybe Args -> Args) -> Maybe Args -> Args
forall a b. (a -> b) -> a -> b
$ Elims -> Maybe Args
forall a. [Elim' a] -> Maybe [Arg a]
allApplyElims Elims
es
      let n :: Int
n = Args -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length Args
vs
      Bool -> TCM () -> TCM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
3) TCM ()
forall a. HasCallStack => a
__IMPOSSIBLE__
      let (Args
pars, [ Arg Term
typ , Arg Term
lhs, Arg Term
rhs ]) = Int -> Args -> (Args, Args)
forall a. Int -> [a] -> ([a], [a])
splitAt (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
3) Args
vs
      EqualityView -> TCM EqualityView
forall (m :: * -> *) a. Monad m => a -> m a
return (EqualityView -> TCM EqualityView)
-> EqualityView -> TCM EqualityView
forall a b. (a -> b) -> a -> b
$ Sort' Term
-> QName
-> Args
-> Arg Term
-> Arg Term
-> Arg Term
-> EqualityView
EqualityType Sort' Term
s QName
equality Args
pars Arg Term
typ Arg Term
lhs Arg Term
rhs
    Term
_ -> EqualityView -> TCM EqualityView
forall (m :: * -> *) a. Monad m => a -> m a
return (EqualityView -> TCM EqualityView)
-> EqualityView -> TCM EqualityView
forall a b. (a -> b) -> a -> b
$ Type -> EqualityView
OtherType Type
t0

-- | Revert the 'EqualityView'.
--
--   Postcondition: type is reduced.

equalityUnview :: EqualityView -> Type
equalityUnview :: EqualityView -> Type
equalityUnview (OtherType Type
t) = Type
t
equalityUnview (EqualityType Sort' Term
s QName
equality Args
l Arg Term
t Arg Term
lhs Arg Term
rhs) =
  Sort' Term -> Term -> Type
forall t a. Sort' t -> a -> Type'' t a
El Sort' Term
s (Term -> Type) -> Term -> Type
forall a b. (a -> b) -> a -> b
$ QName -> Elims -> Term
Def QName
equality (Elims -> Term) -> Elims -> Term
forall a b. (a -> b) -> a -> b
$ (Arg Term -> Elim' Term) -> Args -> Elims
forall a b. (a -> b) -> [a] -> [b]
map Arg Term -> Elim' Term
forall a. Arg a -> Elim' a
Apply (Args
l Args -> Args -> Args
forall a. [a] -> [a] -> [a]
++ [Arg Term
t, Arg Term
lhs, Arg Term
rhs])

-- | Primitives with typechecking constrants.
constrainedPrims :: [String]
constrainedPrims :: [String]
constrainedPrims =
  [ String
builtinConId
  , String
builtinPOr
  , String
builtinComp
  , String
builtinHComp
  , String
builtinTrans
  , String
builtin_glue
  , String
builtin_glueU
  ]

getNameOfConstrained :: HasBuiltins m => String -> m (Maybe QName)
getNameOfConstrained :: String -> m (Maybe QName)
getNameOfConstrained String
s = do
  Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (String
s String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [String]
constrainedPrims) m ()
forall a. HasCallStack => a
__IMPOSSIBLE__
  String -> m (Maybe QName)
forall (m :: * -> *). HasBuiltins m => String -> m (Maybe QName)
getName' String
s