[Haskell-beginners] program not running lazily

Mason Lai masonmlai at gmail.com
Thu Jan 21 19:34:35 UTC 2016


I've changed the "if minimum < 3" line with an "any (< 3)" line. This has
sped up the performance to be good enough. (I assume that I have to
calculate the Lev. distance of all the 9-mers in order to take the minimum.
I really only care if any element has a Lev. distance less than three, so I
can stop when I find the first.) The rest of this discussion is purely for
fun.

I've swapped "y:ys" for "ys ++ [y]", and while the output is reversed, I
don't appear to be able to take the first n elements still. I haven't timed
how long the program takes now to see if it blows up. Rein, I don't quite
understand your answer; I may need you to be more explicit if I don't
figure this out. Part of what confuses me is that the recursion takes place
in merge, and the (:) is in addInto. I think your comment has given me an
idea, so I'm going to take some time to play with this in the afternoon, so
I'll send an update tonight.

Thanks for looking at this!
-- Mason

On Thu, Jan 21, 2016 at 11:05 AM, Rein Henrichs <rein.henrichs at gmail.com>
wrote:

> s/not/note, sorry
>
> On Thu, Jan 21, 2016 at 10:42 AM Rein Henrichs <rein.henrichs at gmail.com>
> wrote:
>
>> But not that doing so will cause the program to have an exponential
>> runtime as each new ys must be repeatedly traversed to append a [y].. The
>> alternative is to *unfold* your list by recursing on the right hand side of
>> the (:) to add new elements.
>>
>> On Thu, Jan 21, 2016 at 5:43 AM Doug McIlroy <doug at cs.dartmouth.edu>
>> wrote:
>>
>>> Each time you find another good 9-mer, you add it to
>>> the head of the list. This means that the ultimate
>>> list will be in reverse order of discovery: the first element
>>> to be printed is the last one to be found.  To get
>>> output in the order it was discovered, build the
>>> output by ys++[y] rather than y:ys.
>>> _______________________________________________
>>> Beginners mailing list
>>> Beginners at haskell.org
>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160121/15fe120e/attachment.html>


More information about the Beginners mailing list