|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
>> 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...
The trouble is, as soon as you start assigning more than one value to
something, it suddenly matters *when* you read it's value. And that
means if you start reordering things, everything goes horribly wrong.
Haskell does not permit you to assign more than one value to any given
variable. Thus, Haskell is able to chase down dependencies (even
circular ones) and Do The Right Thing(tm). So it really is a math-style
definition that always holds rather than an imperative-style assignment
at a specific point in time.
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Orchid XP v7 <voi### [at] devnull> wrote:
> 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]
I wonder what something along the lines of this would do:
foo a =
let res = if a<2 then 1 else a*foo(a-1)
in res
--
- Warp
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Orchid XP v7 <voi### [at] devnull> wrote:
> > I asked because 'let' sounded to me like an assignment, which is not
> > functional.
>
> I'm pretty sure you're right about Lisp. But in Haskell, it's not an
> assignment - although it does look like one.
In Scheme and Lisp, let introduces new lexical scoped bindings for values, just
like in Haskell. Except someone can use set! on them and break all referential
transparency apart...
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Orchid XP v7 <voi### [at] devnull> wrote:
> And how do you suggest I do that, given that there's no obvious "entry
> point"?
run one of them, perhaps "un", on some RSA key?
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Nicolas Alvarez wrote:
> http://rinkworks.com/stupid/cs_programming.shtml
Woah. Some of these are pretty "special" BTW... :-D
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
nemesis wrote:
> Orchid XP v7 <voi### [at] devnull> wrote:
>>> I asked because 'let' sounded to me like an assignment, which is not
>>> functional.
>> I'm pretty sure you're right about Lisp. But in Haskell, it's not an
>> assignment - although it does look like one.
>
> In Scheme and Lisp, let introduces new lexical scoped bindings for values, just
> like in Haskell. Except someone can use set! on them and break all referential
> transparency apart...
Ah, OK.
IIRC there's also a bunch of functions for modifying lists in-place that
Haskell also doesn't have...
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
nemesis <nam### [at] gmailcom> wrote:
> In Scheme and Lisp, let introduces new lexical scoped bindings for values, just
> like in Haskell. Except someone can use set! on them and break all referential
> transparency apart...
Maybe I confused "let" with "set".
--
- Warp
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Jim Henderson <nos### [at] nospamcom> wrote:
> Well, yes, but at the same time, there must be a definitive reference on
> it. Or is it the "ipsum lorem" text that's considered definitive? ;-)
googled:
http://www.muppetlabs.com/~breadbox/bf/
I don't lose time with that kind of stuff...
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Warp wrote:
> I wonder what something along the lines of this would do:
>
> foo a =
> let res = if a<2 then 1 else a*foo(a-1)
> in res
Looks like YAFFI [Yet Another Factorial Function] to me. ;-)
[And yes, for anybody else reading it, it works just fine...]
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Nicolas Alvarez <nic### [at] gmailisthebestcom> wrote:
> 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."
a functional programmer with no prior exposure to the imperative paradigm?!
Haskell is creating mindless monsters! :D
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |