Exercises

Mandatory exercises

Exercise 9

A question about the design of OCaml:

  • in its language of expressions, applications implicitly associate to the left, i.e., String.get "hello world" 0 is parsed as (String.get "hello world") 0;
  • in its language of types, function types implicitly associate to the right, i.e., string -> int -> char is parsed as string -> (int -> char).

Justify this choice.

Exercise 10

Consider the following definition:

let length_of_string_concatenation s1 s2 =
  String.length (s1 ^ s2) = String.length s1 + String.length s2;;

What is the result of applying length_of_string_concatenation to any two strings?

  • true, always?
  • false, always?
  • sometimes true, sometimes false?

Justify your answer.

Version

Added Exercise 10 [14 Feb 2020]

Created [07 Feb 2020]

Table Of Contents

Previous topic

The proof is trivial (variations on a theme)

Next topic

YSC1212 Lecture Notes, Week 05