Annotation for unfolding wanted

Georg Martius georg.martius at
Mon Jul 30 10:09:21 EDT 2007

Hi folks, sorry for multiple copies of this email, but my mailserver had a 
problem and thought I am sending spam which is hopefully not true. 
Since I got a replay allready I modified my mail a bit.

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 even with {#- INLINE search0 -#} (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)

---- Georg Martius,  Tel: +49 177 6413311  -----
------- ----------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url :

More information about the Glasgow-haskell-users mailing list