Theory and Design of PL (CS 538)
January 27, 2020
I call it my billion-dollar mistake […]
This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage.
Define what programs look like!
Define what programs should do!
If something is not working, please let us know ASAP and we will try to fix it.
Start as early as you can!
Think about programs in isolation
doublePlus :: Int -> Int -> Int
doublePlus x y = double x + double y
-- SAME AS: doublePlus x y = (double x) + (double y)
-- BUT NOT: doublePlus x y = double(x) + double(y)
doublePlus
takes two inputsdouble x
and double y
Standard if-then-else:
Cleaner (or for more cases):
Use a case expression:
At the beginning…
tripleSecret :: Int
tripleSecret = let secret = mySecretNum
other = myOtherNum
in 3 * secret + other
…or at the end
This is a list of four integers:
Lots of operations on lists:
Define functions on list by case analysis:
listPrinter :: [Int] -> String
listPrinter [] = "Empty list :("
listPrinter (x:xs) = "List: " ++ (show x) ++ " and " ++ (show xs)
Underscore _
matches any value:
ext
refer to below?myFun
called elsewhere, remembers value of ext
What is the result of the following program?
Answer: 2. Looks like foo
was updated…
What about the following programs?
Answer: 3. Inner foo
has nothing to do with outer foo
!
Social factors