CISC 360: Programming Paradigms
Queen’s University
Copyright By PowCoder代写 加微信 powcoder
Lecture logistics
• This lecture is (supposed to be) recorded
• The recording will be edited minimally, if at
• If you need me to edit out something you said,
let me know
• If you’re participating from Zoom, you can
use the Zoom chat, but I won’t always notice
it immediately
CISC 360 Fall 2022
Well, here we are
• I have managed to not get COVID yet
• I had cancer
• Please wear a mask
• N95 / 95PFE / FFP3 if you can
• My mask is N95 (US standard)
+ 95PFE (Canadian standard)
+ FFP3 (European standard)
• Open windows whenever you can
• QUFA, the faculty union, filed a grievance over
inadequate ventilation in lecture halls
• Please stay home if you have symptoms
or were exposed
CISC 360 Fall 2022
Queen’s University is endangering us
•Masks work (especially N95s)
• Yes, they are annoying
• Long COVID can be worse than annoying
CISC 360 Fall 2022
Carbon dioxide monitoring
• Proxy measure for amount of exhaled breath
• (And how much you’ve been cooking with gas)
• Rough upper baseline of COVID risk
• High CO2 also impairs cognition
• If this gets too high, I will end the lecture
CISC 360 Fall 2022
• Instructors are permitted (even not in a
pandemic) to change the syllabus until the
end of the second week
• Instructors have the right to decide how
students are assessed:
I have the right to hold tests and exams
over onQ even if Queen’s says we are
teaching in person
•Who am I?
•Hello, what is this course about?
• What is a paradigm?
• Functional programming
• Logic programming
• Logistics
• Next time…
Jana / Prof. Jana / Prof. Dunfield
pronouns: she/her
—2007→ McGill —2010→
MPI-SWS —2014→ UBC —2017→ Queen’s
• I study “programming languages”:
• Logical and mathematical foundations of
programming languages
• Reasoning about programs and programming
• Formal methods
• Types (so many types)
I am transgender
(a vegan cheesecake that was ordered for me
by my colleagues in the School of Computing)
Jana / Prof. Jana / Prof. Dunfield
http://dunfieldlab.ca/
Virtual office hours (Microsoft Teams): TBA
Indoor office hours: maybe, if so, masks will
be required
CISC 360 Fall 2022
http://dunfieldlab.ca/
Hello, what is this course about?
•World domination?
World domination: this time for sure!
• 196x: Algol was going to dominate
• 1970: PL/I was going to dominate
• 1980: C was going to dominate
• 1990: C++ was definitely going to dominate
• had to justify why he would dare
to design a new language (Java)
• 2000: Java was going to dominate
If you keep programming after you
…you will have to learn languages you don’t
know yet (and maybe haven’t been invented yet)
Learning a new functional language will be
easier if you already know one (like Haskell)
Learning a new logic programming language will
be easier if you already know one (like Prolog)
The more languages you know, the easier it
becomes to learn new ones
Different languages for different purposes
•Machine-level programming: assembly
• Low-level programming: C, C++, Rust
•Web development: JavaScript, TypeScript, …
• “Scripting”: bash, zsh, Python, Ruby, …
• Numerical computing: Matlab, R, Fortran, …
• Symbolic computing:
Lisp, Scheme, OCaml, Haskell, …
• Deductive reasoning: Prolog, Twelf, Agda…
• Destroying (?) the world’s economy: Haskell
“Programming Paradigms”
•What is a paradigm?
• “a typical example or pattern of something;
a model… a worldview underlying the theories
and methodology of a particular scientific
subject” (Oxford American Dictionary)
“Programming Paradigms”
•What is a programming paradigm?
• object-oriented programming
(“object-oriented paradigm”—163K results)
• imperative programming
(“imperative paradigm”—11K results)
• functional programming
(“functional paradigm”—58K results)
“the functional paradigm completely changes the
way we think about programming”
—theburningmonk.com
“Programming Paradigms”
•What do these mean?
• object-oriented programming languages
• imperative programming languages
• functional programming languages
“Programming Paradigms”
• Object-oriented
• Imperative
• Functional
features languages
features languages
features languages
“Programming Paradigms”
• Object-oriented
• Imperative
• Functional
objects, classes, inheritance,
(methods),
(instance variables)
Simula-67, Smalltalk, C++,
Java, Python (?), OCaml (?)
commands (“statements”),
variable assignment,
(procedures), (structs)
Fortran, Algol-60, PL/I, Pascal,
C, C++, Java (?), Python (?)
functions, (recursion),
no variable assignment
Lisp, Scheme, Racket, OCaml,
Haskell, Python (?), Java (??),
“Programming Paradigms”
• Lots of (?) and overlap (like Python)
• Possible to write in a functional style in
many languages
(use lots of anonymous functions)
• Possible to write in an object-oriented style
in many languages
(C with function pointers inside structs)
Functional programming (in Haskell)
• “Pure” or “side effect-free” programming
• no assignment to variables (no overwriting)
• no loops
• lots of recursive functions
(anything you can do with a loop,
you can do with recursion)
• no printing; more accurately, weird printing
• No side effects often makes it easier to reason
about programs
• Functions can take functions as arguments
• Functions can build new functions
Functional programming (in Haskell)
(\x -> x + 1) 3
a function has no name
\: supposed to be a lambda (λ)
parameter name: x
function body: x + 1
Functional programming (in Haskell)
(\x -> x + 1) 3
add1 = map (\x -> x + 1)
:type add1
add1 :: Num b => [b] -> [b]
add1 [1, 10, 100]
[2,11,101]
Logic programming (in Prolog)
• Unlike Haskell, Prolog is not usually considered
general-purpose
• Instead, for deductive reasoning
• A Prolog program is a set of facts
combined with rules about deriving (deducing)
“new” facts
Fact: smoky(british_columbia)
Rule: on_fire(X) :- smoky(X) “if smoky(X) then on_fire(X)”
————— (CISC 204) ∀X (smoky(X) → on_fire(X))
on_fire(X)
Is British Columbia on fire?
Logic programming (in Prolog)
• Unlike Haskell, Prolog is not usually considered
general-purpose
• Instead, for deductive reasoning
• A Prolog program is a set of facts
combined with rules about deriving (deducing)
“new” facts
Fact: smoky(british_columbia)
Rule: on_fire(X) :- smoky(X)
Is British Columbia on fire?
1. smoky(british_columbia) [Fact]
2. on_fire(X) :- smoky(X) [Rule]
3. on_fire(british_columbia) [X = british_columbia] 1, 2
Aside: Similar to a 204 natural deduction proof, except Prolog has fewer built-in rules.
Writing programs systematically
• Reasoning about Haskell programs
by stepping (tracing)
• Proving properties of programs (by stepping)
• Defining what stepping is by logical rules
• “Running” the logical rules (in Prolog)
Some learning outcomes
•Write short programs in a functional
language such as Haskell or LISP, including
the use of recursion, lists, higher-order
functions.
• Use structural induction to prove simple
assertions about functional programs.
•Write short programs in a logical language
such as Prolog.
• Predict the behaviour of small programs
written in either paradigm.
• Course material
Notes, code, slides
• Instructor and TA office hours
(being organized)
• Discussions on Piazza, a site designed to let
students ask (and answer) questions without
feeling intimidated
• You can be anonymous to other students,
but not to me and the TAs
Course grade
• Assignments (5?): 35%
• Lowest mark dropped
•Quizzes (3): 35%
• Lowest mark dropped
• Final exam: 30%
• in onQ, no proctoring
CISC 360 Fall 2022
• Several years ago, these were required:
• . Haskell: The Craft of
Functional Programming, third edition.
• . Prolog Programming for Artificial
Intelligence, fourth edition.
…and then became optional…
…and now I don’t really recommend them,
but you’re welcome to look at them if you
Academic integrity
• Don’t copy (from anyone or anywhere)
• Don’t allow anyone to copy from you
•Work on individual assignments individually
• Get help from me or the TAs
•On Piazza: you can always post questions
about assignments, but be careful answering
them—let me and the TAs decide how much
to “give away”
• Please do answer general questions!
Academic integrity
• Sometimes people are tempted to
“depart from academic integrity”
because they feel desperate
• Ask for help
• Helping individual students is one of
the best parts of teaching
Asking for help
• Try to ask for help as early as you need to
• “need to” ≠ “can” (believe me, I know)
Academic Consideration
• Example: If you become ill and can’t write a
quiz, go to the link below and fill out a
• https://www.queensu.ca/artsci/undergrad-
students/academic-consideration-for-
• one 3-day request without documentation
• In general,
I don’t need to know personal details
• If you’re not in ArtSci, consult your Faculty
CISC 360 Fall 2022
https://www.queensu.ca/artsci/undergrad-students/academic-consideration-for-students
Academic Consideration
• If the official system takes too long
(which it will, because COVID),
or you get rejected for silly reasons:
CISC 360 Fall 2022
Academic Accommodation
• Accommodations are now handled online
• You no longer need to email instructors your
QSAS letter
CISC 360 Fall 2022
•Haskell: two major alternatives
1. GHC (Glasgow Haskell Compiler)
• If you use Windows, some recommend WinGHCi
• macOS / Linux: ghci
They give different, but often equally confusing,
error messages
CISC 360 Fall 2022
• Prolog: SWI-Prolog
• more information when we get into Prolog,
around Week 7
CISC 360 Fall 2022
• A text editor
• not a word processor (Word, TextEdit, …)
• Atom (Windows, macOS, Linux)
• Notepad++ (Windows)
• If you’re old-school, or want to be:
Aquamacs (macOS), Emacs, vim (Linux, …)
CISC 360 Fall 2022
To do in Week 1
1. Sign up on the 360 Piazza:
• https://piazza.com/queensu.ca/fall2022/cisc360
• Good for Q & A and discussions
• onQ for everything else
2. Maybe try to log in to caslab machines
(possibly useful as a backup)
3. Start trying to install GHCi
(it’s sometimes difficult to install)
4. Find a text editor or IDE that (ideally) supports
Haskell well
Basics of Haskell
(lec2.pdf and (lec2-slides.pptx or lec2-slides.pdf))
CISC 360 Fall 2022
https://piazza.com/queensu.ca/fall2022/cisc360
• If you have questions, you may:
• follow me into the Mac-Corry courtyard
(behind )
• Turn left, turn right, go straight, go out
• contact me via email, Teams, or ISC 360 Fall 2022
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com