From my understanding, as Haskell uses lazy evaluation, which allows operations on for example infinite lists to be evaluated in a finite amount of time.
As a test, I defined the following function
X Boolean
Y Int
f(X,Y) = (Y == 3) OR X
Hence, fold left applied to the infinite list of integers [1..]
with False
as initial value and the function defined above, should return True
, because when it will reach n=3
evaluating f(n==3,False)
will return True
, and hence this True
will propagate through the function.
I implemented this function in Haskell code
myfunc :: Bool -> Int -> Bool
myfunc True _ = True
myfunc _ n
| (n == 3) = True
| otherwise = False
and tried it out in the cli
foldl myfunc False [1..]
The command becomes unresponsive, suggesting it is doing an infinite computation. Why is Haskell not benefiting from the lazy evaluation here?