@@ -27,7 +27,7 @@ module Idris.Core.Evaluate(normalise, normaliseTrace, normaliseC,
27 lookupNameTotal, lookupMetaInformation, lookupTyEnv, isTCDict,
27 lookupNameTotal, lookupMetaInformation, lookupTyEnv, isTCDict,
28 isCanonical, isDConName, canBeDConName, isTConName, isConName, isFnName,
28 isCanonical, isDConName, canBeDConName, isTConName, isConName, isFnName,
29 Value(..), Quote(..), initEval, uniqueNameCtxt, uniqueBindersCtxt, definitions,
29 Value(..), Quote(..), initEval, uniqueNameCtxt, uniqueBindersCtxt, definitions,
30− isUniverse) where
30+ isUniverse, linearCheck, linearCheckArg) where
32import Idris.Core.CaseTree
32import Idris.Core.CaseTree
33import Idris.Core.TT
33import Idris.Core.TT
@@ -1174,6 +1174,33 @@ lookupInjectiveExact :: Name -> Context -> Maybe Injectivity
1174lookupInjectiveExact n ctxt = fmap mkt $ lookupCtxtExact n (definitions ctxt)
1174lookupInjectiveExact n ctxt = fmap mkt $ lookupCtxtExact n (definitions ctxt)
1175 where mkt (d, _, inj, a, t, m) = inj
1175 where mkt (d, _, inj, a, t, m) = inj
1177+-- Assume type is at least in whnfArgs form
1178+linearCheck :: Context -> Type -> TC ()
1179+linearCheck ctxt t = checkArgs t
1181+ checkArgs (Bind n (Pi RigW _ ty _) sc)
1182+ = do linearCheckArg ctxt ty
1183+ checkArgs (substV (P Bound n Erased) sc)
1184+ checkArgs (Bind n (Pi _ _ _ _) sc)
1185+ = checkArgs (substV (P Bound n Erased) sc)
1186+ checkArgs _ = return ()
1188+linearCheckArg :: Context -> Type -> TC ()
1189+linearCheckArg ctxt ty = mapM_ checkNameOK (allTTNames ty)
1192+ = case lookupRigCountExact f ctxt of
1194+ tfail $ Msg $ show f ++ " can only appear in a linear binding"
1197+ checkArgs (Bind n (Pi RigW _ ty _) sc)
1198+ = do mapM_ checkNameOK (allTTNames ty)
1199+ checkArgs (substV (P Bound n Erased) sc)
1200+ checkArgs (Bind n (Pi _ _ _ _) sc)
1201+ = checkArgs (substV (P Bound n Erased) sc)
1202+ checkArgs _ = return ()
1177-- Check if a name is reducible in the type checker. Partial definitions
1204-- Check if a name is reducible in the type checker. Partial definitions
1178-- are not reducible (so treated as a constant)
1205-- are not reducible (so treated as a constant)
1179tcReducible :: Name -> Context -> Bool
1206tcReducible :: Name -> Context -> Bool