1{-# LANGUAGE PatternGuards #-}
2module Idris.Elab.Transform where
14import Idris.Primitives
16import Idris.PartialEval
18import Idris.Output (iputStrLn, pshow, iWarn)
21import Idris.Elab.Utils
24import Idris.Core.Elaborate hiding (Tactic(..))
25import Idris.Core.Evaluate
26import Idris.Core.Execute
27import Idris.Core.Typecheck
28import Idris.Core.CaseTree
30import Idris.Docstrings
32import Prelude hiding (id, (.))
33import Control.Category
35import Control.Applicative hiding (Const)
38import Control.Monad.State.Strict as State
43import qualified Data.Map as Map
44import qualified Data.Set as S
45import qualified Data.Text as T
46import Data.Char(isLetter, toLower)
47import Data.List.Split (splitOn)
49import Util.Pretty(pretty, text)
51elabTransform :: ElabInfo -> FC -> Bool -> PTerm -> PTerm -> Idris (Term, Term)
52elabTransform info fc safe lhs_in@(PApp _ (PRef _ tf) _) rhs_in
53 = do ctxt <- getContext
55 let lhs = addImplPat i lhs_in
56 ((lhs', dlhs, []), _) <-
57 tclift $ elaborate ctxt (sMN 0 "transLHS") infP []
58 (erun fc (buildTC i info ELHS [] (sUN "transform")
60 let lhs_tm = orderPats (getInferTerm lhs')
61 let lhs_ty = getInferType lhs'
62 let newargs = pvars i lhs_tm
64 (clhs_tm, clhs_ty) <- recheckC fc [] lhs_tm
65 logLvl 3 ("Transform LHS " ++ show clhs_tm)
66 let rhs = addImplBound i (map fst newargs) rhs_in
68 tclift $ elaborate ctxt (sMN 0 "transRHS") clhs_ty []
71 erun fc (build i info ERHS [] (sUN "transform") rhs)
72 erun fc $ psolve lhs_tm
74 return (runState (collectDeferred Nothing tt) []))
75 (crhs_tm, crhs_ty) <- recheckC fc [] rhs'
76 logLvl 3 ("Transform RHS " ++ show crhs_tm)
77 -- Types must always convert
78 case converts ctxt [] clhs_ty crhs_ty of
80 Error e -> ierror (At fc (CantUnify False clhs_tm crhs_tm e [] 0))
81 -- In safe mode, values must convert (Thinks: This is probably not
82 -- useful as is, perhaps it should require a proof of equality instead)
83 when safe $ case converts ctxt [] clhs_tm crhs_tm of
85 Error e -> ierror (At fc (CantUnify False clhs_tm crhs_tm e [] 0))
87 case unApply (depat clhs_tm) of
88 (P _ tfname _, _) -> do addTrans tfname (clhs_tm, crhs_tm)
89 addIBC (IBCTrans tf (clhs_tm, crhs_tm))
90 _ -> ierror (At fc (Msg "Invalid transformation rule (must be function application)"))
91 return (clhs_tm, crhs_tm)
94 depat (Bind n (PVar t) sc) = depat (instantiate (P Bound n t) sc)
97elabTransform info fc safe lhs_in rhs_in
98 = ierror (At fc (Msg "Invalid transformation rule (must be function application)"))
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