[Haskell-cafe] GHC magic optimization ?

2009-12-03 Thread Emmanuel CHANTREAU
Hello One thing is magic for me: how GHC can know what function results to remember and what results can be forgotten ? Is it just a stupid buffer algorithm or is there some mathematics truths behind this ? I'm very happy about Haskell, it's so great to put some smart ideas in a computer. thank

Re: [Haskell-cafe] GHC magic optimization ?

2009-12-03 Thread Henning Thielemann
On Thu, 3 Dec 2009, Emmanuel CHANTREAU wrote: Hello One thing is magic for me: how GHC can know what function results to remember and what results can be forgotten ? Is it just a stupid buffer algorithm or is there some mathematics truths behind this ? Although it is not required by the Has

Re: [Haskell-cafe] GHC magic optimization ?

2009-12-03 Thread Eugene Kirpichov
Hi. There is actually no magic at all going on. Haskell has a reasonably well-defined evaluation model; you can approximate it, at least not taking IO into account, with lazy graph reduction (look that up on google). Probably that is the "mathematical truth" you're looking for. Actually, if Haske

Re: [Haskell-cafe] GHC magic optimization ?

2009-12-03 Thread Miguel Mitrofanov
Does this really mean that you want to know how the garbage collector works? Emmanuel CHANTREAU wrote: Hello One thing is magic for me: how GHC can know what function results to remember and what results can be forgotten ? Is it just a stupid buffer algorithm or is there some mathematics truth

Re: [Haskell-cafe] GHC magic optimization ?

2009-12-03 Thread Emmanuel CHANTREAU
Hello First, thank you for all answers. Le Thu, 03 Dec 2009 18:58:33 +0300, Miguel Mitrofanov a écrit : > Does this really mean that you want to know how the garbage collector > works? Well, I try to understand your question... I will take an example: f x y= x+y The program ask the user to

Re: [Haskell-cafe] GHC magic optimization ?

2009-12-03 Thread Evan Laforge
> I will take an example: > > f x y= x+y > > The program ask the user to enter two numbers and print the sum. If the > user enter "1 2" "f 1 2=3" is stored and a gargage collector is used to > remove this dandling expression later ? > If the user enter again "1 2", ghc search in dandling results to

Re: [Haskell-cafe] GHC magic optimization ?

2009-12-03 Thread Miguel Mitrofanov
I will take an example: f x y= x+y The program ask the user to enter two numbers and print the sum. If the user enter "1 2" "f 1 2=3" is stored and a gargage collector is used to remove this dandling expression later ? It's not stored in any way. If the user enter again "1 2", ghc searc

Re: [Haskell-cafe] GHC magic optimization ?

2009-12-04 Thread Neil Brown
Emmanuel CHANTREAU wrote: I will take an example: f x y= x+y The program ask the user to enter two numbers and print the sum. If the user enter "1 2" "f 1 2=3" is stored and a gargage collector is used to remove this dandling expression later ? If the user enter again "1 2", ghc search in dandl

Re: [Haskell-cafe] GHC magic optimization ?

2009-12-04 Thread Luke Palmer
On Fri, Dec 4, 2009 at 3:36 AM, Neil Brown wrote: > But let's say you have: > > g x y = f x y * f x y > > Now the compiler (i.e. at compile-time) can do some magic.  It can spot the > common expression and know the result of f x y must be the same both times, > so it can convert to: > > g x y = le

Re: [Haskell-cafe] GHC magic optimization ?

2009-12-04 Thread Joachim Breitner
Hi, Am Freitag, den 04.12.2009, 10:36 + schrieb Neil Brown: > But let's say you have: > > g x y = f x y * f x y > > Now the compiler (i.e. at compile-time) can do some magic. It can > spot the common expression and know the result of f x y must be the > same both times, so it can convert to

Re: [Haskell-cafe] GHC magic optimization ?

2009-12-04 Thread Mark Lentczner
On Dec 4, 2009, at 2:43 AM, Luke Palmer wrote: > So GHC leaves it to the user to specify sharing. If you want an > expression shared, let bind it and reuse. Does GHC treat where and let the same in this regard? Or in code, are these treated the same? > x'' = sum l + product l where l = [1..10

Re: [Haskell-cafe] GHC magic optimization ?

2009-12-04 Thread Luke Palmer
On Fri, Dec 4, 2009 at 9:44 AM, Mark Lentczner wrote: > > On Dec 4, 2009, at 2:43 AM, Luke Palmer wrote: > >> So GHC leaves it to the user to specify sharing.  If you want an >> expression shared, let bind it and reuse. > > Does GHC treat where and let the same in this regard? Or in code, are thes

Re: [Haskell-cafe] GHC magic optimization ?

2009-12-04 Thread Matt Morrow
Although, in Luke's example, > x = sum [1..10^6] + product [1..10^6] > x' = let l = [1..10^6] in sum l + product l We can do much much better, if we're sufficiently smart. -- Define: bar m n = foo (enumFromTo m n) foo xs = sum xs + prod xs -- We're given: sum = foldl (+) 0 product = foldl (*)

Re: [Haskell-cafe] GHC magic optimization ?

2009-12-04 Thread George Pollard
2009/12/4 Evan Laforge : > The interesting thing is CAFs, which at the top level will never be > out of scope and hence live forever. Untrue! CAFs can be garbage collected as well. See: http://www.haskell.org/pipermail/glasgow-haskell-users/2005-September/009051.html _

Re: [Haskell-cafe] GHC magic optimization ?

2009-12-04 Thread Matt Morrow
Fixing my errors: > x = sum [1..10^6] + product [1..10^6] > x' = let l = [1..10^6] in sum l + product l -- Define: bar m n = foo (enumFromTo m n) foo xs = sum xs + prod xs -- We're given: sum = foldl (+) 0 product = foldl (*) 1 foldl f z xs = case xs of [] -> [] x:xs -> foldl f (f z x

Re: [Haskell-cafe] GHC magic optimization ?

2009-12-04 Thread wren ng thornton
Luke Palmer wrote: On Fri, Dec 4, 2009 at 9:44 AM, Mark Lentczner wrote: On Dec 4, 2009, at 2:43 AM, Luke Palmer wrote: So GHC leaves it to the user to specify sharing. If you want an expression shared, let bind it and reuse. Does GHC treat where and let the same in this regard? Or in code,