@@ -105,10 +105,10 @@ eval ctxt statics genv tm opts = ev True [] tm where
105105
106106 ev top env (P _ n ty)
107107 | Just (Let t v) <- lookup n genv = ev top env v
108− ev top env (P Ref n ty) = case lookupDef n ctxt of
109− Just (Function (Fun _ _ _ v)) -> return v
110− Just (TyDecl nt ty hty) -> return $ VP nt n hty
111− Just (CaseOp inl _ _ [] tree) ->
108+ ev top env (P Ref n ty) = case lookupDef Nothing n ctxt of
109+ [Function (Fun _ _ _ v)] -> return v
110+ [TyDecl nt ty hty] -> return $ VP nt n hty
111+ [CaseOp inl _ _ [] tree] ->
112112 if simpl && (not inl)
113113 then liftM (VP Ref n) (ev top env ty)
114114 else do c <- evCase top env [] [] tree
@@ -149,14 +149,14 @@ eval ctxt statics genv tm opts = ev True [] tm where
149149 apply False env f args
150150 | spec = return $ unload env f args
151151 apply top env (VP Ref n ty) args
152− | Just (CaseOp inl _ _ ns tree) <- lookupDef n ctxt
152+ | [CaseOp inl _ _ ns tree] <- lookupDef Nothing n ctxt
153153 = -- traceWhen (n == UN ["interp"]) (show (n, args)) $
154154 if simpl && (not inl) then return $ unload env (VP Ref n ty) args
155155 else do c <- evCase top env ns args tree
156156 case c of
157157 (Nothing, _) -> return $ unload env (VP Ref n ty) args
158158 (Just v, rest) -> evApply top env rest v
159− | Just (Operator _ i op) <- lookupDef n ctxt
159+ | [Operator _ i op] <- lookupDef Nothing n ctxt
160160 = if (i <= length args)
161161 then case op (take i args) of
162162 Nothing -> return $ unload env (VP Ref n ty) args
@@ -292,10 +292,10 @@ eval_hnf ctxt statics genv tm = ev [] tm where
292292 ev :: [HNF] -> TT Name -> Eval HNF
293293 ev env (P _ n ty)
294294 | Just (Let t v) <- lookup n genv = ev env v
295− ev env (P Ref n ty) = case lookupDef n ctxt of
296− Just (Function (Fun _ _ t _)) -> ev env t
297− Just (TyDecl nt ty hty) -> return $ HP nt n ty
298− Just (CaseOp inl _ _ [] tree) ->
295+ ev env (P Ref n ty) = case lookupDef Nothing n ctxt of
296+ [Function (Fun _ _ t _)] -> ev env t
297+ [TyDecl nt ty hty] -> return $ HP nt n ty
298+ [CaseOp inl _ _ [] tree] ->
299299 do c <- evCase env [] [] tree
300300 case c of
301301 (Nothing, _, _) -> return $ HP Ref n ty
@@ -325,7 +325,7 @@ eval_hnf ctxt statics genv tm = ev [] tm where
325325 app <- apply env sc' as
326326 wknH (-1) app
327327 apply env (HP Ref n ty) args
328− | Just (CaseOp _ _ _ ns tree) <- lookupDef n ctxt
328+ | [CaseOp _ _ _ ns tree] <- lookupDef Nothing n ctxt
329329 = do c <- evCase env ns args tree
330330 case c of
331331 (Nothing, _, env') -> return $ unload env' (HP Ref n ty) args
@@ -494,29 +494,30 @@ addOperator n ty a op uctxt
494494 ctxt' = addDef n (Operator ty a op) ctxt in
495495 uctxt { definitions = ctxt' }
496496
497−lookupTy :: Name -> Context -> Maybe Type
498−lookupTy n ctxt = do def <- lookupCtxt n (definitions ctxt)
497+lookupTy :: Maybe Name -> Name -> Context -> [Type]
498+lookupTy root n ctxt
499+ = do def <- lookupCtxt root n (definitions ctxt)
499500 case def of
500501 (Function (Fun ty _ _ _)) -> return ty
501502 (TyDecl _ ty _) -> return ty
502503 (Operator ty _ _) -> return ty
503504 (CaseOp _ ty _ _ _) -> return ty
504505
505−lookupP :: Name -> Context -> Maybe Term
506−lookupP n ctxt
507− = do def <- lookupCtxt n (definitions ctxt)
506+lookupP :: Maybe Name -> Name -> Context -> [Term]
507+lookupP root n ctxt
508+ = do def <- lookupCtxt root n (definitions ctxt)
508509 case def of
509510 (Function (Fun ty _ tm _)) -> return (P Ref n ty)
510511 (TyDecl nt ty hty) -> return (P nt n ty)
511512 (CaseOp _ ty _ _ _) -> return (P Ref n ty)
512513 (Operator ty _ _) -> return (P Ref n ty)
513514
514−lookupDef :: Name -> Context -> Maybe Def
515−lookupDef n ctxt = lookupCtxt n (definitions ctxt)
515+lookupDef :: Maybe Name -> Name -> Context -> [Def]
516+lookupDef root n ctxt = lookupCtxt root n (definitions ctxt)
516517
517−lookupVal :: Name -> Context -> Maybe Value
518−lookupVal n ctxt
519− = do def <- lookupCtxt n (definitions ctxt)
518+lookupVal :: Maybe Name -> Name -> Context -> [Value]
519+lookupVal root n ctxt
520+ = do def <- lookupCtxt root n (definitions ctxt)
520521 case def of
521522 (Function (Fun _ _ _ htm)) -> return htm
522523 (TyDecl nt ty hty) -> return (VP nt n hty)