rec01 - Recitation 1 Introduction to OCaml Syntax We will...

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

View Full Document Right Arrow Icon
Recitation 1: Introduction to OCaml Syntax We will use the Objective Caml (OCaml) programming language this semester. OCaml is a functional language rather than a procedural language; the key difference between these two classes of languages is the execution model ---the way in which programs are executed. Procedural (or imperative ) languages, such as C and Java, are based on commands that change the state of the machine on which they execute. For example, the assignment statement (in both C and Java) explicitly changes the value stored in some memory location. Functional languages, in contrast, are based on evaluating expressions to produce values. OCaml provides good ways to build correct, understandable, and large expressions. The focus of this lecture is understanding expressions. For real applications, programming with expressions may seem like a stretch. After all, applications often do not "compute" anything; instead, they allow you to "do" something. Later in the course, we will introduce the notion of side-effects : evaluate this , and do that while you're at it---e.g., evaluate an expression, and (as a side-effect) display a window on the screen. But for the moment, we will live in a pure world, one without side-effects. To start learning OCaml, you should begin playing with the OCaml language by writing toy expressions. Like most programming languages, Ocaml has a compiler that can be run on source files to produce object files. But to really understand expressions, there is a better way to interact with the OCaml compiler, called the OCaml toplevel system . This system is something like a very fancy calculator---you interact with it by typing in an expression, and it responds by evaluating that expression and telling you the resulting value. IMPORTANT NOTE : In previous semesters, this course has been taught in SML, a language very similar to OCaml. They share both a common origin and almost all of their syntax, but OCaml is currently better supported than SML, and looks to have better support in the future as well. OCaml also has better secondary features, such as debugging. We will try to update recitation and lecture notes to use the correct OCaml syntax as we cover material, but we may miss things. If we do miss things, don't panic. For aid in understanding notes from previous years or notes that may not have been updated, you may wish to consult the SML vs. OCaml page, which provides a detailed list of the differences between the two. Again, the two languages are very similar: for most of the standard syntax, almost everything is the same except the keywords. With a good understanding of OCaml, it is easy to understand SML. Starting the OCaml toplevel system. You can find current releases of OCaml at the OCaml home page . Once you have OCaml properly installed, you will be able to start an interactive session by typing
Background image of page 1

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

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

{[ snackBarMessage ]}

Page1 / 5

rec01 - Recitation 1 Introduction to OCaml Syntax We will...

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