# Why doesn't \`\<system\>\` work?

**URL:** <https://forum.dfinity.org/t/why-doesnt-system-work/28304>\
**Category:** Motoko\
**Created:** [March 10, 2024, 6:03pm UTC](https://forum.dfinity.org/t/why-doesnt-system-work/28304 "2024-03-10T18:03:03Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![qwertytrewq](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/qwertytrewq/32/10423_2.png) [@qwertytrewq](https://forum.dfinity.org/u/qwertytrewq)\
**Post date:** [March 10, 2024, 6:03pm UTC](https://forum.dfinity.org/t/why-doesnt-system-work/28304/1 "2024-03-10T18:03:03Z")

</div>

I did add `<system>` to my code, but it does not compile anyway. What did I do wrong?

```auto
.mops/base@0.10.4/src/ExperimentalCycles.mo:96.60-96.77: type error [M0096], expression of type
  <system>Nat -> Nat
cannot produce expected type
  Nat -> Nat
.mops/base@0.10.4/src/ExperimentalCycles.mo:124.43-124.57: type error [M0096], expression of type
  <system>Nat -> ()
cannot produce expected type
  Nat -> ()

```

```auto
import Cycles "mo:base/ExperimentalCycles";
import Int "mo:base/Int";
import Debug "mo:base/Debug";
import Nat "mo:base/Nat";

module {
    public func topUpCycles<system>(maxCycles: Nat): (accepted : Nat) {
        // Debug.print("maxCycles: " # debug_show(maxCycles) # " Proposed cycles: " # debug_show(Cycles.available()) # " balance: " # debug_show(Cycles.balance()));
        // let amount = Int.min(maxCycles, Int.max(0, Cycles.available() + Cycles.balance()));
        let amount = Int.min(maxCycles, Cycles.available()) - Cycles.balance();
        let amount2 = Int.max(amount, 0);
        // Debug.print("Accepting cycles: " # debug_show(amount2));
        Cycles.accept<system>(Int.abs(amount2));
    };

    public func addPart<system>(maxAmount: Nat) {
        let amount = Nat.min(Cycles.balance() / 2, maxAmount);
        ignore Cycles.accept(amount);
        // Debug.print("adding " # debug_show(amount) # " cycles");
        Cycles.add<system>(amount);
    };
}

```

---

<div class="post-metadata">

**Author:** ![jamesbeadle](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jamesbeadle/32/10110_2.png) [@jamesbeadle](https://forum.dfinity.org/u/jamesbeadle)\
**Post date:** [March 10, 2024, 6:29pm UTC](https://forum.dfinity.org/t/why-doesnt-system-work/28304/2 "2024-03-10T18:29:22Z")

</div>

Functions using need to be async mate

---

<div class="post-metadata">

**Author:** ![jamesbeadle](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jamesbeadle/32/10110_2.png) [@jamesbeadle](https://forum.dfinity.org/u/jamesbeadle)\
**Post date:** [March 10, 2024, 6:30pm UTC](https://forum.dfinity.org/t/why-doesnt-system-work/28304/3 "2024-03-10T18:30:09Z")

</div>

![image](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/3X/c/9/c93e8c236d83f116a43cce455474a1900f1ff991.png)

Like that

---

<div class="post-metadata">

**Author:** ![qwertytrewq](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/qwertytrewq/32/10423_2.png) [@qwertytrewq](https://forum.dfinity.org/u/qwertytrewq)\
**Post date:** [March 10, 2024, 7:57pm UTC](https://forum.dfinity.org/t/why-doesnt-system-work/28304/4 "2024-03-10T19:57:20Z")

</div>

But why? Isn’t this async an extra slow-down?!

In the previous version of the compiler (before `<system>` appeared), async was not required. And that was OK.

---

<div class="post-metadata">

**Author:** ![timo](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/timo/32/5543_2.png) [@timo](https://forum.dfinity.org/u/timo)\
**Post date:** [March 10, 2024, 8:15pm UTC](https://forum.dfinity.org/t/why-doesnt-system-work/28304/5 "2024-03-10T20:15:21Z")

</div>

Don’t think async is required.

It’s probably this line in `addPart`:

```auto
ignore Cycles.accept<system>(amount);

```

---

<div class="post-metadata">

**Author:** ![qwertytrewq](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/qwertytrewq/32/10423_2.png) [@qwertytrewq](https://forum.dfinity.org/u/qwertytrewq)\
**Post date:** [March 10, 2024, 8:28pm UTC](https://forum.dfinity.org/t/why-doesnt-system-work/28304/6 "2024-03-10T20:28:12Z")

</div>

> [@timo](#):
>
> It’s probably this line in `addPart`:

No, after I added this it still does not compile.

---

<div class="post-metadata">

**Author:** ![dfxjesse](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/dfxjesse/32/17424_2.png) [@dfxjesse](https://forum.dfinity.org/u/dfxjesse)\
**Post date:** [March 10, 2024, 8:57pm UTC](https://forum.dfinity.org/t/why-doesnt-system-work/28304/7 "2024-03-10T20:57:09Z")

</div>

My guess is you are using Motoko 10 or below? But your Motoko plugin is expecting motoko 11?

```auto
cannot produce expected type
  Nat -> ()

```

This type is from Motoko 10

---

<div class="post-metadata">

**Author:** ![timo](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/timo/32/5543_2.png) [@timo](https://forum.dfinity.org/u/timo)\
**Post date:** [March 10, 2024, 9:12pm UTC](https://forum.dfinity.org/t/why-doesnt-system-work/28304/8 "2024-03-10T21:12:34Z")

</div>

> [@dfxjesse](#):
>
> My guess is you are using Motoko 10 or below?

Probably so, indicated by the output mentioning base@0.10.4. I guess base@0.10.4 wouldn’t work with moc 0.11.0 and would result in different (earlier) errors at the imports already.

---

<div class="post-metadata">

**Author:** ![qwertytrewq](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/qwertytrewq/32/10423_2.png) [@qwertytrewq](https://forum.dfinity.org/u/qwertytrewq)\
**Post date:** [March 10, 2024, 9:41pm UTC](https://forum.dfinity.org/t/why-doesnt-system-work/28304/9 "2024-03-10T21:41:44Z")

</div>

> [@dfxjesse](#):
>
> ```auto
> cannot produce expected type
> Nat -> ()
> 
> ```
> 
> This type is from Motoko 10

No, I use 11:

```auto
$ moc --version
Motoko compiler 0.11.0+ (source yh3wb1vx-vj8j4j32-k8gq4m8y-4cxlqinf)

```

---

<div class="post-metadata">

**Author:** ![dfxjesse](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/dfxjesse/32/17424_2.png) [@dfxjesse](https://forum.dfinity.org/u/dfxjesse)\
**Post date:** [March 10, 2024, 9:56pm UTC](https://forum.dfinity.org/t/why-doesnt-system-work/28304/11 "2024-03-10T21:56:25Z")

</div>

Well actually looks like your code is not compiling, so that might be something else, nonetheless the update to Motoko 11 seems to have a brought a few bugs 🤔

---

<div class="post-metadata">

**Author:** ![qwertytrewq](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/qwertytrewq/32/10423_2.png) [@qwertytrewq](https://forum.dfinity.org/u/qwertytrewq)\
**Post date:** [March 11, 2024, 12:20am UTC](https://forum.dfinity.org/t/why-doesnt-system-work/28304/12 "2024-03-11T00:20:34Z")

</div>

The following solved the problem:

```plaintext
$ mops update base
Package installed base = "0.11.0"

```
