3
module Agda.TypeChecking.Monad.Open
10
import Control.Applicative
12
import Control.Monad.Error
15
import Agda.Syntax.Common
17
import Agda.TypeChecking.Substitute
18
import Agda.TypeChecking.Monad.Base
20
import {-# SOURCE #-} Agda.TypeChecking.Monad.Context
22
#include "../../undefined.h"
23
import Agda.Utils.Impossible
25
-- | Create an open term in the current context.
26
makeOpen :: MonadTCM tcm => a -> tcm (Open a)
29
return $ OpenThing ctx x
31
-- | Create an open term which is closed.
32
makeClosed :: a -> Open a
33
makeClosed = OpenThing []
36
-- | Extract the value from an open term. Must be done in an extension of the
37
-- context in which the term was created.
38
getOpen :: (MonadTCM tcm, Raise a) => Open a -> tcm a
39
getOpen (OpenThing [] x) = return x
40
getOpen (OpenThing ctx x) = do
42
unless (ctx `isSuffixOf` ctx') $ fail $ "thing out of context (" ++ show ctx ++ " is not a sub context of " ++ show ctx' ++ ")"
43
return $ raise (genericLength ctx' - genericLength ctx) x
45
tryOpen :: (MonadTCM tcm, Raise a) => Open a -> tcm (Maybe a)
48
`catchError` \_ -> return Nothing