
The trouble is that you probably *don't* want to expand this case x of { "foogle" -> e1; _ -> e2 } to this case x of c1:x1 -> case c1 of 'f' -> case x1 of c2:x2 -> case c2 of 'o' -> of .... So GHC generates a series of equality tests instead. A decent alternative might be: generate case expressions when there is more than one string in the list, otherwise use an equality test That would not be hard to do. If it becomes important to you, I'd have a go. But before doing so, could you do the work by hand and see if it makes a useful performance difference? Simon | -----Original Message----- | From: glasgow-haskell-users-bounces@haskell.org [mailto:glasgow-haskell-users- | bounces@haskell.org] On Behalf Of Sven Panne | Sent: 22 February 2004 15:32 | To: John Meacham | Cc: glasgow-haskell-users@haskell.org | Subject: Re: optimization question | | 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. | | _______________________________________________ | Glasgow-haskell-users mailing list | Glasgow-haskell-users@haskell.org | http://www.haskell.org/mailman/listinfo/glasgow-haskell-users