[From nobody Sat Jul 28 14:37:41 2007
Return-Path: &lt;mai99dgf@studserv.uni-leipzig.de&gt;
Received: from antrieb.raumzeit.net (p57ACAA3B.dip0.t-ipconnect.de
	[87.172.170.59])
	by h7568.serverkompetenz.net (Postfix) with ESMTP id 0C75839C4C5
	for &lt;glasgow-haskell-users@haskell.org&gt;;
	Sat, 28 Jul 2007 20:45:02 +0200 (CEST)
From: Georg Martius &lt;mai99dgf@studserv.uni-leipzig.de&gt;
To: glasgow-haskell-users@haskell.org
Subject: Annotation for unfolding wanted
Date: Sat, 28 Jul 2007 20:50:36 +0200
User-Agent: KMail/1.9.5
MIME-Version: 1.0
Content-Type: multipart/signed; boundary=&quot;nextPart1379835.VAeEdfuycP&quot;;
	protocol=&quot;application/pgp-signature&quot;; micalg=pgp-sha1
Content-Transfer-Encoding: 7bit
Message-Id: &lt;200707282050.37246.mai99dgf@studserv.uni-leipzig.de&gt;

--nextPart1379835.VAeEdfuycP
Content-Type: text/plain;
  charset=&quot;iso-8859-1&quot;
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Hi,

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

search0 :: Int -&gt; String -&gt; String -&gt; (String, Int)
search0 i [] _ =3D ([],i)
search0 i haystack needle =3D=20
    let len =3D 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 -&gt; String -&gt; String -&gt; (String, Int)
search1 i [] _ =3D ([],i)
search1 i haystack needle =3D=20
    let i =3D elemIndex True $ map (isPrefixOf needle) $ tails haystack
        len =3D length needle
    in case i of
         Just  index -&gt; (drop (index+len) haystack, index + len)
         Nothing     -&gt; ([],0)

Regards!
        Georg

--nextPart1379835.VAeEdfuycP
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQBGq4/97Y/IAAz6KBMRAtdMAJ0Rcsk26RUOWPYzEFYWK1HRQP8AxQCfacoZ
kmlJCAtPAuwUiHampBR93lo=
=IiHF
-----END PGP SIGNATURE-----

--nextPart1379835.VAeEdfuycP--
]