title: How to transform Scheme program into Haskell?
body: <p>I'm going to transform a scheme program into Haskell but I'm having a hard time learning all about Haskell. If you are familiar with SICP, I`m tasked to answer Exercises 3.63, 3.64, 3.65, 3.66 and 3.71. I have already found the answers to these problems but they are written in scheme. Here is the question and answer in 3.63:</p>
  
  <blockquote>
    <p>Exercise 3.63. Louis Reasoner asks why the sqrt-stream procedure was not written in the following more straightforward way, without the local variable guesses:</p>
  
  <pre><code>(define (sqrt-stream x)
    (cons-stream 1.0
    (stream-map (lambda (guess)
    (sqrt-improve guess x))
      (sqrt-stream x))))
  </code></pre>
    
    <p>Alyssa P. Hacker replies that this version of the procedure is considerably less efficient because it performs redundant computation. </p>
    
    <p>Explain Alyssa's answer. </p>
    
    <p>Would the two versions still differ in efficiency if our implementation of delay used only <code>(lambda () &lt;exp&gt;)</code> without using the optimization provided by memo-proc (section 3.5.1)?</p>
  </blockquote>
  
  <p>Answer:</p>
  
  <blockquote>
    <p>In Louis Reasoner’s procedure, <code>(sqrt-stream x)</code> is recursively called inside <code>(sqrt-stream x)</code>. However, the two streams are not the same variable. Therefore redundant computation is performed. In the original version, a local variable guesses is used. </p>
  
  <pre><code>(define (sqrt-stream x)
     (define guesses
       (cons-stream 1.0
         (stream-map (lambda (guess)
              (sqrt-improve guess x))
                    guesses)))
     guesses)
  (display-stream (sqrt-stream 2))
  </code></pre>
  </blockquote>
  
  <p>Here is the Haskell code that I wrote and it's not working:</p>
  
  <pre><code>module Main
  where
  guess = 1:: Double
  x=0
  do
   if ((guess*guess) = x)
    then y = (x + guess) / x
    guess = y
   else
    sqrt x = guess
  </code></pre>
  
  <p>Please help me fix my codes. I need them next week.</p>
  
  <p>I'll also try the other ones and post them here if there there will be errors again. Hope you can help me.Thanks a lot.</p>