5
5
module Agda.TypeChecking.Implicit where
7
import Control.Applicative
7
10
import Agda.Syntax.Common
11
import Agda.Syntax.Internal
13
import Agda.TypeChecking.Irrelevance
14
import {-# SOURCE #-} Agda.TypeChecking.MetaVars
15
import Agda.TypeChecking.Monad
16
import Agda.TypeChecking.Reduce
17
import Agda.TypeChecking.Substitute
18
import Agda.TypeChecking.Telescope
19
import {-# SOURCE #-} Agda.TypeChecking.InstanceArguments
21
import Agda.Utils.Size
22
import Agda.Utils.Tuple
9
24
#include "../undefined.h"
10
25
import Agda.Utils.Impossible
11
import Control.Applicative
28
-- | @implicitArgs n expand t@ generates up to @n@ implicit arguments
29
-- metas (unbounded if @n<0@), as long as @t@ is a function type
30
-- and @expand@ holds on the hiding info of its domain.
31
implicitArgs :: Int -> (Hiding -> Bool) -> Type -> TCM (Args, Type)
32
implicitArgs 0 expand t0 = return ([], t0)
33
implicitArgs n expand t0 = do
35
case ignoreSharing $ unEl t0' of
36
Pi (Dom h rel a) b | expand h -> do
37
when (h == Instance) $ reportSLn "tc.term.args.ifs" 15 $
38
"inserting implicit meta for type " ++ show a
39
v <- applyRelevanceToContext rel $ newMeta h (absName b) a
41
mapFst (arg:) <$> implicitArgs (n-1) expand (absApp b v)
44
newMeta Hidden = newNamedValueMeta RunMetaOccursCheck
45
newMeta Instance = initializeIFSMeta
46
newMeta _ = __IMPOSSIBLE__
48
{- UNUSED, BUT DONT REMOVE (Andreas, 2012-07-31)
49
introImplicits :: (Hiding -> Bool) -> Type -> (Int -> Type -> TCM a) -> TCM a
50
introImplicits expand t cont = do
51
TelV tel t0 <- telViewUpTo' (-1) (expand . domHiding) t
52
addCtxTel tel $ cont (size tel) t0
55
{- POINTLESS, NEEDS TO BE CONTINUATION-PASSING
56
-- | @introImplicits expand t@ introduces domain types of @t@
57
-- into the context, as long as @expand@ holds on them.
58
introImplicits :: (Hiding -> Bool) -> Type -> TCM (Int, Type)
59
introImplicits expand t = do
62
Pi dom@(Dom h rel a) b | expand h ->
63
addCtxString (absName b) dom $ do
64
mapFst (+1) <$> introImplicits expand (absBody b)
68
---------------------------------------------------------------------------
13
70
data ImplicitInsertion
14
71
= ImpInsert [Hiding] -- ^ this many implicits have to be inserted