E081: Anonymous Function Missing Parameter Type
This error is emitted when the compiler cannot infer the type of a parameter in an anonymous function (lambda) and no explicit type is provided.
The compiler needs to know the types of function parameters to properly type-check the function body. When there's not enough context to infer the type, you must provide an explicit type annotation.
Example
val f = (x) => x + 1
Error
-- [E081] Type Error: example.scala:1:9 ----------------------------------------
1 |val f = (x) => x + 1
| ^
| Missing parameter type
|
| I could not infer the type of the parameter x
Solution
// Add an explicit type annotation to the parameter
val f = (x: Int) => x + 1
// Or provide type context through the variable declaration
val f: Int => Int = x => x + 1
// Or use the function in a context that provides type information
val result = List(1, 2, 3).map(x => x + 1)
In this article