I have been using haskell for a long time, and I read most of Real World Haskell and recognized you in Haskell. I want to know if it makes sense to use a language with lazy evaluation, in particular the “advantage” of having infinite lists, is there a task that infinite lists make very easy, or even a task that is possible only with infinite lists?
Here's a completely trivial but actually everyday useful example of where endless lists are especially useful: when you have a list of elements that you want to use to initialize a data structure such as a key value, starting with sequential keys. So, let's say you have a list of strings, and you want to put them in a number IntMapfrom 0. Without lazy endless lists, you would do something like go through the input list, keeping the “next index” counter and creating IntMapwhen you go.
IntMap
With endless lazy lists, the list itself acts as a counter; just use zip [0..]with a list of elements to assign indices, then IntMap.fromListto build the final result.
zip [0..]
IntMap.fromList
, . , , .
, . , , , , AST, . Unix-.
, , , , , , .
take 10 mySequence takeWhile (<100) mySequence
, , ,
first10ofMySequence elementsUnder100ofMySequence
, .
, , . , , , .
: u_n , . , | u_n - u_ {n-1} | < epsilon, .
: u_n v_n, . :
, u_n v_n. , . f (u_n), (.. , ) f .
( ) , , , . , //, .
, , .
/ " ": http://www.haskell.org/haskellwiki/Tying_the_Knot
, . (, , / - - .): fibs = 1:1:zipwith (+) fibs (tail fibs)
fibs = 1:1:zipwith (+) fibs (tail fibs)
. , - , , , , , .. , , , , , , . , , . , - .. , , . , , , , / .
- . :
http://users.info.unicaen.fr/~karczma/arpap/cleasyn.pdf
Haskell - WAV IO. GHCi Athalon 1,5 , , .
- cycle. cycle [False, True] [False, True, False, True, False ...]. , xs ! 0 = False, xs ! 1 = True, , . ? , , -: , .
cycle
cycle [False, True]
[False, True, False, True, False ...]
xs ! 0 = False
xs ! 1 = True
, , , , , , " , ", , . camcanns .
Source: https://habr.com/ru/post/1781245/More articles:Erasing a container element using iterators - c ++Пользовательская проверка jQuery: номер телефона, начинающийся с 6 - jqueryUnicode library for creating / processing Json documents (C ++) - c ++Connection in .Net - c #Brackets in a Doctrine request - phpObjectDataSource could not find a non-generic method - c #Convert delegation method? - .netShould CodeContracts replace regular ArgumentExceptions? - .netПочему MySQL (по-прежнему) не воспринимается всерьез как СУБД многими разработчиками? - databaseGetting the most significant functions received from SIFT / SURF - optimizationAll Articles