Re: [Haskell-cafe] What is the role of $!?

2007-12-10 Thread Jules Bean
David Fox wrote: Here is a practical example I ran into a few days ago. With this expression: writeFile path (compute text) the file at path would be overwritten with an empty file if an error occurs while evaluating (compute text). With this one: writeFile path $! (compute text)

role of seq, $!, and bangpatterns illuminated with lazy versus strict folds Re: [Haskell-cafe] What is the role of $!?

2007-12-10 Thread Thomas Hartman
rather than ask the role of $! I found it helpful to first grasp the role of seq, since $! is defined in terms of seq and seq is a primitive operation (no prelude definition, like with IO, it's a given). What helped me grasp seq was its role in a strict fold. Basically, try to sum all the

Re: role of seq, $!, and bangpatterns illuminated with lazy versus strict folds Re: [Haskell-cafe] What is the role of $!?

2007-12-10 Thread Albert Y. C. Lai
Thomas Hartman wrote: -- (myfoldl f q ) is a curried function that takes a list -- If I understand currectly, in this lazy fold, this curried function isn't applied immediately, because -- by default the value of q is still a thunk myfoldl f z [] = z myfoldl f z (x:xs) = ( myfoldl f q ) xs

Re: [Haskell-cafe] What is the role of $!?

2007-12-10 Thread Dean Herington
Thanks, Tom, for a nice description of lazy evaluation. Besides the minor things Derek pointed out, there's one more subtle but important thing to correct: At 7:29 AM + 11/29/07, Thomas Davie wrote: $! is the special case, which means strictly apply. It evaluates its argument first,

Re: [Haskell-cafe] What is the role of $!?

2007-12-09 Thread David Fox
Argh, that last sentence should read the file is left alone.. On Dec 9, 2007 10:15 PM, David Fox [EMAIL PROTECTED] wrote: Here is a practical example I ran into a few days ago. With this expression: writeFile path (compute text) the file at path would be overwritten with an empty file

Re: [Haskell-cafe] What is the role of $!?

2007-11-30 Thread Derek Elkins
On Thu, 2007-11-29 at 07:29 +, Thomas Davie wrote: On 29 Nov 2007, at 06:32, PR Stanley wrote: Hi Thanks for the response. JCC: In most languages, if you have some expression E, and when the computer attempts to evaluate E it goes in to an infinite loop, then when the

Re: [Haskell-cafe] What is the role of $!?

2007-11-28 Thread PR Stanley
Hi Thanks for the explanation. I would be grateful for some examples accompanying the text. I will indicate the right places for real life (Haskell code) examples in the paragraphs below: PJ: As I understand it, the distinction is between the mathematical term non-strict and the

Re: [Haskell-cafe] What is the role of $!?

2007-11-28 Thread Luke Palmer
On Nov 29, 2007 4:23 AM, PR Stanley [EMAIL PROTECTED] wrote: PRS: You would also get different results - e.g. let a = 3, b = 7, c = 2 therefore 20 = strict ( ( (a+(b*c)) ) therefore 17 = non-strict ( (a+(b*c)) ) or am I misunderstanding the

Re: [Haskell-cafe] What is the role of $!?

2007-11-28 Thread PR Stanley
Hi Thanks for the response. JCC: In most languages, if you have some expression E, and when the computer attempts to evaluate E it goes in to an infinite loop, then when the computer attempts to evaluate the expression f(E), it also goes into an infinite loop, regardless of what f is. That's

Re: [Haskell-cafe] What is the role of $!?

2007-11-28 Thread Thomas Davie
On 29 Nov 2007, at 06:32, PR Stanley wrote: Hi Thanks for the response. JCC: In most languages, if you have some expression E, and when the computer attempts to evaluate E it goes in to an infinite loop, then when the computer attempts to evaluate the expression f(E), it also goes into

Re: [Haskell-cafe] What is the role of $!?

2007-11-19 Thread Henning Thielemann
On Sun, 18 Nov 2007, Andrew Coppin wrote: Lauri Alanko wrote: Please note that if you're using GHC, bang patterns are often much more convenient than $! or seq when you want to enforce strictness: http://www.haskell.org/ghc/docs/latest/html/users_guide/bang-patterns.html Wait, so...

Re: [Haskell-cafe] What is the role of $!?

2007-11-18 Thread Andrew Coppin
PR Stanley wrote: Hi okay, so $! is a bit like $ i.e. the equivalent of putting parentheses around the righthand expression. I'm still not sure of the difference between $ and $!. Maybe it's because I don't understand the meaning of strict application. While we're on the subject, what's meant

Re: [Haskell-cafe] What is the role of $!?

2007-11-18 Thread Paul Johnson
Andrew Coppin wrote: PS. There is a technical distinction between the terms lazy and non-strict, and also the opposite terms eger and strict. I couldn't tell you what that is. As I understand it, the distinction is between the mathematical term non-strict and the implementation method of

Re: [Haskell-cafe] What is the role of $!?

2007-11-18 Thread David Menendez
On Nov 18, 2007 9:23 AM, Paul Johnson [EMAIL PROTECTED] wrote: Obviously there is a strong correspondance between a thunk and a partly-evaluated expression. Hence in most cases the terms lazy and non-strict are synonyms. But not quite. For instance you could imagine an evaluation engine on

Re: [Haskell-cafe] What is the role of $!?

2007-11-18 Thread Lauri Alanko
Please note that if you're using GHC, bang patterns are often much more convenient than $! or seq when you want to enforce strictness: http://www.haskell.org/ghc/docs/latest/html/users_guide/bang-patterns.html Lauri ___ Haskell-Cafe mailing list

Re: [Haskell-cafe] What is the role of $!?

2007-11-18 Thread Andrew Coppin
Lauri Alanko wrote: Please note that if you're using GHC, bang patterns are often much more convenient than $! or seq when you want to enforce strictness: http://www.haskell.org/ghc/docs/latest/html/users_guide/bang-patterns.html Wait, so... f x = x + 1; f $! (a + b) and f !x = x + 1;

Re: [Haskell-cafe] What is the role of $!?

2007-11-17 Thread PR Stanley
Hi okay, so $! is a bit like $ i.e. the equivalent of putting parentheses around the righthand expression. I'm still not sure of the difference between $ and $!. Maybe it's because I don't understand the meaning of strict application. While we're on the subject, what's meant by Haskell being

Re: [Haskell-cafe] What is the role of $!?

2007-11-17 Thread Jonathan Cast
On 17 Nov 2007, at 8:04 PM, PR Stanley wrote: Hi okay, so $! is a bit like $ i.e. the equivalent of putting parentheses around the righthand expression. I'm still not sure of the difference between $ and $!. Maybe it's because I don't understand the meaning of strict application. While

Re: [Haskell-cafe] What is the role of $!?

2007-11-14 Thread Justin Bailey
It's: f $! x = x `seq` f x That is, the argument to the right of $! is forced to evaluate, and then that value is passed to the function on the left. The function itself is not strictly evaluated (i.e., f x) I don't believe. Justin ___ Haskell-Cafe

Re: [Haskell-cafe] What is the role of $!?

2007-11-14 Thread Shachaf Ben-Kiki
On Nov 14, 2007 4:27 PM, Justin Bailey [EMAIL PROTECTED] wrote: It's: f $! x = x `seq` f x That is, the argument to the right of $! is forced to evaluate, and then that value is passed to the function on the left. The function itself is not strictly evaluated (i.e., f x) I don't believe.

Re: [Haskell-cafe] What is the role of $!?

2007-11-14 Thread Derek Elkins
On Wed, 2007-11-14 at 16:27 -0800, Justin Bailey wrote: It's: f $! x = x `seq` f x That is, the argument to the right of $! is forced to evaluate, and then that value is passed to the function on the left. The function itself is not strictly evaluated (i.e., f x) I don't believe.

Re: [Haskell-cafe] What is the role of $!?

2007-11-14 Thread Jonathan Cast
On 14 Nov 2007, at 4:32 PM, Shachaf Ben-Kiki wrote: On Nov 14, 2007 4:27 PM, Justin Bailey [EMAIL PROTECTED] wrote: It's: f $! x = x `seq` f x That is, the argument to the right of $! is forced to evaluate, and then that value is passed to the function on the left. The function itself is