--===============1183333966== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="dkEUBIird37B8yKS" Content-Disposition: inline --dkEUBIird37B8yKS Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Mar 22, 2010 at 03:06:08AM +0200, Sami Liedes wrote: > On Sun, Mar 21, 2010 at 08:28:23PM -0400, Patrick LeBoutillier wrote: > > - Also, does memory usage improve if you remove the "sort"? >=20 > Yes. Then it only takes a few megabytes, regardless of how large the > file is. This led me to investigate further. The following hack (and nothing less crude I could invent) seems to significantly lessen the amount of memory needed by the program. Now it takes maybe 180 megabytes instead of 1.5 gigabytes. I guess the 180 megabytes consists of the output stream (string), which is now explicitly computed entirely before sorting and outputting it. It's still far from perfect. I think there definitely _should_ be a better way of doing this (forcing some computation to be strict so it takes less memory). Any ideas? And I especially despise the (sum (map (const 0) b)) thing, but it seems nothing less ugly does the trick. It seems seq doesn't force the entire computation to finish, only the next level. Is there some way to force the entire computation subtree to finish? That way I could say just seq' b (if seq' was the function that does that). (see my original posting for the entire code) ------------------------------------------------------------ -- Return the unsorted package list and the sorted package list processFile :: String -> (String,String) processFile str =3D let l =3D lines str pkgs =3D readRecords l in (unlines (map sprintPackage pkgs), unlines (map sprintPackage (sort pkgs))) -- Force the unsorted pkg list to be computed first (outputting it also -- does the trick, but mere (map id b) doesn't). This is really ugly. -- A mere "do putStrLn c" however eats 1.5 GB of memory instead of 180 MB. main =3D do a <- getContents let (b,c) =3D processFile a in seq (sum (map (const 0) b)) ( do putStrLn c) ------------------------------------------------------------ Sami --dkEUBIird37B8yKS Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iQIcBAEBCAAGBQJLp8vlAAoJEKLT589SE0a0R4UP+QEkm9HmZbRaKXLTo8nBQ4I8 KKWalotSTbaLOmSQ+/AaB6fIqc7P1wi6vPoTrOpa6aSXsYJYV9bIj3RXSp9u/R7L uxCmyzTKbbHMO3XiTT8XsReBlsYdKBsPorKM9eBUroGsVIB/7HByUDW2idbKUNwU gMPb72JQ48pfKRxeitlXiuXWxvq6l5wB4CvReIqZtjnFgjyhb0QZuRgIExVcfA5k +NNdSFkUK5aRV+PyZcXTkDjU6D9U8Xj03LTCTClTFmRtlBHTMbBPCsNyZv9E5PJU BYdkrCTJBFjFUmKuwPQqu33ch5G5HNHwnwwd6SKy4R1EfJtcQFSNeoBsyobAECyq Ny9XDji3IQE6mzOyzCQsS98dj7Mc5PH9pm5rSO9usCbrFCfGHQaUGPgZD6NWY2k6 22Tq9nI9DM/ERdTB/YaOLWr5HQ2p8MI6eHFaZXrfA7tI/kHKm2+pZJRQDp3E7GDt tZV9cPd0vnG2p3/X6Y227TemEAN1iCM/iGWLkVTXQSMZvDbVboFs9m+HRp4Kf8r2 zzytVG2cIhlqZavfJpNf8Kncjpr7YRtoz2d3YoA3rOTu+BAL2V0/fN3RPRA9iGk8 cAc3n59lOgx499mm0nvuf1uMF0U9MAgqb6D8AbbZvVFPpGbbsYGcnPpc+2HFTzN+ 2BEwyh2Cagi4D6KayQ5S =Geh5 -----END PGP SIGNATURE----- --dkEUBIird37B8yKS-- --===============1183333966== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners --===============1183333966==--