1{-# LANGUAGE GeneralizedNewtypeDeriving #-}
2module Rename (rename) where
5import Control.Arrow (first)
6import Control.Monad (ap, liftM, foldM, mapM, Monad)
7import Control.Monad.State (evalState, State, get, put)
8import Data.Char (isLower)
12rename = run . rename' id
14rename' :: (String -> String) -> Expr -> GuidCounter Expr
18 Range e1 e2 -> Range `liftM` rnm e1
21 Access e x -> Access `liftM` rnm e
24 Binop op@(h:_) e1 e2 ->
25 let rop = if isLower h || '_' == h
28 in Binop rop `liftM` rnm e1
32 (rx, env') <- extend env x
33 Lambda rx `liftM` rename' env' e
35 App e1 e2 -> App `liftM` rnm e1
38 If e1 e2 e3 -> If `liftM` rnm e1
42 Lift e es -> Lift `liftM` rnm e
45 Fold e1 e2 e3 -> Fold `liftM` rnm e1
49 Async e -> Async `liftM` rnm e
52 let (vs,es) = unzip defs
53 env' <- foldM (\acc x -> snd `liftM` extend acc x) env vs
54 es' <- mapM (rename' env') es; re <- rename' env' e
55 return $ Let (zip (map env' vs) es') re
57 Var x -> return . Var $ env x
59 Data name es -> Data name `liftM` mapM rnm es
61 Case e cases -> Case `liftM` rnm e
62 `ap` mapM (patternRename env) cases
66 where rnm = rename' env
68extend :: (String -> String) -> String -> GuidCounter (String, String -> String)
71 let rx = x ++ "_" ++ show n
72 return (rx, \y -> if y == x then rx else env y)
74patternExtend :: Pattern -> (String -> String) -> GuidCounter (Pattern, String -> String)
75patternExtend pattern env =
77 PAnything -> return (PAnything, env)
78 PVar x -> first PVar `liftM` extend env x
80 first (PData name . reverse) `liftM` foldM f ([], env) ps
81 where f (rps,env') p = do (rp,env'') <- patternExtend p env'
82 return (rp:rps, env'')
84patternRename :: (String -> String) -> (Pattern, Expr) -> GuidCounter (Pattern, Expr)
85patternRename env (p,e) = do
86 (rp,env') <- patternExtend p env
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