This project is read-only.

stage_mass function

Chapter 2 contains, right below the stage_mass function, the following code:

     {
      r
      with Body =
       {
        r.Body
        with Position = 
         let p = r.Body.Position+r.Velocity*dt
         { p with X = max (p.X) earth_radius };
           Mass = r.BaseMass+stage_mass r.Stage1 
              +stage_mass r.Stage2 
              +stage_mass r.Stage3 
         };
         Velocity = r.Velocity+(F/r.Body.Mass)*dt 
     }



as you can see, Position and Mass are not vertically aligned, and this causes the code to fail to compile. The right code is the following, or any other source where Position and Mass are correctly aligned:

     {
      r
      with Body =
       {
        r.Body
        with 
          Position = 
           let p = r.Body.Position+r.Velocity*dt
           { p with X = max (p.X) earth_radius };
           Mass = r.BaseMass+stage_mass r.Stage1 
              +stage_mass r.Stage2 
              +stage_mass r.Stage3 
         };
         Velocity = r.Velocity+(F/r.Body.Mass)*dt 
     }





run coroutine

In Chapter 5, we say that we may run a coroutine with the following recursive function:

let rec run (c:Coroutine<'a>) : 'a =
 match c () with
 | Result x -> x
 | Yield c' | ArrowYield c' -> c'


unfortunately this function is incorrect, since it returns c' and not run c'; as it is written above, the function does not even type correctly, since 'a is not the same as Coroutine<'a>; the correct version of the function is:

let rec run (c:Coroutine<'a>) : 'a =
 match c () with
 | Result x -> x
 | Yield c' | ArrowYield c' -> run c'

Last edited Aug 28, 2011 at 4:40 PM by giuseppemag, version 2

Comments

No comments yet.