Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Traits vs. Inheritance

Dispatch and encapsulation wrote traits and bounds for a program’s own types. The prelude has been doing something similar since Part II, without saying how. The program below declares Version, a struct holding a release’s major and minor numbers, and makes a list vs of two versions. It then calls three prelude functions: len, which gives the length of a string or a list; maximum, which returns the greatest element of a list wrapped in Some, or None for an empty list; and maximum again, on vs:

struct Version { major: Int, minor: Int }

fn main() {
    let vs = [Version { major: 1, minor: 4 }, Version { major: 2, minor: 0 }];
    println(len("bridger"));
    println(len([3, 1, 2]));
    println(maximum([3, 1, 2]));
    println(maximum(vs));
}

The program never starts. The checker accepts the first three calls and reports at vs:

no `impl Ord for Version`, so the bound is not satisfied

A program’s own function that hands its argument to len fares no better:

fn size<T>(x: T) -> Int = len(x);
// no `impl Len for T`, so the bound is not satisfied

The program raises these questions:

  • What type does len have? It accepts a String and a list, two types with no structure in common, and Part V’s type parameters act the same way on every type.
  • How can a program’s own type join in? maximum orders integers but has no way to order versions.
  • What may a generic function ask of its type parameter? Function types and polymorphism rejected fn eq<T>(a: T, b: T) -> Bool = a == b;, since not every type has ==.
  • Could the ordering be inherited instead? Many object-oriented languages would have Version inherit its comparison operations from a base class of comparable things.

Two kinds of polymorphism

Christopher Strachey’s lecture notes “Fundamental Concepts in Programming Languages”, from a 1967 summer school in Copenhagen and published in 2000, sorted the ways one operator can serve many types: “There seem to be two main classes, which can be called ad hoc polymorphism and parametric polymorphism.” For the first, “In ad hoc polymorphism there is no single systematic way of determining the type of the result from the type of the arguments.” The ordinary arithmetic operators were his example. He called parametric polymorphism “more regular”, and his example was a function Map that applies a function to each member of a list, whatever the types of the list’s elements.

Languages that followed treated the two separately. ML gave parametric polymorphism a type system and type inference, which Part V described, and handled overloaded arithmetic and equality with special cases built into the language. Philip Wadler and Stephen Blott’s “How to make ad-hoc polymorphism less ad hoc” (POPL 1989) observed that there was “no widely accepted approach to ad-hoc polymorphism, and so its name is doubly appropriate.” Their type classes let a program declare a class of types that support some operations, declare which types are instances, and write functions over any instance, “and thus bring together the two sorts of polymorphism that Strachey separated.” Haskell adopted type classes, and Rust’s traits are widely described as drawing on them. Bridger’s prelude traits are a small case of the same design.

Overloading as evidence

A bound T: Ord divides a function in two. Its body is parametric: max does the same thing for every T, calling cmp and returning one of its arguments. The cmp it calls is ad hoc: each type supplies its own, and they share nothing but a signature.

The checker has to make sure the cmp exists. At each call of a bounded function it needs evidence that the type at which T was instantiated meets the bound. Appendix D accepts three kinds: an impl of the trait for that type, a built-in conformance the language provides for a primitive type, or, inside a declaration, a type parameter that carries the bound itself. In size above, T carries no bound, so the checker can find no evidence that T is Len, and it rejects the call to len inside size. Writing fn size<T: Len>(x: T) -> Int moves the requirement to size’s callers, and each of them supplies the evidence for its own type.

The evaluator has to run the right cmp. The evidence the checker found has to reach the call somehow, and languages differ in how. Bridger reaches it through the receiver’s head, as Dispatch and encapsulation described, and the design space compares two other routes.

Bridger’s prelude traits

The prelude declares five traits, listed in Appendix C:

type Ordering = Less | Equal | Greater;

trait Eq {}
trait Print {}
trait Ord     { fn cmp(self, other: Self) -> Ordering; }
trait Len     { fn length(self) -> Int; }
trait From<T> { fn from(x: T) -> Self; }

Ord and Len

Ord describes types with an order. a.cmp(b) answers Less, Equal, or Greater, and Ordering is an ordinary sum type a program takes apart with match. Len describes types with a length. Int, String, and Bool are Ord, and String and every list type are Len, by built-in conformance:

