Homework 6. Generics in Go, Java and OCaml

[131 home > Homework]

Background

You’re working for a Metahilang, a software development company that writes a lot of high-level code in Java and OCaml, mostly for financial applications but also for other uses. Your codebase heavily uses generic types and you and your customers rely on these generic types heavily. Some of your app and libraries are available in both Java and OCaml; others are just in one language.

Some of your customers have been using Go for projects and have asked for Go versions of some of your libraries. You’ve said no because Go lacks generics and your software designs depend on generics so heavily. However, Go 1.18 (2022-03-15) added support for generic code using parameterized types, so you are now thinking of revisiting this decision.

Assignment

First, read the following:

Then, answer the following questions:

  1. Greisemer and Taylor write:
    The exact details of how type inference works are complicated, but using it is not: type inference either succeeds or fails. If it succeeds, type arguments can be omitted, and calling generic functions looks no different than calling ordinary functions. If type inference fails, the compiler will give an error message, and in those cases we can just provide the necessary type arguments.
    How well does this statement apply to Java and OCaml? Where there are differences, briefly explain the differences with examples; if there are no differences, briefly explain why not.
  2. Taylor’s “When to use generics” contains four examples of when type parameters are useful: and three examples of when type parameters are not useful: For each of these seven examples, briefly explain whether it applies equally well to Java.

Submit

Submit a file hw6.pdf containing your answers to the questions.