I am trying to learn F# computation expressions. In general, what is the purpose of the Zero member?
What is its definition for sequences?
What is its definition for async workflows?
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.
The
Zeromember is used, for example, when you omit theelsebranch in anifexpression:… would be translated to something like this:
How is it defined for standard computation types?
For asynchronous workflows, it is defined as asynchronous workflow that immediately returns a unit value – essentially equivalent to writing:
async { return () }.For sequences (where you use
yieldinstead ofreturn) theZeromember returns a sequence that does not return anything, corresponding to the standardSeq.emptyvalue.If you want to read about some more theoretical background, then you can check out this paper. In a more theoretical terms, it says that
Zerois either going to bereturn ()(when the computation is a monad) or it is going to be the unit of a monoid (when the computation is monoidal) which is something that Haskellers callmzero.