user2107: In the solution for the Lecture #4 (cohort 1 I guess, I'm following on Youtube)
payContract :: Contract () PaySchema Text () 
payContract = do
      pp <- endpoint @"pay"
      let tx = mustPayToPubKey (ppRecipient pp) $ lovelaceValueOf $ ppLovelace pp
      handleError (\err -> Contract.logInfo $ "caught error: " ++ unpack err) $ void $ submitTx tx
      payContract 

It appears that payContract calls itself, and this is required to get the payTest1 and payTest2 functions to actually run.
My question is: how does this not recurse infinitely? Where is the condition that stops it?
I'm still learning Haskell as I go and I come from a C# background, so I'm still getting my head around the functional programming thing.
TIA

user1130: Simply put, it could recurse infinitely.
Haskell doesn't have loops, so this is the equivalent of a while loop or something, where the exit case is the Contract monad throwing an error.
If you want to learn more, check out this page on tail recursion in Haskell.

user2201: payContract blocks on the first line of the do block until the pay endpoint is invoked. The input of the invocation is put in pp.
pp <- endpoint @"pay"

It then executes the endpoint invocation by creating the transaction and submitting it, and returns to the blocked state waiting for the next invocation.
It does recurse indefinitely, thus ensuring that the contract endpoints are available.

2107: <p>In the solution for the Lecture #4 (cohort 1 I guess, I'm following on Youtube)</p>
<pre><code>payContract :: Contract () PaySchema Text () 
payContract = do
      pp &lt;- endpoint @&quot;pay&quot;
      let tx = mustPayToPubKey (ppRecipient pp) $ lovelaceValueOf $ ppLovelace pp
      handleError (\err -&gt; Contract.logInfo $ &quot;caught error: &quot; ++ unpack err) $ void $ submitTx tx
      payContract 
</code></pre>
<p>It appears that payContract calls itself, and this is required to get the payTest1 and payTest2 functions to actually run.</p>
<p>My question is: how does this not recurse infinitely? Where is the condition that stops it?</p>
<p>I'm still learning Haskell as I go and I come from a C# background, so I'm still getting my head around the functional programming thing.</p>
<p>TIA</p>
 1130: <p>Simply put, it could recurse infinitely.</p>
<p>Haskell doesn't have loops, so this is the equivalent of a <code>while</code> loop or something, where the exit case is the <code>Contract</code> monad throwing an error.</p>
<p>If you want to learn more, check out this page on <a href="https://wiki.haskell.org/Tail_recursion" rel="nofollow noreferrer">tail recursion</a> in Haskell.</p>
 2201: <p><code>payContract</code> blocks on the first line of the <code>do</code> block until the pay endpoint is invoked. The input of the invocation is put in <code>pp</code>.</p>
<pre><code>pp &lt;- endpoint @&quot;pay&quot;
</code></pre>
<p>It then executes the endpoint invocation by creating the transaction and submitting it, and returns to the blocked state waiting for the next invocation.</p>
<p>It does recurse indefinitely, thus ensuring that the contract endpoints are available.</p>
