As I understand it, the range-v3 library's view operations (requires C++17 currently, but to become an official part of the STL in C++20) provides chainable STL-like algorithms that are lazily evaluated. As an experiment, I created the following code to evaluate the first 4 perfect numbers:
When I call safeHead with the argument (4:5:3::) the pattern only evaluates the argument to see if either it is empty or if it has a head. So despite the nonsensical bit ":" it should not throw an error since this part is not even evaluated.
How can this function return true?The first fold looks like this:, which should return an errorSo im guessing haskell gives priority to the lazyness of the OR function over doing the folds step by step. Finds a True on the way and returns that before starting the fold