lab2 - Getting Familiar with Haskell& Ghci CIS 252 h...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Getting Familiar with Haskell & Ghci CIS 252 h Introduction to Computer Science You may work singly or in pairs on this lab: If you work with a partner, turn in a single solution with both names on it. 1 Overview This lab is intended to make you comfortable enough with the Ghci environ- ment (= Haskell + Ghci + Emacs) so that you can use it successfully for the rest of the semester. Running Ghci from inside Emacs has the following benefits: • Emacs’s Haskell-mode provides semi-automatic indenting of Haskell, which helps in writing code that meets Haskell’s layout rules. Proper in- dentation is critical for getting your programs to run correctly. Good formating and indentation also makes your code easier to read (for both you and your grader). • It gives you an easy way of calling up and editing previous commands to Ghci. This makes correcting errors in your code significantly less painful, because you don’t have to retype the entire expression again. • It provides a simple (but handy) integrated environment for editing and running Haskell programs. Conventions: Throughout the text of this lab, underlining (as in C-x ) denotes Emacs commands or keys. Text in blue (as in simple 4 5 ) denotes code or Emacs file/buffer names. Text in red (as in Int ) denotes a Haskell type. In regards to Emacs commands, suppose ♥ is a particular character: C- ♥ means hold the CONTROL-key while typing the character ♥ . So, C-g would be: hold the CONTROL-key while typing g. M- ♥ means hold the META-key or ALT-key down while typing ♥ . If your key- board does not have a META-key or ALT-key, instead press and release the ESC-key and then type ♥ . For more detail on Emacs than provided in this lab: Start up Emacs, go to Emacs’s Help menu, select Emacs Tutorial , and follow the directions. Also see http://www.cis.syr.edu/courses/cis252/links.html#emacs for general emacs information. 2 Editing and Saving Haskell Programs Start up Emacs from the Unix command line by typing the following: emacs & ←- From the initial *scratch* buffer, enter Haskell-editing mode ( M-x haskell-mode ): the mode-line at the bottom of your Emacs win- dow/frame should now indicate that you’re in Haskell mode. (If there is other text in your *scratch* buffer, delete it now before continuing.) Type the follow- ing text into the *scratch* buffer: simple :: Int -> Int -> Int simple a b = a + 3*b Before continuing, write the buffer to the file lab2.hs ( C-x C-w ), and the buffer will now be labeled as lab2.hs . 2.1 Simple Equations The first line of simple is a type declaration (also known as a type signature): it declares simple to be a function that takes two integers and returns an integer....
View Full Document

This note was uploaded on 02/19/2011 for the course CIS 325 taught by Professor Worden during the Spring '11 term at Syracuse.

Page1 / 5

lab2 - Getting Familiar with Haskell& Ghci CIS 252 h...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online