Re: [Haskell-cafe] Safer common subexpression elimination

2010-12-04 Thread Henning Thielemann
Joachim Breitner schrieb: Hi, although semantically it could, ghc does not do common subexpression elimination (CSE), at least not in every case. The canonical example where it would be bad is the function (with div to avoid numerical casting): avg :: [Int] - Int avg n = (sum [0..n]

Re: [Haskell-cafe] Safer common subexpression elimination

2010-12-04 Thread Joachim Breitner
Hello Henning, Am Samstag, den 04.12.2010, 12:41 +0100 schrieb Henning Thielemann: Joachim Breitner schrieb: Now consider the program: avg' :: [Int] - (Int, Int) avg' n = (sum [0..n] `div` length [0..n], length [0..n]) It think this is not typecorrect, since 'n' denotes a list and

Re: [Haskell-cafe] Safer common subexpression elimination

2010-12-04 Thread Henning Thielemann
Joachim Breitner schrieb: Am Samstag, den 04.12.2010, 12:41 +0100 schrieb Henning Thielemann: Joachim Breitner schrieb: Now consider the program: avg' :: [Int] - (Int, Int) avg' n = (sum [0..n] `div` length [0..n], length [0..n]) It think this is not typecorrect, since 'n' denotes a list

Re: [Haskell-cafe] Safer common subexpression elimination

2010-11-27 Thread John Meacham
On Thu, Nov 25, 2010 at 2:32 AM, Joachim Breitner m...@joachim-breitner.dewrote: So I wonder: * Is sharing values of type Int (and Bool and similar small values) always safe? * If so: does GHC already do that? * Would it be technically possible? * Is there an established theory that can

Re: [Haskell-cafe] Safer common subexpression elimination

2010-11-26 Thread Josef Svenningsson
On Thu, Nov 25, 2010 at 11:32 AM, Joachim Breitner m...@joachim-breitner.de wrote: Hi, although semantically it could, ghc does not do common subexpression elimination (CSE), at least not in every case. The canonical example where it would be bad is the function (with div to avoid numerical

[Haskell-cafe] Safer common subexpression elimination

2010-11-25 Thread Joachim Breitner
Hi, although semantically it could, ghc does not do common subexpression elimination (CSE), at least not in every case. The canonical example where it would be bad is the function (with div to avoid numerical casting): avg :: [Int] - Int avg n = (sum [0..n] `div` length [0..n]) The reason why