println("apple".cmp("pear"));   // Less
println(true.cmp(false));       // Greater
println([1, 2].length());       // 2

The comparison operators stay as they were: < and its relatives take integers, and "apple" < "pear" is still type mismatch: expected Int, found String. Ordering strings goes through cmp. The other operators are fixed in the same way. Tree-walking evaluation gave ++ two shapes of operand, strings and lists, and it keeps exactly those: 1 ++ 2 is still type mismatch: expected String, found Int, and no trait extends an operator to a new type. A program’s own type gets an order through cmp and a length through length, called by name.

Through Part VIII, len, min, max, minimum, and maximum were native functions of the interpreter, each with a short list of built-in types it accepted. From M8 they are ordinary Bridger, written over the traits. This is the prelude’s own source:

fn min<T: Ord>(a: T, b: T) -> T = match a.cmp(b) { Greater => b, _ => a };
fn max<T: Ord>(a: T, b: T) -> T = match a.cmp(b) { Less => b, _ => a };

fn maximum<T: Ord>(xs: [T]) -> Option<T> =
    match xs {
        [] => None,
        h :: t => Some(fold(t, h, max)),
    };

fn len<T: Len>(xs: T) -> Int = xs.length();

minimum mirrors maximum with min. len’s type is now fn<T: Len>(T) -> Int, and the overloading the prelude used to perform by special case is a bound any program could have written. A program that implements Ord for its own type joins the built-in types. Versions compare by major number, then by minor:

impl Ord for Version {
    fn cmp(self, other: Self) -> Ordering =
        match self.major.cmp(other.major) {
            Equal => self.minor.cmp(other.minor),
            o => o,
        };
}

fn main() {
    let a = Version { major: 1, minor: 4 };
    let b = Version { major: 2, minor: 0 };
    println(a.cmp(b));
    println(max(a, b));
    println(maximum([a, b, Version { major: 1, minor: 9 }]));
}

This prints:

Less
Version { major: 2, minor: 0 }
Some(Version { major: 2, minor: 0 })

maximum called max, which called a.cmp(b) on two versions, and that call found the cmp in impl Ord for Version, although the prelude’s maximum was written with no knowledge of Version.

A built-in conformance counts as an impl for coherence, so a program cannot replace it:

impl Ord for Int { fn cmp(self, other: Self) -> Ordering = Equal; }
// `Int` is `Ord` by a built-in rule and cannot be implemented again

A built-in type that lacks a conformance can be given one. Here Int becomes Len, its length being its number of decimal digits, with the sign not counted:

impl Len for Int {
    fn length(self) -> Int =
        if self < 0 { (0 - self).length() }
        else if self < 10 { 1 } else { 1 + (self / 10).length() };
}

fn main() { println(len(12345)); println(len(-42)); println(len("abc")); }

This prints 5, 2, and 3. The length that len reaches depends on the value it is handed.

Eq and Print

Eq and Print declare no methods. A type is Eq when its values can be compared with ==, and Print when they can be printed. Both are decided by the type’s shape, so no program may write an impl of either. A type is Eq when it is data all the way down: the scalar types, tuples, lists, and declared types and structs whose components are all Eq. A function anywhere inside makes a type fail, since Bridger has no equality on functions. A reference is Eq whatever it holds, because references compare by identity. Print follows the same pattern, with a reference printable when its contents are.

The function eq that Part V had to reject is accepted with the bound:

fn eq<T: Eq>(a: T, b: T) -> Bool = a == b;

eq(1, 1)                        // true
eq(|x: Int| x, |x: Int| x)      // type fn(Int) -> Int admits no equality

The second call is rejected at its first argument, where the bound fails. Before M8, the same judgment applied to == itself, to the prelude’s contains, and to print. These now carry the bounds Eq and Print in their signatures. A struct that holds a function cannot be printed as a whole, though its other fields can:

struct Button { label: String, on_click: fn() -> () }

let b = Button { label: "ok", on_click: || println("clicked") };
println(b.label);   // ok
println(b);         // type Button cannot be printed

Ord asks for equality as well. impl Ord for τ is accepted only when τ is Eq, and a function with an Ord bound may use == on its type parameter:

struct Callback { f: fn(Int) -> Int }
impl Ord for Callback { fn cmp(self, other: Self) -> Ordering = Equal; }
// type Callback admits no equality

