<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body><div><div style="font-family: Calibri,sans-serif; font-size: 11pt;">Apologies for the empty post.<br>You might turn your attention to the following web page, which approaches the problem using recursive co-routines. Amidst a discussion of UNIX pipes, both in history and as a primitive co-routine implementation, there is a two-line Haskell program.<br><br>http://www.cs.dartmouth.edu/~doug/sieve/<br><br></div></div><div dir="ltr"><hr><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">From: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;"><a href="mailto:beginners-request@haskell.org">beginners-request@haskell.org</a></span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Sent: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;">‎5/‎5/‎2016 11:10 AM</span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">To: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;"><a href="mailto:beginners@haskell.org">beginners@haskell.org</a></span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Subject: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;">Beginners Digest, Vol 95, Issue 8</span><br><br></div>Send Beginners mailing list submissions to<br>  beginners@haskell.org<br><br>To subscribe or unsubscribe via the World Wide Web, visit<br>    http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners<br>or, via email, send a message with subject or body 'help' to<br>      beginners-request@haskell.org<br><br>You can reach the person managing the list at<br>        beginners-owner@haskell.org<br><br>When replying, please edit your Subject line so it is more specific<br>than "Re: Contents of Beginners digest..."<br><br><br>Today's Topics:<br><br>   1. Re:  Timed Profiling (Vale Cofer-Shabica)<br>   2. Re:  Infinite recursion in list comprehension (Silent Leaf)<br>   3. Re:  Infinite recursion in list comprehension (Silent Leaf)<br><br><br>----------------------------------------------------------------------<br><br>Message: 1<br>Date: Thu, 5 May 2016 10:38:50 -0400<br>From: Vale Cofer-Shabica <vale.cofershabica@gmail.com><br>To: The Haskell-Beginners Mailing List - Discussion of primarily<br>   beginner-level topics related to Haskell <beginners@haskell.org><br>Subject: Re: [Haskell-beginners] Timed Profiling<br>Message-ID:<br> <CAAzfV4Rse76Yw8Vq_Mqny_cFRw_9_FFcXBAAm4W+54zXWTuveQ@mail.gmail.com><br>Content-Type: text/plain; charset="utf-8"<br><br>timeout(1) allows you to specify the signal(7) sent with the --signal<br>option. It may be worth experimenting with different values. One of them<br>might terminate the program while allowing it to clean up and generate<br>profiling information. I don't know enough about the haskell runtime to<br>know.<br><br>-vale<br><br>--<br>vale cofer-shabica<br>401.267.8253<br><br>On Wed, May 4, 2016 at 7:06 PM, Tim Perry <tim.v2.0@gmail.com> wrote:<br><br>> I believe that timeout sends a kill signal to the process in question. I<br>> imagine that the process is killed before the profiling information is<br>> written and so you get an empty file. When you close the program with<br>> alt-F4, the program gets a chance to shut down cleanly and writes on the<br>> profiling information (.prof)<br>><br>><br>> On Wed, May 4, 2016 at 9:11 AM, Ben Rogalski <bwrogalski@gmail.com> wrote:<br>><br>>> I would like to generate a time and allocation profiling report after<br>>> running my program for exactly 60 seconds (on Ubuntu Linux).<br>>><br>>> I compiled with the following flags:<br>>><br>>> -rtsopts -auto-all -caf-all -fforce-recomp<br>>><br>>> I then ran the program:<br>>><br>>> The program stops after 60 seconds, but the .prof file is empty.<br>>><br>>> When I run the program without using timeout, and close it manually (Alt<br>>> F4, it is a graphical program), the .prof file contains the information I<br>>> would expect.<br>>><br>>> _______________________________________________<br>>> Beginners mailing list<br>>> Beginners@haskell.org<br>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners<br>>><br>>><br>><br>> _______________________________________________<br>> Beginners mailing list<br>> Beginners@haskell.org<br>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners<br>><br>><br>-------------- next part --------------<br>An HTML attachment was scrubbed...<br>URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160505/b8bbb307/attachment-0001.html><br><br>------------------------------<br><br>Message: 2<br>Date: Thu, 5 May 2016 19:57:52 +0200<br>From: Silent Leaf <silent.leaf0@gmail.com><br>To: The Haskell-Beginners Mailing List - Discussion of primarily<br> beginner-level topics related to Haskell <beginners@haskell.org><br>Subject: Re: [Haskell-beginners] Infinite recursion in list<br>   comprehension<br>Message-ID:<br>    <CAGFccjMN86K9ibBPi_q+Jx07tU4Jc0zbF9Kggy12zY1CA2=pfg@mail.gmail.com><br>Content-Type: text/plain; charset="utf-8"<br><br>I succeeded to get it working with n = 2,000,000 at least, through this<br>means:<br><br>primesBelow :: Int -> [Int]<br>primesBelow max = list<br>  where list = 2:3:rest<br>        rest = [ v | k <- [1..(max-1)`div`6], i <- [-1, 1]<br>                       , let v = 6*k+i, checker v]<br>        ...<br>        ...<br><br>the function "checker" (in the list comprehension, as conditional) is using<br>itself in its definition the variable "list" to generate the test for each<br>"v" of the list comprehension "rest". I dunno if this kind of recursion<br>suits you.<br>-------------- next part --------------<br>An HTML attachment was scrubbed...<br>URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160505/314e2cca/attachment-0001.html><br><br>------------------------------<br><br>Message: 3<br>Date: Thu, 5 May 2016 20:10:29 +0200<br>From: Silent Leaf <silent.leaf0@gmail.com><br>To: The Haskell-Beginners Mailing List - Discussion of primarily<br> beginner-level topics related to Haskell <beginners@haskell.org><br>Subject: Re: [Haskell-beginners] Infinite recursion in list<br>   comprehension<br>Message-ID:<br>    <CAGFccjPCcn0q+ZvrE+BNN7iaCw-b4HJURfPDceVELcJKT3KdoQ@mail.gmail.com><br>Content-Type: text/plain; charset="utf-8"<br><br>Implicitly, primesBelow shouldn't ever in fact call itself, not as it is<br>articulated here **at the very least**, not without wasting a lot of<br>calculus.<br><br>As it is, and maybe no matter what (i'm not sure, don't have the knowledge<br>to certify that), when primesBelow checks if a value "v" is prime or not,<br>well no matter what it'll already have calculated and stored all primes<br>below this value n (this, according to how primesBelow is articulated, aka<br>filtering of Naturals bottom-top).<br><br>Thus, if for each potential element "v" of the result (in my version,<br>"list") of primesBelow, you call once again primesBelow, asking it to<br>generate again all primes below sqrt(v), you'll do nothing more than doing<br>again what you already did, because all those previous primes have already<br>been generated, stored away, and especially very accessible, in the<br>list-result in-construction of the **current** call to primesBelow, so if<br>you don't use it but call again primesBelow to get a copy of what you<br>already have, you'll multiply immensely the work without any gain.<br>That's why I named the very result of primesBelow, to get a way to use<br>"list" (the previously generated items of the future result-list) in<br>"checker".<br><br>2016-05-05 15:44 GMT+02:00 Dushyant Juneja <juneja.dushyant@gmail.com>:<br><br>> Hi Akash,<br>><br>> Thanks for the response. A very simple and lucid explanation. Looks<br>> interesting.<br>><br>> So, here's the big picture now, for which I need this. I intend to<br>> implement a lookalike Sieve of Eratosthenes algorithm in haskell. For this,<br>> I intend to use the earlier function recursively, as follows:<br>><br>> primesBelowN :: Integer -> [Integer]<br>> primesBelowN n = 2:3:filter f [6*k+i | k <- [1..(n-1)`div`6], i <- [-1, 1]]<br>>                      where f x = foldr g True xs<br>>                                  where g t ac = (x `rem` t /= 0) && ac<br>>                                        xs = [ m | m <- primesBelowN n, m<br>> <= (truncate (sqrt (fromInteger x)))]<br>><br>> Of course, I could do something like this:<br>><br>> primesBelowN :: Integer -> [Integer]<br>> primesBelowN n = 2:3:filter f [6*k+i | k <- [1..(n-1)`div`6], i <- [-1, 1]]<br>>                      where f x = foldr g True xs<br>>                                  where g t ac = (x `rem` t /= 0) && ac<br>>                                        xs = [ m | m <- primesBelowN (truncate<br>> (sqrt (fromInteger x)))]<br>><br>> However, this calls primesBelowN function with a new argument everytime. I<br>> suppose that is not optimal (correct me if I am wrong).<br>><br>> Point number 2: both fail. Grrh.<br>><br>> Any ideas how I could go recursive with this function?<br>><br>> Dushyant<br>><br>><br>> On Thu, May 5, 2016 at 6:31 PM akash g <akaberto@gmail.com> wrote:<br>><br>>> Hi Dushyant,<br>>><br>>> The problem most likely is<br>>> [m | m <- [5,7..], m <= (truncate (sqrt (fromInteger x)))]<br>>><br>>>  This is because, the filter condition (the last part) does a very simple<br>>> thing:  It filters out any element that does not fulfil the criteria.  You<br>>> are operating on a list that is monotonically increasing.  However, the<br>>> filter isn't aware of this property.  Hence, this list comprehension never<br>>> ends because it doesn't know that once the condition fails, it will always<br>>> fail.<br>>><br>>> Thus, the solution would be to generate a finite set (or take a part of<br>>> the infinite set using takeWhile or something like that), instead of using<br>>> an infinite one.<br>>><br>>> Regards,<br>>> G Akash.<br>>><br>>> On Thu, May 5, 2016 at 6:13 PM, Dushyant Juneja <<br>>> juneja.dushyant@gmail.com> wrote:<br>>><br>>>> Hi,<br>>>><br>>>> I seem to be landing into infinite recursion when using higher order<br>>>> functions with list comprehension. Take this for an example. The following<br>>>> works well, and gives answers for numbers like 2000000 as well:<br>>>><br>>>> primesBelowN :: Integer -> [Integer]<br>>>> primesBelowN n = 2:3:filter f [6*k+i | k <- [1..(n-1)`div`6], i <- [-1,<br>>>> 1]]<br>>>>                      where f x = foldr g True xs<br>>>>                                  where g t ac = (x `rem` t /= 0) && ac<br>>>>                                        xs = [5, 7..(truncate (sqrt<br>>>> (fromInteger x)))]<br>>>><br>>>><br>>>> However, the following never returns anything for the same number,<br>>>> probably due to some kind of loop malfunction:<br>>>><br>>>> primesBelowN :: Integer -> [Integer]<br>>>> primesBelowN n = 2:3:filter f [6*k+i | k <- [1..(n-1)`div`6], i <- [-1,<br>>>> 1]]<br>>>>                      where f x = foldr g True xs<br>>>>                                  where g t ac = (x `rem` t /= 0) && ac<br>>>>                                        xs = [ m | m <- [5, 7, ..], m <= (truncate<br>>>> (sqrt (fromInteger x)))]<br>>>><br>>>> Any ideas what might be going wrong?<br>>>><br>>>> Thanks in advance!<br>>>><br>>>> DJ<br>>>><br>>>> _______________________________________________<br>>>> Beginners mailing list<br>>>> Beginners@haskell.org<br>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners<br>>>><br>>>><br>>> _______________________________________________<br>>> Beginners mailing list<br>>> Beginners@haskell.org<br>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners<br>>><br>><br>> _______________________________________________<br>> Beginners mailing list<br>> Beginners@haskell.org<br>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners<br>><br>><br>-------------- next part --------------<br>An HTML attachment was scrubbed...<br>URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160505/d46458fe/attachment.html><br><br>------------------------------<br><br>Subject: Digest Footer<br><br>_______________________________________________<br>Beginners mailing list<br>Beginners@haskell.org<br>http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners<br><br><br>------------------------------<br><br>End of Beginners Digest, Vol 95, Issue 8<br>****************************************<br></body></html>