2Module : Idris.ErrReverse
3Description : Utility to make errors readable using transformations.
6Maintainer : The Idris Community.
8{-# LANGUAGE PatternGuards #-}
10module Idris.ErrReverse(errReverse) where
13import Idris.Core.Evaluate (unfold)
18-- | For display purposes, apply any 'error reversal' transformations
19-- so that errors will be more readable,
20-- and any 'error reduce' transformations
21errReverse :: IState -> Term -> Term
22errReverse ist t = rewrite 5 (do_unfold t) -- (elideLambdas t)
24 do_unfold :: Term -> Term
25 do_unfold t = let ns = idris_errReduce ist in
27 else unfold (tt_ctxt ist) []
28 (map (\x -> (x, 1000)) (idris_errReduce ist))
32 rewrite n t = let t' = foldl applyRule t (reverse (idris_errRev ist)) in
34 else rewrite (n - 1) t'
36 applyRule :: Term -> (Term, Term) -> Term
37 applyRule t (l, r) = applyNames [] t l r
39 -- Assume pattern bindings match in l and r (if they don't just treat
40 -- the rule as invalid and return t)
42 applyNames ns t (Bind n (PVar _ ty) scl) (Bind n' (PVar _ ty') scr)
43 | n == n' = applyNames (n : ns) t (instantiate (P Ref n ty) scl)
44 (instantiate (P Ref n' ty') scr)
46 applyNames ns t l r = matchTerm ns l r t
49 | Just nmap <- match ns l t = substNames nmap r
50 matchTerm ns l r (App s f a) = let f' = matchTerm ns l r f
51 a' = matchTerm ns l r a in
53 matchTerm ns l r (Bind n b sc) = let b' = fmap (matchTerm ns l r) b
54 sc' = matchTerm ns l r sc in
56 matchTerm ns l r t = t
58 match ns l t = do ms <- match' ns l t
61 -- If any duplicate mappings, it's a failure
64 | Just _ <- lookup x xs = Nothing
65 | otherwise = do xs' <- combine xs
68 match' ns (P Ref n _) t | n `elem` ns = Just [(n, t)]
69 match' ns (App _ f a) (App _ f' a') = do fs <- match' ns f f'
72 -- no matching Binds, for now...
73 match' ns x y = if x == y then Just [] else Nothing
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list