From and the conversion in ?

From<T> is a trait with a type argument, and its method has no self: from is an associated function that builds a value of the implementing type out of a T. It is the trait that Error handling said ? would use. Until now, e? in a function returning Result<T, E> has required e’s error type to be exactly E. From M8, when the two error types differ, the checker inserts a conversion, so the desugaring becomes

match e { Ok(v) => v, Err(err) => return Err(E.from(err)) }

and the conversion is whichever impl From<…> for E accepts err’s type. Here a parse failure becomes a configuration error on its way out of port:

struct ParseError { at: Int }
type ConfigError = BadNumber(Int) | Missing(String);

impl From<ParseError> for ConfigError {
    fn from(e: ParseError) -> Self = BadNumber(e.at);
}

fn digit(s: String) -> Result<Int, ParseError> =
    if s == "7" { Ok(7) } else { Err(ParseError { at: 0 }) };

fn port(s: String) -> Result<Int, ConfigError> {
    let d = digit(s)?;
    Ok(8000 + d)
}

fn main() {
    println(port("7"));
    println(port("x"));
}

This prints:

Ok(8007)
Err(BadNumber(0))

Without the impl, the ? in port is the type error it was in Part VIII. When the error types already agree, the checker inserts no call, so every program that type-checked before M8 runs as it did. Because from has no receiver, the evaluator has no value whose head could choose among several impl From<…> for ConfigError. The checker chooses by the argument’s type and records its choice for the evaluator, as it does for the trait instances of Dispatch and encapsulation. For the same reason, an associated call cannot be made on a type parameter. Inside fn make<T: From<Int>>(n: Int) -> T, the call T.from(n) is rejected with the message that T is a type parameter and an associated call names a concrete type, since at run time there is no head for T to dispatch on.

Building it

No new arm appears in eval_expr or check_expr. The bounds are written with the shapes the AST chapter gave every declaration:

struct TyParam {
    name: Name,               // T
    bound: Option<TraitRef>,  // : Ord, the trait bound, if any
    span: Span,
}

struct TraitRef { name: Name, args: Vec<Ty>, span: Span }   // Ord, or From<T>

At run time, len("abc") calls the Bridger function len, whose body is the method call xs.length(). That call is the E-Method of Dispatch and encapsulation: the head of "abc" is String, no impl provides length for it, and the built-in conformance runs a native primitive. A user impl Len for Int puts an entry for Int in the same method table, and the same arm finds it. The bound checks that Dispatch and encapsulation built cover the prelude’s bounds as well, with the built-in conformances added to the evidence. Eq and Print are judged by the provided checker, which walks a type’s structure, looking through each declared type and struct to its components.

The design space

Where the evidence travels

Bridger finds a type’s cmp from the head of the value it is called on. Wadler and Blott’s translation takes another route, which Haskell implementations use. A bounded function receives an extra argument, a dictionary holding the instance’s methods, and each call site passes the dictionary for its type. Their paper arrives at the idea by noticing that when objects carry their methods, two arguments of an equality test carry the same table: “This suggests that perhaps dictionaries should be passed around independently of objects; now polymorphic equality would be passed one dictionary and two objects (minus dictionaries).”

A Bridger program can write that translation by hand, with a one-method dictionary passed as a function:

fn largest<T>(xs: [T], cmp: fn(T, T) -> Ordering) -> Option<T> =
    match xs {
        [] => None,
        h :: t => Some(fold(t, h, |a: T, b: T| match cmp(a, b) {
            Less => b,
            _ => a,
        })),
    };

fn main() {
    println(largest([3, 9, 2], |a: Int, b: Int| a.cmp(b)));
    println(largest([3, 9, 2], |a: Int, b: Int| b.cmp(a)));
}

This prints Some(9) and then Some(2). Here the caller chooses the ordering at each call, and two calls on the same type can choose differently. A bound gives each type one cmp, and the checker builds and passes the dictionary itself.

Passing dictionaries removes two of Bridger’s restrictions. A dictionary does not depend on a receiver, so a method like from, or Haskell’s read, which produces a value of the type and consumes none, is chosen by the type the context expects. A dictionary also names one instance, so Dispatch and encapsulation’s twice<S: Scale<Int>> would receive the Scale<Int> methods for Meters, and the second instance under the same head would never be consulted. The cost is an extra argument at every bounded call, and an evaluator that has to know where the checker put it.

