
Hi all, If I have the following module: ----------8<--------------------8<---------- module Q (foo) where foo :: String -> [String] -> Bool #ifdef FIRST foo x _ | x `seq` x == "." = True #else foo x _ | x == "." = True #endif foo x xs = x `seq` any (x ==) xs ----------8<--------------------8<---------- then I would expect the code to be identical regardless of whether FIRST is defined or not. However, the following shows that (without the first seq) GHC forces the evaluation of x due to the seq in the last line. But, as I understand it, it should know that x has already been evaluated (to WHNF). This also seems to affect what gets inlined in larger examples. Am I confused? $ rm -f *.o $ /usr/bin/ghc -ddump-simpl -cpp -O -c Q.hs -DFIRST > 1 $ rm -f *.o $ /usr/bin/ghc -ddump-simpl -cpp -O -c Q.hs > 2 $ diff -u1000 1 2 --- 1 Fri Jun 25 02:11:46 2004 +++ 2 Fri Jun 25 02:12:02 2004 @@ -1,32 +1,34 @@ ==================== Tidy Core ==================== Q.a :: GHC.Base.Char [GlobalId] NoCafRefs Str: DmdType m Q.a = GHC.Base.C# '.' Q.lvl :: [GHC.Base.Char] [GlobalId] NoCafRefs Str: DmdType Q.lvl = GHC.Base.: @ GHC.Base.Char Q.a (GHC.Base.[] @ GHC.Base.Char) Q.foo :: GHC.Base.String -> [GHC.Base.String] -> GHC.Base.Bool [GlobalId] Arity 2 NoCafRefs Str: DmdType SL Q.foo = \ x :: GHC.Base.String ds :: [GHC.Base.String] -> case GHC.Base.eqString x Q.lvl of wild { GHC.Base.True -> GHC.Base.True; GHC.Base.False -> + case x of tpl { __DEFAULT -> GHC.List.any @ GHC.Base.String - (\ ds1 :: GHC.Base.String -> GHC.Base.eqString x ds1) + (\ ds1 :: GHC.Base.String -> GHC.Base.eqString tpl ds1) ds + } } ==================== Tidy Core Rules ==================== $ Thanks Ian
participants (1)
-
Ian Lynagh