haskell - Why does `take` with a large number return [] even though the list is infinite? -


i have doubt on why haskell couldn't handle following line

prelude> take 1000000000000 $ repeat ' ' 

that line of code return:

"" 

which not 1,000,000,000,000 spaces.

if try 1 less zero, print long time.

and thing bothers me if write

prelude> repeat ' ' 

it work, being lot of more zeros.

so, why couldn't haskell print long time did repeat alone?

are on 32 bit system? suspect 1000000000000 wraps int negative number. it's equal 2^40.

you can check what's going on entering 1000000000000 :: int.

take negative number returns empty list:

prelude> take (- 1) [1,2,3] [] 

for reference, take takes int:

prelude> :t take take :: int -> [a] -> [a] 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -