[Haskell-cafe] Order of evaluation

2007-07-26 Thread Jon Harrop
If you have a boolean-or expression: a || b will "a" be evaluated before "b" in Haskell as it is in other languages? -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. OCaml for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/?e ___

[Haskell-cafe] Order of Evaluation

2008-05-09 Thread PR Stanley
Hi (take 4 . map (>0)) (f s t) where s = 2 : t t = 3 : s f = zipWith (-) What would be the order of evaluation for the above code? How would I illustrate the evaluation step-by-step? I'm guessing that the code necessitates lazy evaluation and as such it starts with take then

Re: [Haskell-cafe] Order of evaluation

2007-07-26 Thread Derek Elkins
On Thu, 2007-07-26 at 12:04 -0500, Spencer Janssen wrote: > On Thursday 26 July 2007 11:02:00 Jon Harrop wrote: > > On Thursday 26 July 2007 17:03:31 C.M.Brown wrote: > > > Hi Jon, > > > > > > On Thu, 26 Jul 2007, Jon Harrop wrote: > > > > If you have a boolean-or expression: > > > > > > > > a ||

Re: [Haskell-cafe] Order of evaluation

2007-07-26 Thread Spencer Janssen
On Thursday 26 July 2007 11:02:00 Jon Harrop wrote: > On Thursday 26 July 2007 17:03:31 C.M.Brown wrote: > > Hi Jon, > > > > On Thu, 26 Jul 2007, Jon Harrop wrote: > > > If you have a boolean-or expression: > > > > > > a || b > > > > > > will "a" be evaluated before "b" in Haskell as it is in oth

Re: [Haskell-cafe] Order of evaluation

2007-07-26 Thread Jon Harrop
On Thursday 26 July 2007 17:03:31 C.M.Brown wrote: > Hi Jon, > > On Thu, 26 Jul 2007, Jon Harrop wrote: > > If you have a boolean-or expression: > > > > a || b > > > > will "a" be evaluated before "b" in Haskell as it is in other languages? > > Yes, I believe it is defined thus: > > True || _

Re: [Haskell-cafe] Order of evaluation

2007-07-26 Thread C.M.Brown
Hi Jon, On Thu, 26 Jul 2007, Jon Harrop wrote: > > If you have a boolean-or expression: > > a || b > > will "a" be evaluated before "b" in Haskell as it is in other languages? > Yes, I believe it is defined thus: True || _= True _|| True = True _|| _= False Therefore it is st

Re: [Haskell-cafe] Order of evaluation

2007-07-26 Thread Jonathan Cast
On Thursday 26 July 2007, Jon Harrop wrote: > If you have a boolean-or expression: > > a || b > > will "a" be evaluated before "b" in Haskell as it is in other languages? Yes. The definition of (||) is roughly True || b = True False || b = b Which de-sugars to (||) = \ a b -> case a of Tru

Re: [Haskell-cafe] Order of Evaluation

2008-05-09 Thread Miguel Mitrofanov
On 9 May 2008, at 21:52, PR Stanley wrote: Hi (take 4 . map (>0)) (f s t) where s = 2 : t t = 3 : s f = zipWith (-) What would be the order of evaluation for the above code? How would I illustrate the evaluation step-by-step? What do you need it for, really? Pure functional

Re: [Haskell-cafe] Order of Evaluation

2008-05-09 Thread Donnie Jones
Hello, I'm quite new to Haskell, but this is my understanding... Please correct me if I am wrong, as there is a good chance I am. ;) ### Begin Code ### module Main where main = putStrLn (show( (take 4 . map (> 0)) (f s t) )) where s = 2 : t t = 3 : s f = zipWith (-) {- - Output

Re: [Haskell-cafe] Order of Evaluation

2008-05-09 Thread Richard Kelsall
PR Stanley wrote: (take 4 . map (>0)) (f s t) where s = 2 : t t = 3 : s f = zipWith (-) What would be the order of evaluation for the above code? As I understand it Haskell does not specify an order of evaluation and it would therefore be a mistake to write a program which relies on

Re: [Haskell-cafe] Order of Evaluation

2008-05-09 Thread Miguel Mitrofanov
As I understand it Haskell does not specify an order of evaluation and it would therefore be a mistake to write a program which relies on a particular evaluation order. This is the 'unsafe' aspect of unsafePerformIO. Hmm... IMHO unsafePerformIO is 'unsafe' because it can lead to type errors in

Re: [Haskell-cafe] Order of Evaluation

2008-05-09 Thread PR Stanley
Hi (take 4 . map (>0)) (f s t) where s = 2 : t t = 3 : s f = zipWith (-) What would be the order of evaluation for the above code? How would I illustrate the evaluation step-by-step? What do you need it for, really? Pure functional programs are not about evaluation order, but a

Re: [Haskell-cafe] Order of Evaluation

2008-05-09 Thread Lennart Augustsson
As others have pointed out, there are many allowed evaluation orders of this expressions. But not only that, how it gets evaluated depends on how you are going to use it. Say that you print it, then you need all 4 elements, but say that it's oly going to be used as an argument to null, then you wi

Re: [Haskell-cafe] Order of Evaluation

2008-05-09 Thread Albert Y. C. Lai
Lennart Augustsson wrote: Even so, it's instructive to study how the normal order reduction of this expression would proceed under the assumption that all 4 elements will be used. I think it's useful to try normal order until weak head normal form. Not all steps are shown. Definitions of take

Re: [Haskell-cafe] Order of Evaluation

2008-05-10 Thread Daniil Elovkov
Hello You may find this paper useful http://research.microsoft.com/~simonpj/Papers/spineless-tagless-gmachine.ps.gz It should give you the general feeling of how things are actually executed. It's quite old, some things in GHC have changed, but the overall scheme, I believe, is the same. The

Re: [Haskell-cafe] Order of Evaluation

2008-05-11 Thread Richard Kelsall
Miguel Mitrofanov wrote: As I understand it Haskell does not specify an order of evaluation and it would therefore be a mistake to write a program which relies on a particular evaluation order. This is the 'unsafe' aspect of unsafePerformIO. Hmm... IMHO unsafePerformIO is 'unsafe' because it ca