IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Okay, remember hearing that before, and I understand ...
... why it's hard to grok. How do you write a program without variables? Is there an example you can point to of how to do something useful? The definition I remember is that each function will always return the same value given the same inputs. What you've described seems to go several steps beyond that.
===

Purveyor of Doc Hope's [link|http://DocHope.com|fresh-baked dog biscuits and pet treats].
[link|http://DocHope.com|http://DocHope.com]
New Re: Okay, remember hearing that before, and I understand ...
Strict functional programming has no side-effects. What this means is that you can't change anything. You can, however, return something calculated from your inputs. Simplistically, a true functional program has an entry point, and all of the functions within just return a modified version of what's passed in, and the output is the result of calling all of the functions.

There are no global variables and no side-effects, and that's why a function will always return the same value given the same inputs. Nothing matters but the parameters that are passed in.

Because of this you have to go through some hoops to perform some imperative constructs: looping is done through recursion, for example.

// Crappy pseudocode example\nfunction forLoopPositiveIncrementsOnly(int from, int to, int inc, function dowhat)\n{\n  if (from > to) return;\n  dowhat(from);\n  loop(from + inc, to, dowhat);\n}


Note that there IS a stack, but you can't modify the values on the stack, just use them.
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
New So you can't have a (pseudo) random number generator?
New Those don't have side-effects
And given the same seed, a pseudo-random number generator will always return the same sequence of "random" numbers.
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
New I was too tearse.
Some random number generators are more random than others. :-) I'm aware of the limitations of typical pseudo random number generators. I was too tearse in putting that in the Subject. (One of many true random number generators is [link|http://www.fourmilab.ch/hotbits/|HotBits].)

I wasn't questioning the "side-effects" aspect (I don't think), I was wondering whether it would be possible to hypotheically code a random number generator in a pure functional language given that, apparently, f(x0,t) = y0 for all x0 for a fuctional language, where a random number generator would give f(x0,t) = y(x0,t,gamma) (where gamma is some truly radom parameter). (If I didn't mess the notation up.) Presumably the code would talk to a radioactivity sensor or something similar that was truly random.

I would think that it must be possible, but wonder how it would be simply explained and whether it violates the premise of functional programming.

Thanks.

Cheers,
Scott.
New For pure functional programming, no
Because the program won't be provable for a given set of inputs.

Unless you count the external random number as one of the inputs, I suppose.
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
Expand Edited by admin March 11, 2006, 02:02:24 PM EST
New You can if you thread the state through the functions...
...and hence the introduction of monads.
     Erlang? - (tuberculosis) - (22)
         Threads, Messages, and Pattern Matching.... - (ChrisR) - (21)
             Right so to me this sounds like the ultimate SOA language - (tuberculosis) - (20)
                 I dunno - (jake123) - (18)
                     Quick CS101 pointer? Diff between fucntional and imperative? -NT - (drewk) - (17)
                         Re: Quick CS101 pointer? Diff between fucntional and imperat - (admin) - (16)
                             Okay, remember hearing that before, and I understand ... - (drewk) - (6)
                                 Re: Okay, remember hearing that before, and I understand ... - (admin) - (5)
                                     So you can't have a (pseudo) random number generator? -NT - (Another Scott) - (4)
                                         Those don't have side-effects - (admin) - (3)
                                             I was too tearse. - (Another Scott) - (2)
                                                 For pure functional programming, no - (admin)
                                                 You can if you thread the state through the functions... - (ChrisR)
                             Is this worth going through? - (broomberg) - (3)
                                 Shorter read.... - (ChrisR) - (2)
                                     Already did that - (broomberg) - (1)
                                         I didn't find the gentle intro useful when I read it... - (ChrisR)
                             The three pillars - (ChrisR) - (4)
                                 You just lost me - (drewk) - (3)
                                     Google the terms - (ben_tilly)
                                     Quick explanation - (ChrisR) - (1)
                                         One other important concept worth mentioning is Currying - (ChrisR)
                 Erlang does look very intriguing, will hopefully influence - (tonytib)

He clearly said, "To blave".
61 ms