Recovering omitted function annotations

A developer leaves the parameter and result annotations out of three functions. Infer their types using only these language rules:

  • Integer literals have type Int, Boolean literals have type Bool, and quoted text has type String.
  • + accepts two Int operands and returns Int.
  • > accepts two Int operands and returns Bool.
  • An if condition must have type Bool. Its branches must have the same type, which becomes the type of the conditional expression.
  • Each function returns its body expression.

Each operator accepts only the operand types listed above.


Plain text
increment(n) = n + 3
invert(b) = if b then false else true
status(k) = if k > 0 then "open" else "closed"


Complete every cell with exactly Int, Bool, or String.

FunctionParameter typeResult type
increment
invert
status

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Type Checking and Inference Questions: