2_R Chapter5-IntroToHaskell

2_R Chapter5-IntroToHaskell - PART 2 Static Types 5 Haskell...

Info iconThis preview shows pages 1–6. 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

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

View Full DocumentRight 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: PART 2 Static Types 5 Haskell Haskell is a lazy, functional programming language that was initially designed by a committee in the eighties and nineties. In contrast to many programming languages, it is lazy , meaning that expressions are evaluated when their values are needed, rather than when they are first encountered. It is functional , meaning that the main organizational construct in the language is the function, rather than a procedure or a class hierarchy. Studying Haskell is useful for a number of reasons. First, studying a functional language will make you think differently about programming. Mainstream lan- guages are all about manipulating mutable state, whereas functional languages are all about manipulating values . Understanding the difference will make you a better programmer in whatever language you regularly use. Second, Haskell serves as a good example of many of the topics we will be covering later in the book, particu- larly issues related to type systems. Finally, the Haskell language is at the forefront of language design, with many new research papers published each year about ex- tensions to the language. Haskell thus provides a glimpse as to where mainstream languages may be going in the future. Because we will use Haskell in various chapters of the book to illustrate proper- ties of programming languages, we will study Haskell in a little more detail than we will study some other languages. Compilers for Haskell are available on the Inter- net without charge. Several books and manuals covering the language are available. In addition to on-line sources easily located by web search, Real World Haskell (OReilly, 2009) is a good reference. 5.1 INTERACTIVE SESSIONS AND THE RUN-TIME SYSTEM In addition to providing standard batch compilation, most Haskell compilers pro- vide the same kind of read-eval-print loop as many Lisp implementations. In this mode of use, programmers enter expressions and declarations one at a time. As each is entered, the source code is type checked, compiled, and executed. Once an identifier has been given a value by a declaration, that identifier can be used in subsequent expressions. 95 96 Haskell The program that implements the read-eval-print loop is often called a shell or an interpreter, even though the code is actually compiled. Such shells are useful for interactively experimenting with code and can function as debuggers. We will use such a shell to explore various features of Haskell. 5.1.1 Expressions For expressions, user interaction with the Haskell shell has the form Prelude> <expression> <print value> it :: <type> where Prelude> is the prompt for user input (The word Prelude indicates that only the standard prelude module has been loaded). The second two lines are output from the Haskell compiler and run-time system. These lines illustrate that if an expression is entered, the shell will compile the expression and evaluate it. The first line of the output <print value>...
View Full Document

This note was uploaded on 03/08/2011 for the course CS 242 at Stanford.

Page1 / 27

2_R Chapter5-IntroToHaskell - PART 2 Static Types 5 Haskell...

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

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