0 | module TTImp.Interactive.Intro
8 | import Idris.REPL.Opts
13 | import TTImp.Elab.Check
18 | import Libraries.Data.NatSet
24 | {auto c : Ref Ctxt Defs}
25 | {auto s : Ref Syn SyntaxInfo}
26 | {auto m : Ref MD Metadata}
27 | {auto u : Ref UST UState}
28 | {auto r : Ref ROpts REPLOpts}
31 | (env : Env Term lhsCtxt)
33 | introLam : Name -> RigCount -> Term lhsCtxt -> Core IRawImp
34 | introLam x rig ty = do
37 | new_hole <- uniqueHoleName defs [] (nameRoot hole)
38 | let iintrod = ILam replFC rig Explicit (Just x) ty (IHole replFC new_hole)
41 | introCon : Name -> Term lhsCtxt -> Core (List IRawImp)
45 | Just gdef <- lookupCtxtExact n (gamma defs)
48 | let TCon _ _ _ _ _ cs _ = definition gdef
50 | let gty = gnf env ty
51 | ics <- for (fromMaybe [] cs) $
\ cons => do
52 | Just gdef <- lookupCtxtExact cons (gamma defs)
54 | let nargs = lengthExplicitPi $
fst $
snd $
underPis (-
1) Env.empty (type gdef)
55 | new_hole_names <- uniqueHoleNames defs nargs (nameRoot hole)
56 | let new_holes = PHole replFC True <$> new_hole_names
57 | let pcons = papply replFC (PRef replFC cons) new_holes
60 | icons <- desugar AnyExpr (toList lhsCtxt) pcons
61 | ccons <- checkTerm hidx InExpr [] (MkNested []) env icons gty
63 | ncons <- normaliseHoles newdefs env ccons
64 | icons <- unelab env ncons
66 | (\ _ => pure Nothing)
70 | pure (catMaybes ics)
73 | intro : Term lhsCtxt -> Core (List IRawImp)
75 | intro (Bind _ x (Let _ _ ty val) sc) = toList <$> intro (subst val sc)
76 | intro (TDelayed _ _ t) = intro t
78 | intro (Bind _ x (Pi _ rig Explicit ty) _) = pure <$> introLam x rig ty
79 | intro t = case getFnArgs t of
80 | (Ref _ (TyCon ar) n, _) => introCon n t