[Haskell-beginners] fractal x = fractal [y - head x + z | y <- x, z <- x] with take doesnt end

Sumit Sahrawat, Maths & Computing, IIT (BHU) sumit.sahrawat.apm13 at iitbhu.ac.in
Wed Mar 4 03:56:08 UTC 2015


Both the versions work for me. The one with two calls to fractal takes
~0.03 seconds, whereas the one with only one call takes ~0.01 seconds.
All timings produced using (:set +s) in ghci.

Also, that totally recursive definition is infinitely recursive.

If you provide some more context, it will be easier to answer your
question. Till now I don't exactly understand what the issue is.

On 4 March 2015 at 08:52, '2+ <electriclightheads at gmail.com> wrote:

> hi!
> since my
>
> fractal :: [Int] -> [Int]
> fractal x = [y - head x + z | y <- x, z <- x]
>
> seems to be working fine with something like:
>
> take 300 $ cycle $ fractal $ fractal $ [11..17] ++ [55..77]
>
> wanted to twist the function to something totally recursive
> but:
>
> fractal x = fractal [y - head x + z | y <- x, z <- x]
>
> experimented with:
>
> take 300 $ fractal $ [11..17] ++ [55..77]
>
> doesnt end its process and eat up the RAM
>
> any hints to solve this issue?
>
> thank you
>
> ----- 2g ---
> http://sarigama.namaste.jp
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>



-- 
Regards

Sumit Sahrawat
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150304/7bda18d5/attachment-0001.html>


More information about the Beginners mailing list