Monomorphization, also described in Dispatch and encapsulation, passes nothing at run time. A copy of maximum is made for Version, its cmp resolved during compilation. Rust compiles bounded generics this way.

Operators

Haskell’s numeric operators are the methods of a type class, so a program can define + for its own type by declaring an instance. Rust’s + is the add method of the trait std::ops::Add, and a + b is a call to it. Bridger keeps its operators fixed. Each operator then has one meaning per operand type, which a reader can look up in Appendix D, at the cost of writing a.cmp(b) where an ordered type might have used <.

Inheritance

Simula 67 let a class be written with another class as its prefix. The new class, a subclass, has every attribute and procedure of the prefix plus its own. A procedure the prefix declared virtual could be redefined in the subclass, and calls on the object then ran the redefinition, including calls made from inside the prefix’s own code. Smalltalk-80 put every class in one tree of superclasses, let any subclass method override an inherited one, and provided super for calling the overridden version. In such a language, Version could be a subclass of a base class of comparable things, supply its comparison by overriding one method, and inherit operations such as a maximum that the base class wrote in terms of that method.

The redirection of the prefix’s own calls is what makes reuse by inheritance work, since a base class written once can call methods supplied later. It also ties a subclass to how its base class is written. Leonid Mikhajlov and Emil Sekerinski’s “A Study of the Fragile Base Class Problem” (ECOOP 1998) describes a developer who produces “a seemingly acceptable revision of a base class which may damage its extensions.” Their example, adapted from earlier work, starts from a class Bag with methods add, addAll, which calls add once per element, and cardinality. A user writes a subclass CountingBag that overrides add to count each addition in a field n and overrides cardinality to return n. Later the framework’s developers rewrite addAll to insert its elements directly, without calling add. That is a correct change to Bag taken alone, but CountingBag’s count no longer sees what addAll inserts, and its cardinality is wrong. Alan Snyder’s “Encapsulation and Inheritance in Object-Oriented Programming Languages” (OOPSLA 1986) had argued earlier that inheritance exposes a class’s implementation to its subclasses, which then depend on it.

Bridger has no subclasses and no overriding. Every impl supplies the only body for its pair of head and method name, so a call b.add(x) on a Bag always runs Bag’s add. Reuse is by composition: the new struct holds the old one as a field and calls its methods. Bridger’s values are immutable, so each method returns a new bag:

struct Bag { items: [String] }

impl Bag {
    fn add(self, x: String) -> Bag = Bag { items: x :: self.items };
    fn add_all(self, xs: [String]) -> Bag =
        fold(xs, self, |b: Bag, x: String| b.add(x));
    fn size(self) -> Int = len(self.items);
}

struct CountingBag { bag: Bag, adds: Int }

impl CountingBag {
    fn add(self, x: String) -> CountingBag =
        CountingBag { bag: self.bag.add(x), adds: self.adds + 1 };
    fn add_all(self, xs: [String]) -> CountingBag =
        CountingBag { bag: self.bag.add_all(xs), adds: self.adds + len(xs) };
    fn size(self) -> Int = self.bag.size();
}

fn main() {
    let c = CountingBag { bag: Bag { items: [] }, adds: 0 };
    let c2 = c.add("a").add_all(["b", "c"]);
    println(c2.size());
    println(c2.adds);
}

It prints 3 twice. The b.add(x) inside Bag’s add_all reaches Bag’s add and nothing else, so rewriting add_all to build its list directly cannot change CountingBag’s count. The price is visible in CountingBag: it has to write size, which only forwards to the bag, and it has to write its own add_all. In a subclass, size would have been inherited. Bridger’s traits have no default method bodies either, so two impls of one trait that share an implementation each spell it out.

Substitution

A subclass is meant to stand in wherever its base class is expected. Barbara Liskov and Jeannette Wing’s “A Behavioral Notion of Subtyping” (1994) states what standing in requires, as their Subtype Requirement: “Let be a property provable about objects of type . Then should be true for objects of type where is a subtype of .” They observe that matching signatures fall short of this. A stack and a queue can both have a put and a get, and a program written for a stack is unlikely to work on a queue.

