hare haskell refactorer
play

HaRe: Haskell Refactorer Advanced Functional Programming - mini-talk - PowerPoint PPT Presentation

HaRe: Haskell Refactorer Advanced Functional Programming - mini-talk Tom Lokhorst 25 `feb` 2008 HaRe Haskell Refactorer 0.3 Refactoring Functional Programs project Computing Laboratory, University of Kent Simon


  1. HaRe: Haskell Refactorer Advanced Functional Programming - mini-talk λ Tom Lokhorst → 25 `feb` 2008

  2. HaRe • Haskell Refactorer 0.3 • ‘Refactoring Functional Programs’ project • Computing Laboratory, University of Kent • Simon Thomson, Claus Reinke, Huiqing Li • From October 2003 to April 2005 • Emacs & Vi bindings

  3. Refactoring • “Controlled technique for improving the design of an existing code base” • Series of small, behavior- preserving transformations, each of which “too small to be worth doing” • Popular in OO / XP worlds

  4. Refactoring demo

  5. Generalize definition

  6. Generalize definition

  7. Generalize definition

  8. Generalize definition

  9. Rename identifier

  10. Rename identifier

  11. Rename identifier

  12. Introduce new definition

  13. Introduce new definition

  14. Introduce new definition

  15. Lift to top level

  16. Lift to top level

  17. Common issues • More than indentation control or textual search-and-replace • Preserve program functionality • Refactorings might only be valid under certain side-conditions

  18. Common issues • More than indentation control or textual search-and-replace • Preserve program functionality • Refactorings might only be valid under certain side-conditions showAll = table . map show where format = ... table = concat . format

  19. Common issues • More than indentation control or textual search-and-replace • Preserve program functionality • Refactorings might only be valid under certain side-conditions showAll = table . map show showAll = table format . map show where where format = ... format = ... table = concat . format table format = concat . format

  20. Requirements • Tool needs to be: • aware of static semantics of the program • have knowledge of free variables • have access to type information • able to access multiple files

  21. Requirements (con’d) • Integration with existing development environments • Layout style must not be changed, and maintained after transformations • Comments need to be retained (and maybe even updated)

  22. HaRe architecture • Gathering semantic information: • Programatica [extended] • Analyses / program transformations: • Strafunski • Interaction / integration: • Text based: Emacs & Vi • API to build specific refactorings

  23. “Use abstract syntax for abstract tasks, concrete syntax for concrete tasks; AST auxiliary, not intermediate representation; concrete updates on token stream”

  24. HaRe architecture old Program AST AST Parser Refactorer Pretty � printer source

  25. HaRe architecture new Program source Lexer (pass1) Lexer (pass1) Parser + Lexer Token Stream AST Refactorer +pretty � printer Token Stream AST AST Token Stream Printer AST Updater Token Stream Lexer Program source

  26. Building a refactoring if isApproaching monster then runAway else investigate

  27. Building a refactoring if isApproaching monster case isApproaching monster of then runAway True -> runAway else investigate False -> investigate

  28. module RefacCase (ifToCase) where import RefacUtils ifToCase fileName beginPos endPos = do (_, _, mod,ts) <- parseSourceFile fileName -- mod: the AST; ts: the token stream. let exp = locToExp beginPos endPos mod ts case exp of (Exp (HsIf _ _ _)) -> do r <- applyRefac (worker exp) (Just(mod,ts)) fileName writeRefactoredFiles False [r] _ -> error "You haven’t selected a conditional expr!" where worker exp = applyTP (once_buTP (failTP ‘adhocTP‘ inExp)) where inExp exp1@((Exp (HsIf e e1 e2))::HsExpP) | sameOccurrence exp exp1 = let newExp = Exp (HsCase e [HsAlt loc0 (nameToPat "True") (HsBody e1) [], HsAlt loc0 (nameToPat "False")(HsBody e2) []]) in update exp1 newExp exp1 inExp _ = mzero

  29. Conclussions • Lots of refactorings available • Lots of papers pulished • Interesting architecture • Too bad it doesn’t work...

  30. More about HaRe • http://www.cs.kent.ac.uk/projects/refactor-fp/ • Paper: “Tool Support for Refactoring Functional Programs”

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend