Go to: Tool Homepage - Downloads - User Guide - Examples

Step by step : Running the "expression problem" example

  1. Download the source code for this example form the download page and extract it (not in the HaRe directory).
    In the following, we consider EXAMPLE is the directory containing the examples files (for instance /local/Expression_Problem) and HARE is the directory containing HaRe (for instance /local/HaRe_28062010)
  2. You should have 6 Haskell files (.hs) and (at least) 2 Emacs-Lisp files (.el). Open them in Emacs.
  3. Set haskell-refac-mode in Emacs ('ESC-X' means press 'Esc' or any corresponding key depending on your keyboard layout, release it and press 'x'; 'RETURN' means press the carriage return and release it) .
    • First, if you have not inserted the directive for loading HaRe in you .emacs file, do the following : ESC-X load file RETURN HARE/editors/Emacs/haskell-refac.el .
    • Second, activate the refactorer mode : ESC-X haskell-refac-mode .
  4. The first time you run this example, you have to create a HaRe project.
    • Select Client.hs as the active buffer in Emacs.
    • In Emacs Refactor menu, select Projects>New project.
    • In Emacs Refactor menu, select Projects>Chase imports. Now all the files needed for refactoring this project are included, but we have to add two additional empty modules that are needed in the target architecture.
    • Select ConstMod.hs as the current active buffer. Then activate the refactoring mode (ESC-X haskell-refac-mode). Then select Refactor>Projects>Add file.
    • Do the same with the file AddMod.hs.
  5. Launch the transformation : from the buffer containing transfo_pfun_pdata.el do ESC-X evaluate-buffer. If you have multiple emacs windows, you should observe the program being transformed. After a while, the transformation stops and the resulting program is in the data-centered architecture. You can check it compiles :
     ghc --make Client.hs
  6. You may launch the reverse transformation : select the buffer for transfo_pdata_pfun.el and do ESC-X eval-buffer. The result program is the same as the initial one (except for some layout, comments and parenthesis).

Basic use of the refactorer

1. Open in Emacs an Haskell file.

2. Load the file describing HaRe in Emacs : ESC-x load-file RETURN and type HAREPATH/editors/Emacs/haskell-refac.el where HAREPATH is the directory containing the refactorer source code (for instance, /local/HaRe_28062010 ). Note that this can be done automatically at Emacs startup by editing your Emacs config file.

3. Activate the HaRe mode in emacs : ESC-x haskell-refac-mode RETURN

4. Create a “HaRe project” containing the files of your program. First click in Refactor>Projects>New Project. Then add the other files in the project, by one of the two following methods.

  • Open each file of the project in Emacs, then for each file put Emacs in the haskell-refac-mode, and then click in Refactor>Project>Add file.
  • If the main file of the program is in the project click in Refactor>Project>Chase Imports.

You need also to call Refactor>Project>Chase imports to include the Haskell library files in the project.

5. You may need to set an Emacs variable for the chase imports operation (see HaRe README). You can use the refactorer. Most operation need that you select a sub-expression or place the cursor at the beginning of an identifier before you call the operation from the Refactorer menu.

6. For some operations, we provide an additional interface (menu Name-based operations) that do not need you to select a region of the file, but prompt you for the names of the function you want to refactor. This interface is the one that is used to build restructuring transformations.

Using Restructuring Transformations

A structure transformation is a sequence of refactoring operations. Instead of using the Emacs menu to interactively run the sequence of operations, we record the sequence of refactoring operations into an emacs-lisp file.

The following gives instruction to run an example of restructuring transformation with our system.

1. Download the archive with the sources of the example from download and extract it. This archive contains an example of Haskell program and the transformation scripts.

2. Run Emacs and open the extracted Haskell files.

3. Create an HaRe project (see instructions in the previous section) containing the 6 files of the program (two of these files are not imported by other modules and cannot be “chased”, they have to be added by the Refactor>Projects>Add file menu). This is done only once for each program.

4. Open the emacs-lisp file transformation_pfun_pdata in emacs. This file contains the sequence of operations defining the transformation of the inital program (operation-centered) and a data-centered version of it.

5. While the buffer with the emacs-lisp program is the active buffer, type ESC-x evaluate-buffer. If you have sub-windows showing the Haskell program, you should see the sequence of recatorings beeing performed and, after a while, you get the program in the data-centered architecture.

6. (OPTIONAL) You may also run the transformation step-by-step by selecting a part of the code in the buffer containing the transformation code, and doing ESC-x evaluate-region. You can also edit the script file to experiment with the transformation.

Reference for Operations

See the list of operations available in View Switcher.

internet/view_switcher/documentation.txt · Last modified: 2011/04/18 13:56 by cohen-j