[Haskell-cafe] Hints for Euler Problem 11

Kim-Ee Yeoh a.biurvOir4 at asuhan.com
Fri Aug 17 04:38:49 EDT 2007


The compiler dumps are illuminating, thank you. 

I'm afraid I don't always compile under -O. In fact I never
debug with -O. I see now what I'm missing.

(Pain, grief, despair.)


Ketil Malde wrote:
> 
> On Thu, 2007-08-16 at 12:50 -0700, Kim-Ee Yeoh wrote:
>> Aaron Denney wrote:
>> > The compiler should be able to
>> > assemble it all at compile time, right?
>> 
>> 'Course not. The (++) function like all Haskell functions is only a
>> /promise/ to do its job. What does "assembling at compile time"
>> mean here:
>> 
>> s = "I will not write infinite loops " ++ s
> 
>   % cat C.hs
> 
>   module Test where
> 
>   x = "Foo" ++ "Bar"
>   y = "Zot" ++ y
> 
>   % ghc -ddump-simpl C.hs
> 
>   ==================== Tidy Core ====================
>   Test.x :: [GHC.Base.Char]
>   [GlobalId]
>   []
>   Test.x =
>     GHC.Base.++
>       @ GHC.Base.Char (GHC.Base.unpackCString# "Foo")
> (GHC.Base.unpackCString# "Bar")
> 
>   Rec {
>   Test.y :: [GHC.Base.Char]
>   [GlobalId]
>   []
>   Test.y = GHC.Base.++ @ GHC.Base.Char (GHC.Base.unpackCString# "Zot")
> Test.y
>   end Rec }
> 
> If I interpret it correctly, the compiler does approximately nothing -
> reasonably enough, since we didn't ask for optimization.  With -O:
> 
>   % ghc -ddump-simpl C.hs -O
> 
>   ==================== Tidy Core ====================
>   Rec {
>   Test.y :: [GHC.Base.Char]
>   [GlobalId]
>   [Str: DmdType]
>   Test.y = GHC.Base.unpackAppendCString# "Zot" Test.y
>   end Rec }
> 
>   Test.x :: [GHC.Base.Char]
>   [GlobalId]
>   [Str: DmdType]
>   Test.x = GHC.Base.unpackCString# "FooBar"
> 
> y gets turned into an unpackAppendCString#, which I can only presume is
> a sensible way to represent a cyclic list, while x gets concatenated
> compile-time.
> 

-- 
View this message in context: http://www.nabble.com/Hints-for-Euler-Problem-11-tf4114963.html#a12196104
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.



More information about the Haskell-Cafe mailing list