concept type in category kotlin

appears as: type, types, type, types, The type
Functional Programming with Kotlin

This is an excerpt from Manning's book Functional Programming with Kotlin.

A function f with input type A and output type B (written in Kotlin as a single type: (A) → B, pronounced "A to B") is a computation that relates every value a of type A to exactly one value b of type B such that b is determined solely by the value of a. Any changing state of an internal or external process is irrelevant to computing the result f(a). For example, a function intToString having type (Int) → String will take every integer to a corresponding string. Furthermore, if it really is a function, it will do nothing else.

Even though we have omitted type declarations in the above examples, the types are still vital and are inferred in all cases; the lambda must still be of type (Int) → Int, otherwise compilation will fail.

The Joy of Kotlin

This is an excerpt from Manning's book The Joy of Kotlin.

Considering your maximum multiple problems, when writing the interface, you realize that it’s not always easy to find such properties. Remember that you must find a set of properties that can be verified on all tuples of type ((Int, List<Int>), Int) that will be true if the last Int is the correct result of applying the function to the pair Int, List<Int>. Here’s a reminder of the function signature:

Here, Kotlin guesses the type by looking forward to the value used to initialize the field. This is called type inference, and it lets you omit the type in numerous cases. But there are places where type inference won’t work, such as when the type is ambiguous or the field isn’t initialized. In these cases, you must specify the type.

It’s generally wise, however, to specify the type. By doing so, you can check that the type inferred by Kotlin is the type you expect. Believe me, that won’t always be the case!

val ls = listOf("A String")
val la = ls + 42 // <- Kotlin infers the type `List<Any>` for `la`

In Java, types are invariant, which means that if A is a parent type of B, List<A> is neither a parent type nor a child type of List<B>. List<A> and List<B> are two different types at compile time (and the same type at runtime). The problem with invariant types is that you can’t write the following: