1

So far I know, we use it mostly for list/array comprehension. Here is two codes:

 [ for x in range do (yield expression)] 

else we can also drop the yield and still it works

 [ for x in range do expression] 

So, is then what is use of yield in F#?

asked Mar 5 at 9:50
2
  • Often "syntactic sugar" is useful. In this case (1) yield has wider applicability than just list and array comprehensions: including custom ones; (2) when mixing with yield! it provides more syntactic consistency (and thus easier maintainability).
    Richard
    Commented Mar 5 at 10:36
  • Note also that yield was not originally optional - you could either have -> (as opposed to do and have an implicit yield). There are also cases where it disambiguates an expression (i.e. yield implies it must match the sequence type as has been declared/inferred, whereas an expression without it might also be a unit 'statement' Commented Mar 5 at 16:37

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.