LMU ☀️ CMSI 585
PROGRAMMING LANGUAGE FOUNDATIONS
Quiz 4

Answer as many questions as you can. For short answer questions, be as brief as possible, but not too brief. You do not need complete sentences. There is neither time enough nor space enough to write complete sentences.

  1. Give the number of inhabitants for each type. If your answer has an $\aleph$ in it and it’s hard for you to write, just spell it out. For example, you can write “aleph-null” instead of $\aleph_0$. Please only show the cardinalities, do not show your work or attempt to list the functions.
    $\textsf{Bool} + \textsf{Unit}$ _______________________
    $\textsf{Nat} + \textsf{Void}$ _______________________
    $\textsf{Nat} \times \textsf{Bool}$ _______________________
    $\textsf{Nat} \times \textsf{Unit}$ _______________________
    $\textsf{Unit} \times \textsf{Void}$ _______________________
    $\textsf{Bool} \times \textsf{Bool}$ _______________________
    $\textsf{Bool} \to \textsf{Unit}$ _______________________
    $\textsf{Bool} \to \textsf{Void}$ _______________________
    $\textsf{Unit} \to \textsf{Nat}$ _______________________
    $\textsf{Void} \to \textsf{Nat}$ _______________________
  2. Define inductively a type for the result of a password change request in a program. The user must submit a valid authentication token, the new password, and the new password a second time as a confirmation. Passwords must be at least 16 characters in length. Call the type $\textsf{Result}$. The result can either be (1) an indication that the request was granted, (2) an indication that the request was denied because the authentication token was invalid, (3) an indication the password request was too short and by how much, or (4) an indication that the request was denied because the new passwords did not match.
  3. Write a function, in typed $\lambda$-notation, that accepts a token, a candidate password, and a password confirmation for a password change request and returns a $\textsf{Result}$ (the type you defined in the previous problem). Assume the existence of functions $\textsf{isValidToken}\!: \textsf{Token} \to \textsf{Bool}$ that checks the validity of a token, (2) $\textsf{length}\!: \textsf{String} \to \textsf{Nat}$ that returns the length of a string, and (3) $\textsf{equals}\!: \textsf{String} \times \textsf{String} \to \textsf{Bool}$ that checks if two strings are equal.
  4. In the Attic Philosophy video on the Curry-Howard Correspondence, Mark Jago shows how the proof of the proposition $(\beta\to\gamma)\to(\alpha\to\beta)\to(\alpha\to\gamma)$ corresponds to the proof term $\lambda x_{\beta\to\gamma}.\lambda y_{\alpha\to\beta}.\lambda z_\alpha.(x(yz))$. What proof term would correspond to the (simpler!) proposition $\beta\to(\alpha\to\beta)$?
  5. Circle all the free occurrences in the following $\lambda$-expression:
    $λx.(λx.\;x\;y)\;(λz.\;(x\;λw.\;w)\;(z\;λp.\;p)\;x)\;z$
  6. Reduce $((\lambda f. \lambda x. (\lambda y.f\,y)(\textsf{square}\,x))\,\textsf{double})$ as much as you can. If you need to rename variables, use the usual scheme of choosing the next free letter in the Latin alphabet. If you see any functions that look like arithmetic functions, they are, and you should apply them too.
  7. Can an expression in the simply typed lambda calculus fail to reduce to a normal form? If so, give an example. If not, explain why not.
  8. What is the significance of the famous equation $Y\,f = f\,(Y\,f)$? What exactly is the equation saying and why is it so fantastical?
  9. In a previous quiz you were given a set $R$ and asked what $R^2$ was when interpreted as a plain set and also when interpreted as a relation. Now here is another set that we will call $R$, namely $R = \{1, 2, 3\}$. What is $R^2$ when $R$ is interpreted as an alphabet?