on master help sign in
Some fixes for adding declarations in wheres

:addclause needs to know how many arguments are parameters so that they don't get printed :addmissing now indents (but still prints too many arguments)

commitc1de41c4f670fc77c2dd0116fcac84f12e59cb0e authorEdwin Brady <ecb10@st-andrews.ac.uk> dateFri 1 Nov 2013, 17:49 (13 years ago) parent92d3d7e
2 files changed+23−7
src/Idris/ElabDecls.hs+11−2 src/Idris/REPL.hs+12−5
src/Idris/ElabDecls.hs+11−2
@@ -77,8 +77,8 @@ elabType info syn doc fc opts n ty' = {- let ty' = piBind (params info) ty_in
7777 let nty' = normalise ctxt [] nty
7878
7979 -- Add normalised type to internals
80− addInternalApp (fc_fname fc) (fc_line fc) (delab i nty')
81− addIBC (IBCLineApp (fc_fname fc) (fc_line fc) (delab i nty'))
80+ addInternalApp (fc_fname fc) (fc_line fc) (mergeTy ty' (delab i nty'))
81+ addIBC (IBCLineApp (fc_fname fc) (fc_line fc) (mergeTy ty' (delab i nty')))
8282
8383 let (t, _) = unApply (getRetTy nty')
8484 let corec = case t of
@@ -98,6 +98,15 @@ elabType info syn doc fc opts n ty' = {- let ty' = piBind (params info) ty_in
9898 addIBC (IBCCoercion n)
9999 when corec $ do setAccessibility n Frozen
100100 addIBC (IBCAccess n Frozen)
101+ where
102+ -- for making an internalapp, we only want the explicit ones, and don't
103+ -- want the parameters, so just take the arguments which correspond to the
104+ -- user declared explicit ones
105+ mergeTy (PPi e n ty sc) (PPi e' _ _ sc')
106+ | e == e' = PPi e n ty (mergeTy sc sc')
107+ | otherwise = mergeTy sc sc'
108+ mergeTy _ sc = sc
109+
101110
102111elabPostulate :: ElabInfo -> SyntaxInfo -> String ->
103112 FC -> FnOpts -> Name -> PTerm -> Idris ()
src/Idris/REPL.hs+12−5
@@ -590,12 +590,14 @@ process h fn (AddProofClauseFrom updatefile l n)
590590process h fn (AddMissing updatefile l n)
591591 = do src <- runIO $ readFile fn
592592 let (before, tyline : later) = splitAt (l-1) (lines src)
593+ let indent = getIndent 0 (show n) tyline
593594 i <- getIState
594595 cl <- getInternalApp fn l
595596 let n' = getAppName cl
597+
596598 extras <- case lookupCtxt n' (idris_patdefs i) of
597599 [] -> return ""
598− [(_, tms)] -> showNew (show n ++ "_rhs") 1 tms
600+ [(_, tms)] -> showNew (show n ++ "_rhs") 1 indent tms
599601 let (nonblank, rest) = span (not . all isSpace) (tyline:later)
600602 if updatefile then
601603 do let fb = fn ++ "~"
@@ -616,12 +618,17 @@ process h fn (AddMissing updatefile l n)
616618 getAppName (PRef _ r) = r
617619 getAppName _ = n
618620
619− showNew nm i (tm : tms)
621+ showNew nm i ind (tm : tms)
620622 = do (nm', i') <- getUniq nm i
621− rest <- showNew nm i' tms
622− return (showPat tm ++ " = ?" ++ nm' ++
623+ rest <- showNew nm i' ind tms
624+ return (replicate ind ' ' ++
625+ showPat tm ++ " = ?" ++ nm' ++
623626 "\n" ++ rest)
624− showNew nm i [] = return ""
627+ showNew nm i _ [] = return ""
628+
629+ getIndent i n [] = 0
630+ getIndent i n xs | take (length n) xs == n = i
631+ getIndent i n (x : xs) = getIndent (i + 1) n xs
625632
626633process h fn (MakeWith updatefile l n)
627634 = do src <- runIO $ readFile fn