Bridger’s conformance check is the signature half. An impl Ord whose cmp is not a consistent order satisfies the checker, and then maximum’s answer can depend on the order of the list. Any further property a trait’s users rely on, such as transitivity of cmp, is a matter between each impl and its callers that the checker does not see. Nor does cmp have to agree with ==, which stays structural: if Version had a field tag that its cmp ignored, two versions differing only in tag would compare Equal and yet be unequal under ==.

Several parents

C++ and others let a class have several base classes. When two of them inherit from one common ancestor, the derived class reaches the ancestor along two paths, the diamond, and the language must say whether it holds one copy of the ancestor’s fields or two, and which inherited method a call finds. C++ answers the first with virtual base classes, which share one copy. Dylan answered the second with a lookup order called C3, from Kim Barrett and colleagues’ “A Monotonic Superclass Linearization for Dylan” (OOPSLA 1996). Python adopted C3 in version 2.3, and Michele Simionato’s essay “The Python 2.3 Method Resolution Order” explains the algorithm.

Bridger’s traits carry no bodies, so a type implementing several traits inherits no code from any of them. The question that remains is a method name two traits share. Bridger rejects it on one head:

trait Speak { fn name(self) -> String; }
trait Label { fn name(self) -> String; }
struct Robot { id: Int }
impl Speak for Robot { fn name(self) -> String = "speaker"; }
impl Label for Robot { fn name(self) -> String = "label"; }
// method `name` is defined more than once for Robot

Rust accepts both impls and asks a call to say which trait it means, when the receiver alone leaves the choice open.

Go and Rust

Go and Rust both left out class inheritance. The Go FAQ explains: “Rather than requiring the programmer to declare ahead of time that two types are related, in Go a type automatically satisfies any interface that specifies a subset of its methods.” A Go type never names the interfaces it satisfies, so an interface can be written after the types that meet it. Go also lets a struct embed another type, whose methods are then callable on the outer struct, which the FAQ calls “analogous—but not identical—to subclassing”. Bridger’s impl Tr for T names its trait, so a type meets a bound only where an impl says it does.

Rust’s traits are declared and implemented by name, as Bridger’s are. They also allow a default body for a method, which an impl may keep or replace, and a supertrait requirement, under which implementing one trait requires implementing another. A default body that calls another method of its trait reproduces, on a small scale, the redirection that makes a base class fragile. Bridger’s traits have neither feature, and Ord’s requirement of Eq is the one fixed relation between them. The design patterns book of Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides (1994) put the general advice as a principle: prefer object composition to class inheritance.

The Expression Problem, from the other side

Exhaustiveness checking quoted Wadler’s statement of the Expression Problem: “The goal is to define a datatype by cases, where one can add new cases to the datatype and new functions over the datatype, without recompiling existing code, and while retaining static type safety (e.g., no casts).” Shapes as a sum type look like this:

type Shape = Circle(Int) | Square(Int);

fn area(s: Shape) -> Int =
    match s { Circle(r) => 3 * r * r, Square(side) => side * side };

fn perimeter(s: Shape) -> Int =
    match s { Circle(r) => 6 * r, Square(side) => 4 * side };

Adding perimeter was one new function, and nothing existing changed. Adding a constructor Rect(Int, Int) changes the declaration, and the checker then reports match is not exhaustive at area and at perimeter until each gains an arm.

With structs and traits, as in Dispatch and encapsulation, the costs fall the other way round. Adding a new shape touches nothing that exists:

struct Rect { w: Int, h: Int }
impl Shape for Rect { fn area(self) -> Int = self.w * self.h; }

Adding perimeter as a method of Shape changes the trait, after which every existing impl fails conformance until it provides one. Bridger also allows the operation to arrive as a new trait, with impls written beside the old ones and none of them edited:

trait Perimeter { fn perimeter(self) -> Int; }
impl Perimeter for Circle { fn perimeter(self) -> Int = 6 * self.r; }
impl Perimeter for Square { fn perimeter(self) -> Int = 4 * self.side; }
impl Perimeter for Rect { fn perimeter(self) -> Int = 2 * (self.w + self.h); }

Both kinds of extension are then additions, with one condition. A value whose type is a struct has that struct’s type, so a list of shapes of different kinds needs the sum type AnyShape from Dispatch and encapsulation, and AnyShape has to be edited for every new kind of shape. An arithmetic tree raises the same trade-off. With generic structs and bounded impls, it can be built from traits, with no sum type:

