1

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?

1
  • Could you resolve your question with any of the answers here?
    – kindofdev
    Feb 16, 2022 at 13:29

2 Answers 2

0

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.

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.