KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have some Haskell code that does work correctly on an infinite list, but I do not understand why it can do so successfully. (I modified my original code -- that did not handle infinite lists -- to incorporate something from some other code online, and suddenly I see that it works but don't know why). myAny :: (a -> Bool) -> [a] -> Bool myAny p list = foldr step False list where step item acc = p item || acc My understanding of foldr is that it will loop through every item in the list (and perhaps that understanding is incomplete). If so, it should not matter how the "step" function is phrased ... the code should be unable to handle infinite loops. However, the following works: *Main Data.List> myAny even [1..] True Please help me understand: why??
Tags (comma-separated)
Save Edits
Cancel