{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

2_R Chapter5-IntroToHaskell

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

Info icon This preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Image of page 1

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

View Full Document Right Arrow Icon
PART 2 Static Types
Image of page 2
Image of page 3

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

View Full Document Right Arrow Icon
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 (O’Reilly, 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
Image of page 4
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> is the value of the expression, serialized as a string. The second line of output is a bit cryptic:
Image of page 5

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

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern