Can someone please explain or give some resources on how function composition works in relation to laziness?
For example how does filter (/='W') . map toUpper $ "justaword" work in Haskell compared to it’s counterpart in erlang which is not lazy?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Every time another character is demanded (or notification of end), the next character – if any – is mapped to uppercase, that is compared to ‘W’, delivered if unequal.
Now the first character is available, so for queries like
nullor functions liketake 1, no further work is done. If more characters are demanded by the consumer, they will be produced one by one until the end of the string is reached.Example:
repeatproduces an infinite list, but as long as only a finite part is consumed, the computation finishes in finite time. However,take 10 . filter (/= 'W') . map toUpper $ repeat 'w'would not terminate, since none of the produced characters passes thefilterto reach thetake 10.