#+title: CS 3MI3 Tutorial #+subtitle: Possible midterm questions ;; things to know #+date: October 29 * How does a type differ from a set? * What type formers are supported in the languages covered in this class? * Why does every language support product types? * Give an example of a language that does not have one-input one-output functions types. * Intersection related to subtyping, how? *Golden Rule* x ↑ y = y ≡ x ≤ y x ∨ y = y ≡ x ⇒ y x ∪ y = y ≡ x ⊆ y How is the intersection Golden Rule useful for simlifying redundant code? Akin to ~b && true~ replaced by ~b~. ** What is the diamond problem? * In C/C++/C#, how is the infinite list [1,2,3,…] implemented? + [1, 1, 1, …] ≈ λ i → 1 - Representation :: Entire RHS. - Element at particular index :: Always 1. + [1, 2, 3, …] ≈ λ i → i + [1, 1, 2, 3, 5, 8, …] ≈ λ i → Fibonacci i *Actually* open a language and implement infinite lists, “streams”. + “Function patching” is how you ‘update’ lists in functional representation. + There are *many* possible representations of lists. * Explain “Arrays are continuous blocks of memory, while lists are not” ** What is an ArrayList --e.g., Java. * Difference between strongly typed and weakly typed; examples in languages? * Explain: Untyped programming is unityped programming. * Implement a parametrically prolymorphic function ** How does this differ from inheritance, ad-hoc polymorphism? Overloading? - Casing along types ≈ overloading - Parameteric ≈ only one definition - Inhertiance ≈ Define the function on a per-child basis * Know what an inductive type is, give common examples. - English letters - Colours: Red, Green, Blue + In generally, any enumeration is an inductive type. + E.g., 𝔹ooleans! - ℕatural numbers - Linked Lists! * Given an inductive type, what is its induction principle? induction principle ≈ recursion principles ≈ super powerful switch/case statements - i.e., pattern matching and more E.g., ℕ-induction principle gives us for-loops! See the Agda cheat sheet for examples. * Explain how to /prove/ a theorem by writing a /program/