# Syntax Erro (Trie2D Put Method)

**URL:** <https://forum.dfinity.org/t/syntax-erro-trie2d-put-method/11403>\
**Category:** Language Support\
**Tags:** Motoko\
**Created:** [March 9, 2022, 4:56pm UTC](https://forum.dfinity.org/t/syntax-erro-trie2d-put-method/11403 "2022-03-09T16:56:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![h1teshtr1path1](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/h1teshtr1path1/32/24662_2.png) [@h1teshtr1path1](https://forum.dfinity.org/u/h1teshtr1path1)\
**Post date:** [March 9, 2022, 4:56pm UTC](https://forum.dfinity.org/t/syntax-erro-trie2d-put-method/11403/1 "2022-03-09T16:56:37Z")

</div>

I am trying to make a Trie2D :

```auto
var containerChunk : Trie2D.Trie2D<Nat32, Nat32, [Nat32]> = Trie.empty();

```

Now , I have to update this containerChunk, with this given key (Nat32) and for value (Nat32, [Nat32]) ,  
So I am finding Trie with given key using :

```auto
var chunk = Trie2D.find(containerChunk, key(pId), Nat32.equal);

```

and then I want to update this Trie , by putting (Key, Value)pair in it using :

```auto
chunk := Trie.put(chunk, key(chunkId), Nat32.equal, chunkData).0;

```

But Last method of updating it is giving error :

**cannot implicitly instantiate function of type  
\<K, V\>(Trie/351\<K, V\>, Key/351, (K, K) → Bool, ?V) →   
(Trie/351\<K, V\>, ?V)  
to argument of type  
(?Trie/351\<Nat32, Nat32\>, Key/351, (Nat32/646, Nat32/646) → Bool,  
[Nat32])  
because no instantiation of K/38405, V/39801 makes  
(?Trie/351\<Nat32, Nat32\>, Key/351, (Nat32/646, Nat32/646) → Bool,  
[Nat32]) \<:  
(Trie/351\<K/38405, V/39801\>, Key/351\<K/38405\>,  
(K/38405, K/38405) → Bool, ?V/39801)**

Please Help.

---

<div class="post-metadata">

**Author:** ![icme](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/icme/32/4327_2.png) [@icme](https://forum.dfinity.org/u/icme)\
**Post date:** [March 9, 2022, 5:21pm UTC](https://forum.dfinity.org/t/syntax-erro-trie2d-put-method/11403/2 "2022-03-09T17:21:47Z")

</div>

The `Trie.put` function requires you to provide type parameters to it

so I believe this should work…

`chunk := Trie.put<Nat32, [Nat32]>(chunk, key(chunkId), Nat32.equal, chunkData).0;`

Or whatever type you expect your `<K, V>` to be.

---

<div class="post-metadata">

**Author:** ![h1teshtr1path1](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/h1teshtr1path1/32/24662_2.png) [@h1teshtr1path1](https://forum.dfinity.org/u/h1teshtr1path1)\
**Post date:** [March 9, 2022, 5:38pm UTC](https://forum.dfinity.org/t/syntax-erro-trie2d-put-method/11403/3 "2022-03-09T17:38:42Z")

</div>

> [@icme](#):
>
> Trie.put\<Nat32, [Nat32]\>(chunk, key(chunkId), Nat32.equal, chunkData).0

Not Working , still showing error :

```auto
expression of type
  Trie/357<Nat32, [Nat32]> = {
                               #branch : Branch/357<Nat32, [Nat32]>;
                               #empty;
                               #leaf : Leaf/357<Nat32, [Nat32]>
                             }
cannot produce expected type
  ?Trie/357<Nat32, Nat32>

```

---

<div class="post-metadata">

**Author:** ![icme](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/icme/32/4327_2.png) [@icme](https://forum.dfinity.org/u/icme)\
**Post date:** [March 9, 2022, 5:55pm UTC](https://forum.dfinity.org/t/syntax-erro-trie2d-put-method/11403/4 "2022-03-09T17:55:29Z")

</div>

Ah, well now it’s just saying that you have a mismatch between an [option type](https://smartcontracts.org/docs/base-libraries/Option.html) that could be null `?`, and a type that will return a value every time

You also have a type mismatch between the value `[Nat]` vs `Nat`.

The error message is essentially telling you this.

---

<div class="post-metadata">

**Author:** ![h1teshtr1path1](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/h1teshtr1path1/32/24662_2.png) [@h1teshtr1path1](https://forum.dfinity.org/u/h1teshtr1path1)\
**Post date:** [March 9, 2022, 6:07pm UTC](https://forum.dfinity.org/t/syntax-erro-trie2d-put-method/11403/5 "2022-03-09T18:07:36Z")

</div>

so what should i do to remove type mismatch between a option type and value that will get returned?

Or to remove this Error?

```auto
expression of type
  Trie/431<Nat32, [Nat32]> = {
                               #branch : Branch/431<Nat32, [Nat32]>;
                               #empty;
                               #leaf : Leaf/431<Nat32, [Nat32]>
                             }
cannot produce expected type
  ?Trie/431<Nat32, [Nat32]>

```

---

<div class="post-metadata">

**Author:** ![icme](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/icme/32/4327_2.png) [@icme](https://forum.dfinity.org/u/icme)\
**Post date:** [March 9, 2022, 6:19pm UTC](https://forum.dfinity.org/t/syntax-erro-trie2d-put-method/11403/6 "2022-03-09T18:19:16Z")

</div>

> [@icme](#):
>
> [option type](https://smartcontracts.org/docs/base-libraries/Option.html)

See this link I posted above. It shows how to construct an option type, and how to deconstruct an option type via pattern matching.
