CSci 450-01: Organization of Programming Languages
CSci 503-01: Fundamental Concepts in Languages
Fall 2014
Lecture Notes and Web Resources
Sections
Reference Materials
Schedule, Lecture Notes, and Examples
Reference Materials
- Free online
programming language textbooks and tutorials
- Functional programming using Haskell:
Primary Haskell lecture notes and tutorials for course
- H. Conrad Cunningham.
Notes on Functional Programming with Haskell
This document is under revision during Fall 2014 and may change
frequently. Reload the page or clear the browser cache to ensure
that you see the latest version.
- Miron Lipovaca. Learn You a Haskell for Great Good: A Beginner's
Guide, online tutorial
This book is also available in print, published by No Starch Press
April 2011.
Other Haskell books
- Kees Doets and Jan van Eijck. The
Haskell Road to Logic, Math and Programming, March 2004
This book is also available in print, published by College
Publications, 2004.
- Paul Hudak. The
Haskell School of Music: From Signals to Symphonies,
Version 2.6, January 2014
This book is a recent rewrite of Hudak's The Haskell School of
Expression: Learning Functional Programming through Multimedia,
Cambridge University Press, 2000:
[source code for SOE]
- Simon Marlowe. Parallel and Concurrent Programming in Haskell: Techniques
for Multicore and Multithreaded Programming, 2013
This book is also available in print, published by O'Reilly Media
2013.
- Bryan O'Sullivan, Don Stewart, and John Goerzen. Real
World Haskell: [HTML book]
This book is also available in print, published by O'Reilly
Media November 2008.
- (book not online) Simon Thompson. Haskell: The Craft of Functional
Programming, Third Edition, Addison Wesley, 2011:
[source code]
[local copy of source code]
Other Haskell resources
- Haskel project web site
- Lua:
- (Textbook not available online) Roberto Ierusalimshcy.
Programming in Lua( PiL), Third Edition, Lua.org, Rio
de Janiero, 2013 (covers Lua 5.2)
- Course notes
by Fabio Mascarenhas for a course based on Programming in Lua
- Official Lua language site:
[download ] [documentation]
- Lua users site:
[wiki]
- Lua
Tutorial
- Love 2D game framework
- Prolog:
- Patrick Blackburn, Johan Bos, and Kristina Striegnitz. Learn Prolog
Now, online tutorial
- SWI Prolog, stable release 6.6.6, available from http://www.swi-prolog.org/
or various other repositories.
- William R. Cook. Anatomy of
Programming Languages, online draft
- Kathleen Fisher's lectures on programming languages:
[local]
- (SICP) Harold Abelson and Gerald J. Sussman with Julie
Sussman. Structure and Interpretation of Computer
Programs, Second Edition, MIT Press, 1996:
[book site at MIT Press]
[HTML book]
[SICP ebook site]
[local copy of source code]
- Shiram Krishnamurthi. Programming Languages: Application
and Interpretation, Second Edition:
[HTML]
[PDF]
[Fall 2012 course]
[Fall 2013 course]
Schedule, Lecture Notes, and Examples
- (25 Sep) Examine syllabus and discuss class organization. Separate
CSci 503 students into new meeting time (10:00 MWF, Weir 106).
- Discuss the changes in computer systems over past 70
years and their implications for programming and programming language
design.
- (27 Sep) Effect of
Computing Hardware Evolution on Programming Languages,
instructor's lecture notes
- (for reference) Nathan Ensmegner's Early History of
Computing, The Franklin Institute
- (for reference) Wikipedia article on History of Computing Hardware
- (for reference) Wikipedia article on the Timeline of Computing
- (27 Aug) Discuss Backus' Turing Award lecture excerpt in
Notes on Functional
Programming with Haskell, section 1.2, pages 2-4.
- (29 Aug) Discuss history
of programming languages over past 60 years, calling attention to
the emergence of paradigms and major languages.
See instructor's notes.
- Discuss programming paradigms
- General programming language concepts: programming language
paradigm, imperative language, declarative language, functional
language, relational or logic language, state, implicit versus
explicit state
- (29 Aug) Lecture from Notes on
Functional Programming with Haskell, section 1.3, pages
5-6
- Discuss simple factorial function example to explore
Haskell syntax and semantics.
- Background reading: Chapter 2 "Starting
Out" of Learn You a Haskell for Great Good
- (for reference) GHCi
User's Guide
- (3 Sep) Lecture from Chapter 3 of Notes on
Functional Programming with Haskell, pages 17-22
- (3 Sep) Demonstrate the GHCi (Glasgow Haskell Compiler interactive
interface) using the factorial
functions from Chapter 3.
Note: GHCi is an interactive REPL (Read-Evaluate-Print-Loop)
tool for the Haskell language.
- Discuss reasons for studying functional programming.
- General programming language concepts: referential
transparency, abstraction, first-class functions, higher-order
functions, eager versus lazy evaluation
- (5 Sep) Lecture from Section 1.4 of Notes on Functional Programming with Haskell,
pages 6-8
- Discuss basic Haskell functional programming concepts from
Chapter 5 of Notes on Functional
Programming with Haskell, pages 25-54.
- Background reading: Chapters 2, 3, 4, and 5
of Learn You a
Haskell for Great Good
- General programming language concepts: data types, lists,
recursion, pattern matching, recursive programming styles (backward,
forward, and tail recursion), accumulating parameter
- (for reference) Haskell Cheat
Sheet
- Haskell modules from Notes
Chapter 5
- (5-8 Sep) Haskell builtin data types, section 5.1, pages 25-29
- (8 Sep) Programming with list patterns, section 5.2, pages
30-34
- (10-12 Sep) Infix operators, recursive programming styles, more
list operations, and the rational arithmetic package, section 5.3-6,
pages 35-47
- (15 Sep) Standard Prelude functions
- (15 Sep) IO program to test an xor function
- (17 Sep) Live coding demonstration using exercises 6 and 8 at the end of
Chapter 5
- (19 Sep) Example rjustify function
- (19 Sep) Exponentiation function examples (backward, tail, and
logarthmic)
- (for reference) Kathleen Fisher's introductory slides on Haskell
Discuss Haskell higher-order functions from Chapter 6 of Notes on Functional Programming with
Haskell, pages 55-78.
- Background reading: Chapter 6 of Learn You a Haskell
for Great Good
- General programming language concepts: first-class functions,
higher-order functions, maps, filters, folds, strictness of
operations, Currying, partial application, combinators, functional
composition, anonymous functions (lambda expressions)
- Haskell modules from
Notes Chapter 6
- (12-15 Sep) Capturing computational patterns using higher-order
functions: Maps and filters from sections 6.1-2, pages 55-58
- (19-22 Sep) Capturing more computational patterns using
higher-order functions: folds from section 6.3, pages 58-61
- (22 Sep) Example uses of fold
functions
- (22 Sep) Higher-order function concepts and features:
Strictness and currying from sections 6.4-5, pages 61-63
- (24-26 Sep) Higher-order function concepts and features:
Operator sections, combinators, and functional composition, and lambda
expressions from sections 6.6-9, pages 64-69
- (26 Sep) Capturing more computational patterns: List-breaking
and list-combining functions, sections 6.10-11, pages 69-71
- (26 Sep) Case studies: Rational arithmetic package revisited
and cosequential processing package, sections 6.12-13, pages 72-74
Discuss Haskell sequences and comprehensions from Chapter 7
of Notes on Functional
Programming with Haskell, pages 79-84.
- Background reading: Sections "Texas ranges" and "I'm a list
comprehension" in Chapter 2 of Learn You a Haskell for Great
Good
- General programming language concepts: sequences, list
comprehensions, solve a more general problem first
- Haskell modules from Notes
Chapter 7
- (15 Sep) Discuss Haskell sequences and comprehensions from
Chapter 7 of Notes on
Functional Programming with Haskell, pages 79-82.
- (19 Sep) Discuss "first occurrence in a list" problem and
"solve a harder problem" strategy from section 7.2.6 of Notes on Functional Programming with
Haskell, page 83.
Examination 1
- (29 Sep) Covers everything to this point in the semester
(e.g. items 9-18 of this list)
- (for reference) 2010 Functional Programming exam:
[CSci 555 Exam 1]
[partial solution]
- (6 Oct) Discuss graded exam: [solution]
(1 Oct, for assignment
#3) Discuss recognizing regular expressions case study from Simon
Thompson. Haskell: The Craft of Functional Programming,
Third edition, Addison Wesley, 2011. Assignment #3 requires us to
treat functions as data.
Discuss Haskell algebraic data types and type classes.
- Background reading: Chapter 3
and Chapter 8 of Learn You a Haskell for Great Good
- General programming language concepts: types; algebraic data
types (enumerated types, tuple types, disjoint union types,
recursive types); Haskell type system concepts (type
classes, instances, overloading, inheritance) versus related
Java/C++ type system concepts (abstract and concrete classes,
objects, inheritance, interfaces)
- Haskell modules from Notes
Chapter 8
- (3, 8 Oct) Chapter 8 of Notes on
Functional Programming with Haskell, pages 85-94
- (8-10 Oct) Overloading and Type Classes
- (for reference) Kathleen Fisher's slides on Type Classes
- (for reference) Type Inference
- (for reference) Kathleen Fisher's slides on Types
(10 Oct) Discuss problem-solving techniques from Chapter 10 of
Notes on Functional Programming
with Haskell, pages 105-108.
(13 Oct) 9:00 CSci 450 class meets with ABET/CAC Program Evaluator.
10:00 CSci 503 class does not meet.
Discuss languages from Chapter 1 of William Cook's Anatomy of Programming
Languages (AoPL).
- (used below with AoPL sections) Bruno
Oliviera's slides for AoPL
- AoPL Chapter 1 concepts: language, syntax, semantics;
metaprogram; expressions, statements, side effects
- (15 Oct) Introduction to languages (pages 8-9)
(Oliveira's lecture 4 slides)
Discuss expressions, syntax, and evaluation from Chapter 2 of William Cook's Anatomy of Programming
Languages (AoPL).
- (used below with AoPL sections) Bruno
Oliviera's slides for AoPL
- AoPL Chapter 2 concepts: expression, syntax, evaluation;
concrete and abstract syntax; literal, token, identifier, grammar,
syntactic category, production rule, terminal, nonterminal,
precedence, associativity, parser generator, object language,
metalanguage
- (15 Oct) Simple language of arithmetic--abstract syntax, and
recognizing tokens in concrete syntax (pages 19-21) (Oliveira's
lecture 6 slides)
- (20 Oct) Simple language for arithmetic--concrete syntax, grammars, and
evaluation (pages 23-30) (Oliveira's lecture 6 slides)
- (for reference) Source code for simple language:
[Lexer.hs]
[Simple.hs]
[Base.hs]
[SimpleParse.y]
[SimpleTest.hs]
Discuss Section 4.1 "Compilers and Syntax" (pages
48-57) of John Mitchell's Concepts in Programming
Languages, Cambridge University Press, 2003. This handout
discusses general programming language concepts but not explicitly in
the context of Haskell or other languages.
- (17 Oct) Phases of a simple compiler (described in handout): lexical analysis, syntax
analysis, semantic analysis, intermediate code generation, code
optimization, and code generation
- (17 Oct) Other optional phases discussed (but not described in this
handout): lexical preprocessing (e.g., as in C) before lexical
analysis and assembly, linking, loading (static and dynamic), and
just-in-time compilation after code generation
- (for reference) Grammar and parse tree concepts: grammars, derivations, parse
trees, ambiguity, parsing,and precedence (This handout was not
discussed from this section but was discussed with Anatomy of
Programming Languages Chapters 2 and 3)
(22 Oct) No class because of instructor illness.
Discuss variables in the arithmetic expression language from
Chapter 3 of William Cook's Anatomy of Programming
Languages.
- (used below with AoPL sections) Bruno
Oliviera's slides for AoPL
- AoPL Chapter 3 concepts:
variable, binding, mutation, substitution, renaming, environment,
local variable, scope, unbound variable, bound variable, free
variable, static and dynamic properties
- (24, 29 Oct) Adding global and local variables to the
arithmetic expression tree (Oliveira's lecture 7, 8, 9 slides).
Discuss domain-specific languages in Haskell.
- General programming language concepts: domain-specific
languages (DSLs); DSLs versus general-urpose programming languages;
external versus internal DSLs; shallow versus deep embedding of
internal DSLs
- (27 Oct) Domain-Specific
Languages, instructor's lecture notes
- (27-29 Oct) SandwichDSL Case Study,
instructor's lecture notes (with significant revisions on 28
October)
- (29 Oct) Assignment
#4, based on the SandwichDSL case study, requires us to use Haskell
algebraic data types to implement a small deeply embedded internal
DSL.
(29 Oct) Review solutions to Assignments #2 and #3.
Examination 2
- (3 Nov) Emphasizes topics covered since Exam 1 (e.g., items
20-30 of this list) plus concepts needed for homework assignments
2-4. Of course, the Haskell language and programming concepts needed
may include anything from the beginning of the semester
- (31 Oct) 2010 Functional Programming exam:
[CSci 555 Exam 2]
[partial solution]
Note: This is only a partial model for the exam. The 555 exam
does not cover the language processing content. Only problems 1, 2,
5, and 7 are relevant to this course.
- (7 Nov) Discuss graded exam:
[partial solution]
Discuss basic Lua concepts using
Fabio Mascarenhas's
Lecture Notes, based on the Programming in Lua
textbook.
- Background reading: Chapters 1-8 of Programming in
Lua (PiL), pages 1-82
- General programming language concepts: types (static versus
dynamic, strong versus weak, duck typing); primitive data types;
scope of variables (global versus local, nested scopes, shadowing);
control constructs; functions versus procedures, side effects;
first-class and higher-order functions; closures; tail recursion
optimization
- (5-10 Nov) Mascarenhas Notes: Introduction to Lua, Getting Started, Types
and Values
- (10-12 Nov) Mascarenhas Notes: Control Flow, Functions
- (14 Nov) Mascarenhas Notes: Data Structures, More Functions,
Iterators, Handling Errors
Discuss Lua modules, metatables, and objects using
Fabio Mascarenhas's
Lecture Notes and other materials
- Background reading: Chapters 13, 15, and 16 of Programming in
Lua (PiL)
- General programming language concepts: modular programming,
information hiding, and abstract data types; object-based
programming, especially prototype-based; single and multiple
inheritance (i.e., object-oriented programming)
- (14 Nov) Mascarenhas Notes: Modules, Metatables, Objects
(for Assignment
#5) Arithmetic expression tree program skeletons (Lua)
Functional versions
- (12 Nov) Recursive Functions with Record Representation
(exprRecFuncRecord.lua)
- (14 Nov) Recursive Functions
with List Representation (exprRecFuncList2.lua)
- (14 Nov) Evaluation
Function Table with List Representation (exprEvalTable2.lua)]
- (for reference) Similar Scala code using case classes
Object-oriented versions
- Prototype Object-Based
(exprObjBased.lua)
- Object-Oriented with
Inheritance (exprObjInherit.lua)
Parsers (defer until LPEG discussion)
- LPEG parser with captures
- LPEG parser with
semantic actions
(TBD) Data Abstraction,
instructor's lecture notes
(TBD) Lua list module
- Cell-based list module:
[module source]
[test driver]
- Closure-and-table-based list module variant:
[module source]
[test driver]
- Function-based cell list module variant:
[module source]
[test driver]
- Lazy list module variant using C preprocessor (cpp -P)
[module source]
[source after cpp]
[test driver]
[driver after cpp]
[sh script]
- Lazy list module variant using
LuaMacro 2.5
[macro definitions]
[module macro source]
[source after luam -o]
[macro test driver]
[driver after luam -o]
[sh script]
(TBD) Introduction to Object-Orientation,
instructor's lecture notes--through the section titled "An Object
Model".
- Note: In CSci 658, along with the discussion of these notes,
we examined the object-oriented versions of the Arithmetic Expression
Tree, Complex Number, and the Movable and Named
Object example.
(TBD) Discuss scope, functions, and storage management from
Chapter 7 (pages 204-231) of John Mitchell's Concepts in
Programming Languages, Cambridge University Press, 2003:
[slides]
Other Materials from Fall 2013 CSci 658 (Software Language Engineering)
(for reference) Recursion Concepts and Terminology (Using Lua Examples),
instructor's lecture notes
(We covered this recursive styles content from Chapter 5 of the Notes on Functional Programming
with Haskell.)
Example recursive Lua functions adapted from from the Scheme
versions in Chapter 1 of Abelson and Sussman's Structure and Interpretation of Computer Programs
- Square root
(Newton's Method)
- Factorial
- Fibonacci
- Exponentiation
- Greatest common divisor
- Summation (takes
function arguments)
- Derivative (returns
function)
Natural number package
- Natural number package in Lua
(nats2.lua)
- Older Lua version with less distinct
data abstraction layers
- Similar programs in other languages:
[Java]
[Ruby]
[Scala (three versions, item 5)]
Complex number arithmetic modules in Lua adapted from SICP Section 2.4. (Modules are repeated in each package in which
they are used.)
- Rectangular coordinates modules
[arithmetic:]
[rectangular representation]
[utilities]
[test driver]
- Polar coordinates modules:
[arithmetic]
[polar representation]
[utilities]
[test driver]
- Tagged data modules:
[arithmetic]
[data tagging]
[utilities]
[test driver]
- Data-directed programming modules:
[arithmetic]
[rectangular representation]
[polar representation]
[data tagging]
[utilities]
[test driver]
- Object-oriented modules:
[arithmetic]
[utilities]
[test driver]
Carrie's Candy Bowl ADT in Lua
- Problem description
- ADT semantics
- Description of bag concept
- Hashed version
(candybowl_hash.lua). This file has a description of the problem
and the formal invariant, precondition, and postcondition
assertions.
- Unsorted list version
(candybowl_list.lua)
- Test driver
(test_candybowl.lua)
Movable and Named Objects example (in Lua but based on a similar
Haskell case study given in Section 14.6 of: Simon
Thompson. Haskell: The Craft of Functional Programming,
Third Edition, Addison Wesley, 2011).
- First Lua version:
[source (movable.lua)]
- Modularized version with improved class support
[class_support module]
[using class-support (movable2.lua)]
[test driver (movable2Test.lua)]
- Other older versions:
[Haskell source ]
[Scala source (partial) ]
Lua versions similar to Martin Fowler's Lair Configuration
domain-specific language (DSL) examples from his book chapter "One Lair
and Twenty Ruby DSLs," Chapter 3, The ThoughtWorks
Anthology: Essays on Software Technology and Innovation, The
Pragmatic Bookshelf, 2008: [book site]
Note: The DSL patterns mentioned are from the DSL patterns catalog from
Martin Fowler's book Domain Specific Languages
(Addison Wesley, 2010.
Caveat: Some of these DSL programs depend upon features from Lua 5.1
that were changed in Lua 5.2.
Shared modules
- Class support module (same as in Movable Objects case study)
[class support module (class_support.lua)]
- Semantic Model
[model module (model.lua)]
[test driver (rules00.lua)]
Internal DSLs
- Global Function Sequence
[builder module (builder08.lua)]
[dsl script (rules08.lua)]
[test driver (test08.lua)]
- Class Method Function Sequence with Method Chaining
[builder module (builder11.lua)]
[dsl script (rules11.lua)]
[test driver (test11.lua)]
- Expression Builder with Method Chaining
[builder module (builder14.lua)]
[dsl script (rules14.lua)]
[test driver (test14.lua)]
- Nested Closures
[builder module (builder03.lua)]
[dsl script (rules03.lua)]
[test driver (test03.lua)]
- Expression Builder with Object Scoping and Method Chaining
[builder module (builder17.lua)]
[dsl script (rules17.lua)]
[test driver (test17.lua)]
- Literal Collection
[builder module (builder22.lua)]
[dsl script (rules22.lua)]
[test driver (test22.lua)]
External DSL
- LPEG Parser/Builder (no corresponding example in Fowler paper)
[builder module (builderLPEG1.lua)]
[dsl script (rulesLPEG1.dsl)]
[test driver (testLPEG1.lua)]
Sandwich DSL in Lua (related but not precisely the same as the
Haskell SandwichDSL above)
- Semantic model
module (sandwich_model.lua)
- DSL builder module using
function sequence pattern (sandwich_builder.lua)
- Test driver
(test_sandwichDSL.lua)
Lua Parsing Expression Grammar (LPEG) library
- Roberto Ierusalimschy's talk LPEG: A New Approach to
Pattern Matching [PDF slides]
[video]
- (For reference) Roberto Ierusalimschy's paper "A Text
Pattern-Matching Tool Based on Parsing Expression Grammars,"
Software: Practice & Experience 39 #3 (2009) 221-258: [PDF]
Kamin Interpreters in Lua Toolset (KILT)
[Compressed tar file]
- Language/Interpreter-independent modules:
[REPL Module (repl.lua)]
[Environment Module (environment.lua)]
[Function Table Module (funtab.lua)]
[Utilities Module (utilities.lua)]
[Opcodes Factory Module (opcodes.lua)]
[Values Factory Module (values.lua) ]
[Parser Factory Module (parser.lua)]
[Evaluator Factory Module (evaluator.lua)]
-
Kamin Chapter 1 Core language interpreter:
[Core Interpreter (Core.lua)]
[Core Opcodes (opcodes_core.lua)]
[Core Values Module (values_core.lua)]
[Core Parser Module (parser_core.lua)]
[Core Evaluator Module
(evaluator_core.lua)
-
Kamin Chapter 2 Lisp language interpreter:
[Lisp Interpreter (Lisp.lua)]
[Lisp Opcodes (opcodes_lisp.lua)]
[Lisp Values Module (values_lisp.lua)]
[Lisp Parser Module (parser_lisp.lua)]
[Lisp Evaluator Module (evaluator_lisp.lua)
[A few Lisp examples]
-
Kamin Chapter 4 Scheme language interpreter:
[Scheme Interpreter (Scheme.lua)]
[Scheme Opcodes (opcodes_scheme.lua)]
[Scheme Values Module (values_scheme.lua)]
[Scheme Parser Module (parser_scheme.lua)]
[Scheme Evaluator Module
(evaluator_scheme.lua)
[A few Scheme examples]
(Not discussed directly in CSci 658) Functional Program Evaluation Concepts, instructor's
lecture notes
UP to CSci 450/503 root document?
Copyright © 2014, H. Conrad Cunningham
Last modified: Thu Nov 13 15:01:21 CST 2014