optimization question

Sven Panne Sven.Panne at aedion.de
Sun Feb 22 16:31:46 EST 2004


John Meacham wrote:
> I was wondering if:
> 
> case x of 
>         "foo" -> Foo
>         "bar" -> Bar
>         "fuzz" -> Fuzz
>         "fuzo" -> Fuzo
>         x -> other .. thing
> 
> would optimize to
> 
> let z = other .. thing in
> case x of 
>         ('f':x) -> case x of
>                 ('u':'z': x) -> 
>                         "z" -> Fuzz
>                         "o" -> Fuzo
>                         _ -> z
>                 "oo" -> Foo
>                 _ -> z
>         "bar" -> Bar
>         _ -> z

String literals are handled in a special way in GHC, so your example is
essentially converted into an if-cascade, which is not what you want.
OTOH, if you write the strings in their expanded form like ['f','o','o'],
you get your optimized version automatically. Perhaps Simon^2 can comment
on the rationale behind this, I can't remember the reason...

Cheers,
    S.



More information about the Glasgow-haskell-users mailing list