title: Convert a Haskell code to Python or pseudocode
body: <p>I am working on <a href="https://www.cs.ox.ac.uk/jeremy.gibbons/publications/spigot.pdf" rel="nofollow">an algorithm</a>. But I am not very clear on the haskell code provide by the author, so I need you guys' help.
  The codes can split into two parts, I think.</p>
  
  <pre class="lang-hs prettyprint-override"><code>&gt; type LFT = (Integer, Integer, Integer, Integer)
  &gt;
  &gt; extr :: LFT -&gt; Integer -&gt; Rational
  &gt; extr (q,r,s,t) x = ((fromInteger q) * x + (fromInteger r)) / ((fromInteger s) * x + (fromInteger t))
  &gt;
  &gt; unit :: LFT
  &gt; unit = (1,0,0,1)
  &gt;
  &gt; comp :: LFT -&gt; LFT -&gt; LFT
  &gt; comp (q,r,s,t) (u,v,w,x) = (q*u+r*w,q*v+r*x,s*u+t*w,s*v+t*x)
  </code></pre>
  
  <p>Here, very clearly, a type called LFT (may be a tuple in Python) and three function called <code>extr unit comp</code> be defined.However, the next part puzzled me a lot:</p>
  
  <pre class="lang-hs prettyprint-override"><code>&gt; pi = stream next safe prod cons init lfts where
  &gt;   init = unit
  &gt;   lfts = [(k, 4*k+2, 0, 2*k+1) | k&lt;-[1..]]
  &gt;   next z = floor (extr z 3)
  &gt;   safe z n = (n == floor (extr z 4))
  &gt;   prod z n = comp (10, -10*n, 0, 1) z
  &gt;   cons z z’ = comp z z’
  </code></pre>
  
  <p>I believe <code>lfts</code> is a generator but I am failed to understand how the loop performed in this code and I do not know much about the Haskell. Can you help me convert this one to Python or a pseudocode?</p>