
I am a haskell beginner and wondering how the following function works (in procedure) : oddsFrom3 :: [Integer] oddsFrom3 = map (+2) oddsFrom3 Thanks for your help.

Sorry, I wrote a wrong function, the correct version is: oddsFrom3 :: [Integer] oddsFrom3 = 3 : map (+2) oddsFrom3 -- A GNU [1] LINUX [2] Patron Links: ------ [1] http://gnu.org [2] http://www.linuxfoundation.org/

Not a problem. And I should have thought about what you wanted too.
This version will give you an infinite list of odd numbers from 3.
On Mon, Aug 17, 2015 at 12:02 PM, Debdut Karmakar
Sorry, I wrote a wrong function, the correct version is:
oddsFrom3 :: [Integer] oddsFrom3 = 3 : map (+2) oddsFrom3 --
A* GNU http://gnu.org Linux http://www.linuxfoundation.org/* Patron
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

Do note that if you force it so that it the value needs the last element,
it will be stuck in an infinite loop of request-> response loop.
Here's what will happen/
last [3,5 ..] -- Same thing as your function
This will be forced to
last [3,5, 7 ..]
which will be forced till it terminates (which is never). So, be careful
with that. However, things like this are perfectly fine.
head [3,5 ..] yields 3
takeWhile (<10) [3,5 ..] yields [3,5,7,9]
On Mon, Aug 17, 2015 at 12:05 PM, akash g
Not a problem. And I should have thought about what you wanted too.
This version will give you an infinite list of odd numbers from 3.
On Mon, Aug 17, 2015 at 12:02 PM, Debdut Karmakar
wrote: Sorry, I wrote a wrong function, the correct version is:
oddsFrom3 :: [Integer] oddsFrom3 = 3 : map (+2) oddsFrom3 --
A* GNU http://gnu.org Linux http://www.linuxfoundation.org/* Patron
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

On 2015-08-17 02:35, akash g wrote:
Not a problem. And I should have thought about what you wanted too.
This version will give you an infinite list of odd numbers from 3.
On Mon, Aug 17, 2015 at 12:02 PM, Debdut Karmakar
wrote: Sorry, I wrote a wrong function, the correct version is:
oddsFrom3 :: [Integer] oddsFrom3 = 3 : map (+2) oddsFrom3 --
A GNU [1] LINUX [2] Patron _______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners [3]
Beginners mailing
_______________________________________________ list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners [3] I know that it will evaluate to a list of odd numbers >= 3, but how? Thanks, anyway. -- A GNU [1] LINUX [2] Patron Links: ------ [1] http://gnu.org [2] http://www.linuxfoundation.org/ [3] http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

It will absolutely work. Lists can be infinite in Haskell and infinite
lists are productive:
λ> take 5 oddsFrom3
[3,5,7,9,11]
On Mon, Aug 17, 2015 at 12:05 AM Debdut Karmakar
On 2015-08-17 02:35, akash g wrote:
Not a problem. And I should have thought about what you wanted too.
This version will give you an infinite list of odd numbers from 3.
On Mon, Aug 17, 2015 at 12:02 PM, Debdut Karmakar
wrote: Sorry, I wrote a wrong function, the correct version is:
oddsFrom3 :: [Integer] oddsFrom3 = 3 : map (+2) oddsFrom3 --
A* GNU http://gnu.org Linux http://www.linuxfoundation.org/* Patron
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing listBeginners@haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
I know that it will evaluate to a list of odd numbers >= 3, but how?
Thanks, anyway. --
A* GNU http://gnu.org Linux http://www.linuxfoundation.org/* Patron _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

Hi Rein,
The initial version which the OP posted doesn't have a terminal value.
The OP had posted the version that he'd wanted clarification on.
On Mon, Aug 17, 2015 at 12:40 PM, Rein Henrichs
It will absolutely work. Lists can be infinite in Haskell and infinite lists are productive:
λ> take 5 oddsFrom3 [3,5,7,9,11]
On Mon, Aug 17, 2015 at 12:05 AM Debdut Karmakar
wrote: On 2015-08-17 02:35, akash g wrote:
Not a problem. And I should have thought about what you wanted too.
This version will give you an infinite list of odd numbers from 3.
On Mon, Aug 17, 2015 at 12:02 PM, Debdut Karmakar
wrote: Sorry, I wrote a wrong function, the correct version is:
oddsFrom3 :: [Integer] oddsFrom3 = 3 : map (+2) oddsFrom3 --
A* GNU http://gnu.org Linux http://www.linuxfoundation.org/* Patron
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing listBeginners@haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
I know that it will evaluate to a list of odd numbers >= 3, but how?
Thanks, anyway. --
A* GNU http://gnu.org Linux http://www.linuxfoundation.org/* Patron _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

You can also peruse SICP for knowing about how lazy evaluation works. The
explanations are nice. It is in lisp, though.
https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-24.html#%_sec_3.5
On Mon, Aug 17, 2015 at 2:12 PM, akash g
Hi Rein,
The initial version which the OP posted doesn't have a terminal value. The OP had posted the version that he'd wanted clarification on.
On Mon, Aug 17, 2015 at 12:40 PM, Rein Henrichs
wrote: It will absolutely work. Lists can be infinite in Haskell and infinite lists are productive:
λ> take 5 oddsFrom3 [3,5,7,9,11]
On Mon, Aug 17, 2015 at 12:05 AM Debdut Karmakar
wrote: On 2015-08-17 02:35, akash g wrote:
Not a problem. And I should have thought about what you wanted too.
This version will give you an infinite list of odd numbers from 3.
On Mon, Aug 17, 2015 at 12:02 PM, Debdut Karmakar
wrote:
Sorry, I wrote a wrong function, the correct version is:
oddsFrom3 :: [Integer] oddsFrom3 = 3 : map (+2) oddsFrom3 --
A* GNU http://gnu.org Linux http://www.linuxfoundation.org/* Patron
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing listBeginners@haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
I know that it will evaluate to a list of odd numbers >= 3, but how?
Thanks, anyway. --
A* GNU http://gnu.org Linux http://www.linuxfoundation.org/* Patron _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

On Mon, Aug 17, 2015 at 1:32 PM, Debdut Karmakar
Sorry, I wrote a wrong function, the correct version is:
oddsFrom3 :: [Integer] oddsFrom3 = 3 : map (+2) oddsFrom3
You can get some idea of lambda evaluation here: http://chrisuehlinger.com/LambdaBubblePop/ (Alas it doesn't support let expressions much less let rec.) Once you have a modicum of intuition, you're now ready to appreciate the illustrated step-by-step evaluation of this infinite list: http://stackoverflow.com/a/19749422 Based on the SO answer, you can now work out your function on your own. -- Kim-Ee

On 2015-08-17 03:21, Kim-Ee Yeoh wrote:
On Mon, Aug 17, 2015 at 1:32 PM, Debdut Karmakar
wrote: Sorry, I wrote a wrong function, the correct version is:
oddsFrom3 :: [Integer] oddsFrom3 = 3 : map (+2) oddsFrom3
You can get some idea of lambda evaluation here:
http://chrisuehlinger.com/LambdaBubblePop/ [2]
(Alas it doesn't
support let expressions much less let rec.)
Once you have a modicum
of intuition, you're now ready to appreciate the illustrated step-by-step evaluation of this infinite list:
http://stackoverflow.com/a/19749422 [3]
Based on the SO answer, you
can now work out your function on your own.
-- Kim-Ee
Beginners mailing
_______________________________________________ list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners [1] Thanks, this is what I wanted. Thanks and the problem has been resolved. -- A GNU [4] LINUX [5] Patron Links: ------ [1] http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners [2] http://chrisuehlinger.com/LambdaBubblePop/ [3] http://stackoverflow.com/a/19749422 [4] http://gnu.org [5] http://www.linuxfoundation.org/

Well, it won't work. Oh, it will compile and you can run it too (stuck in
a infinte loop if you try to force it in any way). Compilation happens
because this satisfies the type solver. However, the compiler cannot
ensure non-termination of said program. Just unrolling it should show you
what's wrong with it.
Unroll once:
oddsForm3 = map (+2) (map (+2) oddsForm3)
Unroll again:
oddsForm3 = map (+2) (map (+2) (map (+2) oddsForm3)
And you can keep on going. It will never evaluate to a terminal value.
On Mon, Aug 17, 2015 at 11:55 AM, Debdut Karmakar
I am a haskell beginner and wondering how the following function works (in procedure) :
oddsFrom3 :: [Integer] oddsFrom3 = map (+2) oddsFrom3
Thanks for your help.
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
participants (4)
-
akash g
-
Debdut Karmakar
-
Kim-Ee Yeoh
-
Rein Henrichs