slight difference in strictness between -O0 and -O

main = print (map (const 'x') (take 1 (undefined:undefined))) In ghci, or with ghc -O0, this produces "x". With ghc -O, this produces Prelude.undefined. But hey, please don't sweat too much on it! I bet it is a rather pathological case.

On 3/12/07, Albert Y. C. Lai
main = print (map (const 'x') (take 1 (undefined:undefined)))
In ghci, or with ghc -O0, this produces "x". With ghc -O, this produces Prelude.undefined.
What version of ghc? Cheers, Kirsten -- Kirsten Chevalier* chevalier@alum.wellesley.edu *Often in error, never in doubt "make them believe, if not in magic, in money well spent" -- Annie Gallup

On 3/12/07, Kirsten Chevalier
On 3/12/07, Albert Y. C. Lai
wrote: main = print (map (const 'x') (take 1 (undefined:undefined)))
In ghci, or with ghc -O0, this produces "x". With ghc -O, this produces Prelude.undefined.
What version of ghc?
I was curious, so I checked this against ghc 6.6. Indeed, it exhibits the behavior Albert describes above. Same goes for the HEAD. In ghc 6.4.2, however, the program prints "x" whether compiled with -O or -O0. This does seem like a bug to me. Cheers, Kirsten -- Kirsten Chevalier* chevalier@alum.wellesley.edu *Often in error, never in doubt "Live fast, love hard, and wear corrective lenses if you need them." --Webb Wilder

On 3/12/07, Kirsten Chevalier
On 3/12/07, Kirsten Chevalier
wrote: On 3/12/07, Albert Y. C. Lai
wrote: main = print (map (const 'x') (take 1 (undefined:undefined)))
In ghci, or with ghc -O0, this produces "x". With ghc -O, this produces Prelude.undefined.
What version of ghc?
I was curious, so I checked this against ghc 6.6. Indeed, it exhibits the behavior Albert describes above. Same goes for the HEAD. In ghc 6.4.2, however, the program prints "x" whether compiled with -O or -O0.
This does seem like a bug to me.
I noticed that compiling with -O -frules-off causes the test program here to correctly print out "x". So, I was looking at the "take" rule in GHC/List.lhs. Doesn't this rule change the strictness of take? "take" [~1] forall n xs . take n xs = case n of I# n# -> build (\c nil -> foldr (takeFB c nil) (takeConst nil) xs n#) Cheers, Kirsten -- Kirsten Chevalier* chevalier@alum.wellesley.edu *Often in error, never in doubt "It's a woman's dream, this autonomy / Where the lines connect and the points stay free" -- Ferron

On 3/13/07, Kirsten Chevalier
I noticed that compiling with -O -frules-off causes the test program here to correctly print out "x". So, I was looking at the "take" rule in GHC/List.lhs. Doesn't this rule change the strictness of take?
"take" [~1] forall n xs . take n xs = case n of I# n# -> build (\c nil -> foldr (takeFB c nil) (takeConst nil) xs n#)
I may be talking to myself here, but what I mean is:
take 1 (1:undefined) [1] build (\ c nil -> foldr (takeFB c nil) (takeConst nil) (1:undefined) 1#) [1*** Exception: Prelude.undefined
(where takeFB and takeConst are defined as they are in GHC/List.lhs) So that rule doesn't seem to be quite right. Cheers, Kirsten -- Kirsten Chevalier* chevalier@alum.wellesley.edu *Often in error, never in doubt "80% of success is showing up."--Woody Allen

You are quite right. I've submitted a Trac report.
Simon
| -----Original Message-----
| From: glasgow-haskell-users-bounces@haskell.org [mailto:glasgow-haskell-users-bounces@haskell.org] On
| Behalf Of Kirsten Chevalier
| Sent: 13 March 2007 10:03
| To: Albert Y. C. Lai
| Cc: glasgow-haskell-users@haskell.org
| Subject: Re: slight difference in strictness between -O0 and -O
|
| On 3/13/07, Kirsten Chevalier
participants (3)
-
Albert Y. C. Lai
-
Kirsten Chevalier
-
Simon Peyton-Jones