trait Eval { fn value(self) -> Int; }

struct Num { n: Int }
struct Add<L, R> { l: L, r: R }

impl Eval for Num { fn value(self) -> Int = self.n; }
impl<L: Eval, R: Eval> Eval for Add<L, R> {
    fn value(self) -> Int = self.l.value() + self.r.value();
}

A Mul is a new struct and a new impl, and a Show is a new trait and its impls, all without editing a line above. The cost is in the types. Add { l: Num { n: 3 }, r: Num { n: 4 } } has type Add<Num, Num>, so each tree’s type spells out its shape, as the tagged tuples at the start of Sum and product types did. A conditional that builds a number in one branch and a sum in the other is rejected with type mismatch: expected Num, found Add<Num, Num>, and a function that parses a tree from a string has no single result type to declare.

Further reading

Ad hoc and parametric polymorphism: Section 3.6.4 of Strachey’s Fundamental Concepts names the two kinds in under two pages, with arithmetic as the example of the first and a list-mapping function as the example of the second. Wadler and Blott’s type classes paper introduces classes through equality and arithmetic, gives the dictionary translation by example, and puts the formal rules in an appendix. An authors’ version is on Wadler’s homepage.

Inheritance and its problems: Mikhajlov and Sekerinski’s study of the fragile base class begins with the Bag example and then works through further examples, each showing a different way a revised base class breaks an extension, before turning to a formal treatment. Liskov and Wing’s paper opens with the stack and queue example and the Subtype Requirement before giving its formal definitions.

Method resolution order: Simionato’s essay on Python 2.3 computes C3 by hand on small class hierarchies, including ones it rejects. The Dylan paper is the original.

Concept checks

Why is fn size<T>(x: T) -> Int = len(x); rejected, and what does adding the bound T: Len change about where a mistake is reported?

len requires evidence that its argument’s type is Len. Inside size, T is a type parameter with no bound, so no impl, built-in conformance, or bound in scope supplies that evidence, and the call to len is rejected in size’s body. With T: Len, the bound in scope is the evidence, and the requirement moves to each call of size: size(3) is reported at the caller, where Int has no Len unless the program provides one.

Why does Bridger accept impl Ord only for a type that admits equality?

A function with an Ord bound may compare its values with == as well as cmp, since Ord grants equality. If a type with a function inside it could be Ord, a bounded function could reach == on two functions, which Bridger has no way to answer, and the checker would have accepted a program that gets stuck.

In the composition version of CountingBag, the maintainer of Bag rewrites add_all to prepend all of xs in one step without calling add. Does CountingBag's count change? Why did the same rewrite break the subclass in Mikhajlov and Sekerinski's example?

It does not change. CountingBag counts in its own add and add_all, and Bag’s add_all calling b.add reaches Bag’s add whatever the rewrite does. In the subclass, the base class’s addAll called add on the object itself, so it ran the subclass’s overriding add, which did the counting. The subclass depended on that call, a detail of how addAll was written, and removing it removed the counting.

Take the shapes as a sum type and as structs with traits. For each, list the declarations a programmer edits to add a Triangle, and those edited to add a scale operation. What does the trait version give up?

As a sum, a Triangle edits the type declaration and every function that matches on Shape; scale is a new function and edits nothing. With traits, a Triangle is a new struct with new impls and edits nothing; scale added to the existing trait edits the trait and every impl, while scale as a new trait edits nothing. The trait version gives up a single type for all shapes: a list of mixed shapes, or a function that returns a circle or a square depending on its input, needs a sum type again, and that sum must be edited for each new shape.

Bridger finds a bounded method by the receiver's head, Haskell implementations pass dictionaries, and Rust monomorphizes. Which of these can choose a method that has no receiver, such as from, at a call through a bound T: From<Int>?

Dictionary passing and monomorphization can. A dictionary for T arrives with the call and holds T’s from, and a monomorphized copy knows T when it is compiled. Head dispatch needs a value whose head names the type, and from is given an Int, which says nothing about the T to build. Bridger’s checker can choose for a call like C.from(3), where the type is written, and it rejects T.from(n), reporting that an associated call has to name a concrete type.