Skip to content

Commit 80447c1

Browse files
committed
[ cleanup ] Simplify Impossible.mkTerm signature
1 parent 3db1009 commit 80447c1

File tree

1 file changed

+38
-34
lines changed

1 file changed

+38
-34
lines changed

src/TTImp/Impossible.idr

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ mutual
7474
Core ClosedTerm
7575
-- unnamed takes priority
7676
processArgs con fn (NBind fc x (Pi _ _ Explicit ty) sc) (e :: exps) autos named
77-
= do e' <- mkTerm e (Just ty) [] [] []
77+
= do e' <- mkTerm e (Just ty)
7878
defs <- get Ctxt
7979
processArgs con (App fc fn e')
8080
!(sc defs (toClosure defaultOpts Env.empty e'))
@@ -83,7 +83,7 @@ mutual
8383
= do defs <- get Ctxt
8484
case findNamed x named of
8585
Just ((_, e), named') =>
86-
do e' <- mkTerm e (Just ty) [] [] []
86+
do e' <- mkTerm e (Just ty)
8787
processArgs con (App fc fn e')
8888
!(sc defs (toClosure defaultOpts Env.empty e'))
8989
[] autos named'
@@ -99,15 +99,15 @@ mutual
9999
!(sc defs (toClosure defaultOpts Env.empty e'))
100100
exps autos named
101101
Just ((_, e), named') =>
102-
do e' <- mkTerm e (Just ty) [] [] []
102+
do e' <- mkTerm e (Just ty)
103103
processArgs con (App fc fn e')
104104
!(sc defs (toClosure defaultOpts Env.empty e'))
105105
exps autos named'
106106
processArgs con fn (NBind fc x (Pi _ _ AutoImplicit ty) sc) exps autos named
107107
= do defs <- get Ctxt
108108
case autos of
109109
(e :: autos') => -- unnamed takes priority
110-
do e' <- mkTerm e (Just ty) [] [] []
110+
do e' <- mkTerm e (Just ty)
111111
processArgs con (App fc fn e')
112112
!(sc defs (toClosure defaultOpts Env.empty e'))
113113
exps autos' named
@@ -119,7 +119,7 @@ mutual
119119
!(sc defs (toClosure defaultOpts Env.empty e'))
120120
exps [] named
121121
Just ((_, e), named') =>
122-
do e' <- mkTerm e (Just ty) [] [] []
122+
do e' <- mkTerm e (Just ty)
123123
processArgs con (App fc fn e')
124124
!(sc defs (toClosure defaultOpts Env.empty e'))
125125
exps [] named'
@@ -166,35 +166,39 @@ mutual
166166
{auto s : Ref Syn SyntaxInfo} ->
167167
{auto q : Ref QVar Int} ->
168168
RawImp -> Maybe ClosedClosure ->
169-
(expargs : List RawImp) ->
170-
(autoargs : List RawImp) ->
171-
(namedargs : List (Name, RawImp)) ->
172169
Core ClosedTerm
173-
mkTerm (IVar fc n) mty exps autos named
174-
= buildApp fc n mty exps autos named
175-
mkTerm (IAs fc fc' u n pat) mty exps autos named
176-
= mkTerm pat mty exps autos named
177-
mkTerm (IApp fc fn arg) mty exps autos named
178-
= mkTerm fn mty (arg :: exps) autos named
179-
mkTerm (IWithApp fc fn arg) mty exps autos named
180-
= mkTerm fn mty (arg :: exps) autos named
181-
mkTerm (IAutoApp fc fn arg) mty exps autos named
182-
= mkTerm fn mty exps (arg :: autos) named
183-
mkTerm (INamedApp fc fn nm arg) mty exps autos named
184-
= mkTerm fn mty exps autos ((nm, arg) :: named)
185-
mkTerm (IMustUnify fc r tm) mty exps autos named
186-
= Erased fc . Dotted <$> mkTerm tm mty exps autos named
187-
mkTerm (IPrimVal fc c) _ _ _ _ = pure (PrimVal fc c)
188-
-- We're taking UniqueDefault here, _and_ we're falling through to nextVar otherwise, which is sketchy.
189-
-- On option is to try each and emit an AmbiguousElab? We maybe should respect `UniqueDefault` if there
190-
-- is no evidence (mty), but we should _try_ to resolve here if there is an mty.
191-
mkTerm (IAlternative _ (UniqueDefault tm) _) mty exps autos named
192-
= mkTerm tm mty exps autos named
193-
mkTerm (Implicit fc _) _ _ _ _ = nextVar fc
194-
mkTerm (IBindVar fc _) _ _ _ _ = nextVar fc
195-
mkTerm tm _ _ _ _
196-
= do tm' <- pterm (map defaultKindedName tm) -- hack
197-
throw $ GenericMsg (getFC tm) "Unsupported term in impossible clause: \{show tm'}"
170+
mkTerm tm mty = go tm [] [] []
171+
where
172+
go : RawImp ->
173+
(expargs : List RawImp) ->
174+
(autoargs : List RawImp) ->
175+
(namedargs : List (Name, RawImp)) ->
176+
Core ClosedTerm
177+
go (IVar fc n) exps autos named
178+
= buildApp fc n mty exps autos named
179+
go (IAs fc fc' u n pat) exps autos named
180+
= go pat exps autos named
181+
go (IApp fc fn arg) exps autos named
182+
= go fn (arg :: exps) autos named
183+
go (IWithApp fc fn arg) exps autos named
184+
= go fn (arg :: exps) autos named
185+
go (IAutoApp fc fn arg) exps autos named
186+
= go fn exps (arg :: autos) named
187+
go (INamedApp fc fn nm arg) exps autos named
188+
= go fn exps autos ((nm, arg) :: named)
189+
go (IMustUnify fc r tm) exps autos named
190+
= Erased fc . Dotted <$> go tm exps autos named
191+
go (IPrimVal fc c) _ _ _ = pure (PrimVal fc c)
192+
-- We're taking UniqueDefault here, _and_ we're falling through to nextVar otherwise, which is sketchy.
193+
-- On option is to try each and emit an AmbiguousElab? We maybe should respect `UniqueDefault` if there
194+
-- is no evidence (mty), but we should _try_ to resolve here if there is an mty.
195+
go (IAlternative _ (UniqueDefault tm) _) exps autos named
196+
= go tm exps autos named
197+
go (Implicit fc _) _ _ _ = nextVar fc
198+
go (IBindVar fc _) _ _ _ = nextVar fc
199+
go tm _ _ _
200+
= do tm' <- pterm (map defaultKindedName tm) -- hack
201+
throw $ GenericMsg (getFC tm) "Unsupported term in impossible clause: \{show tm'}"
198202

199203
-- Given an LHS that is declared 'impossible', build a term to match from,
200204
-- so that when we build the case tree for checking coverage, we take into
@@ -206,7 +210,7 @@ getImpossibleTerm : {vars : _} ->
206210
Env Term vars -> NestedNames vars -> RawImp -> Core ClosedTerm
207211
getImpossibleTerm env nest tm
208212
= do q <- newRef QVar (the Int 0)
209-
mkTerm (applyEnv tm) Nothing [] [] []
213+
mkTerm (applyEnv tm) Nothing
210214
where
211215
addEnv : {vars : _} ->
212216
FC -> Env Term vars -> List RawImp

0 commit comments

Comments
 (0)