Subject: Annotation for unfolding wanted
From: Georg Martius <[email-masked]>
To: [email-masked]
Date: Sat, 28 Jul 2007 20:50:36 +0200

Hi,

I was wondering why we don't have an annotation or pragma for function to tell 
the compiler that we need this particular recursive function to be unfolded. 
If the compiler cannot do this for some reason it should produce an error 
message to help you modifying your code. I have regularly problems that my 
code is either not strict enough or my functions are not unfolded. I find it 
annoying that this is a regular show stopper and consumes much time to fix. 
Here is an example: a search function for strings, which should return the 
index and the rest of the string after the first occurrence: search0 will not 
be unfolded by ghc -O. (I don't know why, it looks tail-recursive to me)
whereas search1 is just fine. 

search0 :: Int -> String -> String -> (String, Int)
search0 i [] _ = ([],i)
search0 i haystack needle = 
    let len = length needle
    in if isPrefixOf needle haystack then (drop len haystack, i+len)
       else search0 (seq i (i+1)) (drop 1 haystack) needle

search1 :: Int -> String -> String -> (String, Int)
search1 i [] _ = ([],i)
search1 i haystack needle = 
    let i = elemIndex True $ map (isPrefixOf needle) $ tails haystack
        len = length needle
    in case i of
         Just  index -> (drop (index+len) haystack, index + len)
         Nothing     -> ([],0)

Regards!
        Georg