haskell - Data.List.iterate lazy evaluation not happening -


i'm having above function, when call it, gets stuck, data.list.iterate evaluates without stopping.

rp:: randomgen g => g -> ([int], g) rp g = (map (\x -> (last (fst x))) lst , snd (next g))              lst = (data.list.iterate id ([1], g_second))         (g_first, g_second) = (split g) 

why happend?

thank you!

while i'm not sure you're trying achieve function, reason doesn't stop because you're mapping on infinite list , giving no reason to stop.

the infinite list originates in use of iterate:

lst = (data.list.iterate id ([1], g_second))

what you've done there create infinite list contains infinite number of tuple value ([1], g_second). seems logic error - list of tuple has no variation; every element same, infinity. clear, list building looks this:

[([1], g_second), ([1], g_second), ([1], g_second), ([1], g_second)...] 

g_second unchanging , never gets reason evaluate, is, in essence, discarded.

if use take or takewhile, force infinite list stop , return known number of elements. however, using map in statement:

map (\x -> (last (fst x))) lst 

all doing pulling value 1 out of tuple , repeating forever.

and since discard g_second , never use g_first, function equivalent following:

rp :: randomgen g => g -> ([int], g) rp g = (repeat 1 , snd (next g)) 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -