
On Thu, Dec 10, 2009 at 6:31 AM, Alberto G. Corona
My understanding is that a pointer to the lazy expression tree for the calcualtion of the parameter is put it the corresponding location of the function expression tree. But at any time you can force the evauation before the call. or the compiler itself. Optimization is possible depending on the knowledge. What happens if the parameter is an infinite list and the function handles a few items of it?.
All of these consideration pales when a programmer has to call a procdure in a library made by others with no documentation, and no clue about what the procedure does inside. The purity and the type system removes many concerns.
That's not a "safe" way to think of 3rd party libraries. It is a convenient claim for promoting the language, and is probably more often than not the case though it does not quite capture the whole truth. unsafePerformIO can exist in any library you import, and while you may think it's pure, you still have to implicitly trust the library writers (unless you bother to look at the source). Take Debug.Trace.trace for example, it's a pure computation, yet causes side effects. Yes, it's a controlled side effect, but a polluted version of the same function signature could "launch the missles" while looking like the function is synonymous with "id". In short unsafePerformIO, while it's "supposed to be" avoided, may not be avoided as much as the advice given to do so :-). Might be interesting to see how many occurrences of unsafePerformIO exist in hackage. I fully realize that someone will probably claim I'm taking this position to the extreme, but I think we're tempted to pretend that all functions with pure signatures are always safe which is another kind of extreme when you consider the existence of backdoors to the Monads that provide the guarantees we're clinging to to talk about how great Haskell is. I think the existence of unsafePerformIO is a bit of an admission that there's some things yet to be figured out to make this system 100% consistent with where we want pure functional programming to be. Dave
2009/12/10 David Leimbach
And that would be true if everything were strict and not partially
evaluated sometimes :-)
My understanding is the following... (and I could be way off)
Remember that a function of arity N is really N functions of arity 1 with their arguments bound one at a time to create a new function along the way. At least you *can* write your code that way if you really want to, but the laziness might make it such that all the parameters are not bound, due to not being "needed" at that moment. Instead a thunk or what some other languages might call a "Future" is put in the argument's place, to be evaluated when needed.
If Haskell were strict by default, I think your claim of passing references around could be true, but my experience with Haskell has been that sometimes it's too lazy for me to write the code that I first thought would be efficient without a lot f study and refactoring of that code.
I'm sure this gets easier with practice, but it's not something I was expecting to be as difficult as it all was.
Dave
On Thu, Dec 10, 2009 at 5:57 AM, Alberto G. Corona
wrote: One more advantage that is not frequently cited
Purity permits to pass every parameter of a procedure by reference (giving the pointer) rather that by value giving a copy, and still be sure that the data has not been modified. Besides the safety. this is great language optimization itself.
2009/12/10 Alberto G. Corona
What material benefit does Haskell derive from being a "pure" functional language as opposed to an impure one?
Here is my list of benefits of purity (some of them are enhanced by other features like the type system).
Purity means referential transparency. that means that the programmer has no way to modify pure data. That cut the tree of possible programmer errors.In particular, since there are no variables, every state change must be in the form o a call to a function with new parameters. each function has no state change (except when needed and then the type system labels the stateful code as such)( This enforcement goes in the righ direction for clarity and readability, maintainability, modularity xxxxxbility.
Purity also eases paralel processing, since no data is modified, each process is isolated better. Less opportunities for errors.
Purity permits lazines because since the execution tree of an expression has pure, data, can be evaluated later, since it will not be changed.
Lazy evaluation eases mathematical reasoning,because mathematics has no notion of eager evaluation, but to make use of mathematical equations when the calculation is needed. .
Mathematical reasoning permits the full use of a long tradition of mathematical knowledge. This makes code more simple, understandable, general, proof guarantted and elegant (for those that know the mathematical domain). This also permits high level optimization of code, both by the programmer and the compiler.
for sure there are a few more
We are superstitious and guided by "nonrational" ideas such is beauty. but:
bauauty -> (simplicity -> (less effort to master, less errors) , utility ->, solve more problems, solve greater problems )
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Hello David
Apropos the (unfortunately) frosty exchanges that greeted the first
release of UHC a couple of months ago, which argued that UHC wasn't
Haskell because it didn't implement n+k patterns, one could argue (at
least for rhetorical effect) that Haskell plus unsafePerformIO isn't
Haskell, I don't think you'll be able to find unsafePerformIO in the
report...
Best wishes
Stephen
2009/12/10 David Leimbach
That's not a "safe" way to think of 3rd party libraries. It is a convenient claim for promoting the language, and is probably more often than not the case though it does not quite capture the whole truth. unsafePerformIO can exist in any library you import,
[snip]
In short unsafePerformIO, while it's "supposed to be" avoided, may not be avoided as much as the advice given to do so :-).

Hi Stephen,
While it's fair to mention that unsafePerformIO is not in the report for the
reasons you give, it is present in some libraries. The practical reality of
the situation is you can not in general trust that because a function's
signature is pure, that the implementation of that function is.
I mean you can, and you can pay the price for when you're wrong, as can the
other people affected by that choice to trust that nothing fishy is going on
behind the scenes, but it'd be a bad idea.
Here's a really contrived example. Let's say you use a library, maybe one
of the soon to be supported shared libraries for GHC, and that you use some
pure functions of that library. Now let's say the system is compromised,
and a modified version of said library is installed on the system which
during the pure computation, has the effect of sending data that's being
computed to some other internet connected machine.
Now let's say you're a financial institution and the haskell code is running
part of a webserver with people's account data in it.
Now do you want to trust all pure functions implicitly?
I realize this might be a bit too much of a straw man, but some people
actually have to consider these possibilities.
Dave
On Thu, Dec 10, 2009 at 9:45 AM, Stephen Tetley
Hello David
Apropos the (unfortunately) frosty exchanges that greeted the first release of UHC a couple of months ago, which argued that UHC wasn't Haskell because it didn't implement n+k patterns, one could argue (at least for rhetorical effect) that Haskell plus unsafePerformIO isn't Haskell, I don't think you'll be able to find unsafePerformIO in the report...
Best wishes
Stephen
2009/12/10 David Leimbach
: That's not a "safe" way to think of 3rd party libraries. It is a
convenient
claim for promoting the language, and is probably more often than not the case though it does not quite capture the whole truth. unsafePerformIO can exist in any library you import, [snip] In short unsafePerformIO, while it's "supposed to be" avoided, may not be avoided as much as the advice given to do so :-).
participants (2)
-
David Leimbach
-
Stephen Tetley