# Type Inference

In most cases, the Move compiler will be able to infer the type arguments so you don't have to write them down explicitly. Here's what the examples above would look like if we omit the type arguments:

```rust
fun foo() {
    let x = id(true);
    //        ^ <bool> is inferred

    let foo = Foo { x: true };
    //           ^ <bool> is inferred

    let Foo { x } = foo;
    //     ^ <bool> is inferred
}
```

Note: when the compiler is unable to infer the types, you'll need annotate them manually. A common scenario is to call a function with type parameters appearing only at return positions.

```rust
module my_addrx::TypeInference{
    use std::vector;

    fun foo() {
        // let v = vector::empty();
        //                    ^ The compiler cannot figure out the element type.

        let v = vector::empty<u64>();
        //                 ^~~~~ Must annotate manually.
    }
}
```

However, the compiler will be able to infer the type if that return value is used later in that function:

```rust
module my_addrx::TypeInference{
    use std::vector;

    fun foo() {
        let v = vector::empty();
        //                 ^ <u64> is inferred
        vector::push_back(&mut v, 100);
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://move-developers-dao.gitbook.io/aptos-move-by-example/intermediate-concepts/type-inference.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
