1{-# LANGUAGE PatternGuards #-}
3module Idris.Transforms where
9data TTOpt = TermTrans (TT Name -> TT Name) -- term transform
10 | CaseTrans (SC -> SC) -- case expression transform
12class Transform a where
13 transform :: TTOpt -> a -> a
15instance Transform (TT Name) where
16 transform o@(TermTrans t) tm = trans t tm where
17 trans t (Bind n b tm) = t $ Bind n (transform o b) (trans t tm)
18 trans t (App f a) = t $ App (trans t f) (trans t a)
22instance Transform a => Transform (Binder a) where
23 transform t (Let ty v) = Let (transform t ty) (transform t v)
24 transform t b = b { binderTy = transform t (binderTy b) }
26instance Transform SC where
27 transform o@(CaseTrans t) sc = trans t sc where
28 trans t (Case n alts) = t (Case n (map (transform o) alts))
30 transform o@(TermTrans t) sc = trans t sc where
31 trans t (Case n alts) = Case n (map (transform o) alts)
32 trans t (STerm tm) = STerm (t tm)
35instance Transform CaseAlt where
36 transform o (ConCase n i ns sc) = ConCase n i ns (transform o sc)
37 transform o (ConstCase c sc) = ConstCase c (transform o sc)
38 transform o (DefaultCase sc) = DefaultCase (transform o sc)
40natTrans = [TermTrans zero, TermTrans suc, CaseTrans natcase]
42zname = NS (UN "O") ["Nat","Prelude"]
43sname = NS (UN "S") ["Nat","Prelude"]
45zero :: TT Name -> TT Name
46zero (P _ n _) | n == zname
50suc :: TT Name -> TT Name
51suc (App (P _ s _) a) | s == sname
52 = mkApp (P Ref (UN "prim__addBigInt") Erased) [Constant (BI 1), a]
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