Recitation 3

  1. Imagine that your boss asks you to implement a function named zardoz and that its type must be exactly int -> bool. In other words, the toplevel would print the following when queried about the function:
    # zardoz;;
    zardoz : int -> bool = <fun>
    

    Use the toplevel to investigate which of the following would be permitted by your boss’s request, and which would not:

    • Making zardoz a recursive function.
    • Making zardoz a non-recursive function.
    • Writing a helper function and using that helper function in the body of zardoz.
    • Making the int argument a labelled argument.

  2. Compare and contrast OCaml functions to functions in another language of your choice, focusing on those concepts: recursive vs. non-recursive, anonymous, polymorphism, and partial application.

  3. One of the premises of functional programming is that mathematical functions are the basic building block of computation. How are OCaml functions like mathematical functions? How are they different? As part of your answer, focus on the notion of types. In your opinion, is mathematics itself typed or untyped?

Submit your answers to CMS.