I was writing some code and I figured that I’d be able to create an infinite map from an infinite list of tuples. Something along the lines of the following:
Map.fromList [(i,i+1)|i<-[1..]]
Of course, I discovered immediately that Data.Map and Data.Set do not support infinite Maps and Sets respectively. I noticed a similar question about Data.Set’s greedy implementation of fromList, and, after reading over the answers here, it’s clear that both lazy and greedy implementations are possible for Set, just that the greedy ones work better. I don’t really understand, however, why a lazy implementation of Map.fromList wouldn’t work. Something to do with how keys are stored?
Data.Mapis implemented as a balanced tree (roughly binary, I think); it’s hard to create and balance infinite binary trees lazily without some foreknowledge about the input! However, you might like something like the MemoTrie package, which uses lazy infinite tries (of bits) instead.