|
|
> So what's the difference? Well, let's try this:
>
> function solve2(a, b, c)
> {
> var det = Math.sqrt(det2);
> var det2 = b*b - 4*a*c;
> var a2 = 2*a;
> return Array((0-b-dat)/a2, (0-b+det)/a2));
> }
>
> Hmm, that's not going to work properly... However, the corresponding
> Haskell works exactly as before:
>
> solve2 a b c =
> let det = sqrt det2
> det2 = b*b - 4*a*c
> a2 = 2*a
> in [(0-b-det)/a2, (0-b+det)/a2]
>
> So in Haskell, the ordering doesn't matter.
http://rinkworks.com/stupid/cs_programming.shtml
"An introductory programming student once asked me to look at his
program and figure out why it was always churning out zeroes as the
result of a simple computation. I looked at the program, and it was
pretty obvious:
begin
readln("Number of Apples", apples);
readln("Number of Carrots", carrots);
readln("Price for 1 Apple", a_price);
readln("Price for 1 Carrot", c_price);
writeln("Total for Apples", a_total);
writeln("Total for Carrots", c_total);
writeln("Total", total);
total := a_total + c_total;
a_total := apples * a_price;
c_total := carrots + c_price;
end;
* Me: "Well, your program can't print correct results before they're
computed."
* Him: "Huh? It's logical what the right solution is, and the computer
should reorder the instructions the right way."
---
So he was right after all...
Post a reply to this message
|
|