<blockquote>
<p>Obviously my argument is wrong, because ppLovelace pp does give you the payment amount.</p>
</blockquote>
<p>Yes the argument is wrong because first of all the endpoint @&quot;pay&quot; return means it returns the value of @&quot;pay&quot; immediately so the side-effect which would be () is not reached. Also the function has a final call awaitPromise which returns a new monad with a different return value. Again the () is not seen by awaitPromise.</p>
<p>I hope I explained myself ok.</p>

CC BY-SA 4.0
2022-02-08T11:20:44.060Z
2022-02-08T11:20:44.060Z
d_fajardo
<p>Here, the full <strong>payContract</strong> in <strong>Homework.hs</strong>.</p>
<pre><code>payContract :: Contract () PaySchema Text ()
payContract = do
    pp &lt;- awaitPromise $ endpoint @&quot;pay&quot; return
    let tx = mustPayToPubKey (ppRecipient pp) $ lovelaceValueOf $ ppLovelace pp
    void $ submitTx tx
    payContract
</code></pre>
<p>where  <code>pp &lt;- awaitPromise $ endpoint @&quot;pay&quot; return</code>  is an intermediate computation which doesn't determine the type result of the function <strong>payContract</strong>. The type result of the function is given by the last expression in the function: <code>payContract</code>.</p>
<p>The type of <code>awaitPromise $ endpoint @&quot;pay&quot; return</code> is <strong>Contract () PaySchema PayParams</strong>. Therefore, pp is <strong>PayParams</strong>. But again, it's an intermediate computation.</p>

CC BY-SA 4.0
2022-02-08T10:26:51.823Z
2022-02-08T10:26:51.823Z
kindofdev
<p>This question is in the context of the homework for Lecture 4.
What is wrong with the following reasoning?</p>
<p>We know that <code>payContract</code> is type <code>m ()</code>, where <code>m</code> stands for the monad <code>Contract () PaySchema Text</code>.  Therefore</p>
<pre><code>payContract = do                                                                
    pp &lt;- awaitPromise $ endpoint @&quot;pay&quot; return
</code></pre>
<p>must bind <code>()</code> to the variable <code>pp</code>.  Hence pp does not contain information about PayParams.</p>
<p>Obviously my argument is wrong, because <code>ppLovelace pp</code> does give you the payment amount.  But where exactly is the error in my logic?</p>

CC BY-SA 4.0
2022-02-16T13:29:44.887Z
Could you resolve your question with any of the answers here?
kindofdev
<plutus-pioneer-program><monad>
About Homework 4 - Getting PayParams through binding
# About Homework 4 - Getting PayParams through binding

(Asked by: username_0 on 2022-02-08)

This question is in the context of the homework for Lecture 4.
What is wrong with the following reasoning?

We know that `payContract` is type `m ()`, where `m` stands for the monad `Contract () PaySchema Text`. Therefore

```
payContract = do                                                                
    pp <- awaitPromise $ endpoint @"pay" return

```

must bind `()` to the variable `pp`. Hence pp does not contain information about PayParams.

Obviously my argument is wrong, because `ppLovelace pp` does give you the payment amount. But where exactly is the error in my logic?

**Tags:** plutus-pioneer-program, monad

> **Comments:**
> **username_1**: Could you resolve your question with any of the answers here?  

---

## 2 answers

### Answer by username_2 on 2022-02-08. Score: 0 | Accepted answer

> Obviously my argument is wrong, because ppLovelace pp does give you the payment amount.

Yes the argument is wrong because first of all the endpoint @"pay" return means it returns the value of @"pay" immediately so the side-effect which would be () is not reached. Also the function has a final call awaitPromise which returns a new monad with a different return value. Again the () is not seen by awaitPromise.

I hope I explained myself ok.


---

### Answer by username_1 on 2022-02-08. Score: 0

Here, the full **payContract** in **Homework.hs**.

```
payContract :: Contract () PaySchema Text ()
payContract = do
    pp <- awaitPromise $ endpoint @"pay" return
    let tx = mustPayToPubKey (ppRecipient pp) $ lovelaceValueOf $ ppLovelace pp
    void $ submitTx tx
    payContract

```

where `pp <- awaitPromise $ endpoint @"pay" return` is an intermediate computation which doesn't determine the type result of the function **payContract**. The type result of the function is given by the last expression in the function: `payContract`.

The type of `awaitPromise $ endpoint @"pay" return` is **Contract () PaySchema PayParams**. Therefore, pp is **PayParams**. But again, it's an intermediate computation.


---

