Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC FS-1069] Implicit yields (allow dropping yield in list, array, sequence and computation expressions) #6304

Closed
wants to merge 36 commits into from

Conversation

dsyme
Copy link
Contributor

@dsyme dsyme commented Mar 2, 2019

This is the implemntation for RFC FS-1069 Implict yields, i.e. the "implicit yields" language suggestion. This allows implicit yield in list, array, sequence and those computation expressions supporting Yield/Combine/Zero/Delay.

See the RFC for notes and discussion

@dsyme
Copy link
Contributor Author

dsyme commented Mar 11, 2019

The simplest, most compatible rule seems to be "implicit yields are enabled if there is no explicit 'yield' in the computation expression"

I have also added the implementation of this rule for computation expressions (rather than just array/list/sequence expressions) using yield

@auduchinok
Copy link
Member

auduchinok commented Mar 11, 2019

We need to consider if this applied to other computation expressions, or just sequence/list/array expressions.

I'd be glad if it worked in other cases too.

@dsyme dsyme changed the title [Needs RFC] allow dropping yield in list, array and sequence expressions [Needs RFC] Implicit yields (allow dropping yield in list, array, sequence and computation expressions) Mar 11, 2019
@dsyme
Copy link
Contributor Author

dsyme commented Mar 11, 2019

I'd be glad if it worked in other cases too.

I've

  1. added the general implementation for computation expressions
  2. expanded the testing
  3. clarified the proposed rules in this issue (getting it closer to a draft of an RFC)

@dsyme dsyme changed the title [FS-1069] Implicit yields (allow dropping yield in list, array, sequence and computation expressions) [RFC FS-1069] Implicit yields (allow dropping yield in list, array, sequence and computation expressions) Mar 12, 2019
@vasily-kirichenko
Copy link
Contributor

vasily-kirichenko commented Mar 19, 2019

Why not enable this for yield! as well? If an expression has type that implements seq<'a> where 'a is the (inferred) type of elements of the computation expression, why not just implicitly yield! it?

@dsyme
Copy link
Contributor Author

dsyme commented Mar 19, 2019

Why not enable this for yield! as well? If an expression has type that implements seq<'a> where 'a is the (inferred) type of elements of the computation expression, why not just implicitly yield! it?

It's a good question. My intuition is it's just too much, too implicit, both for type inference and for users. I don't have proof of this though.

@forki
Copy link
Contributor

forki commented Mar 19, 2019 via email

@dsyme
Copy link
Contributor Author

dsyme commented Mar 21, 2019

Unrelated flaky test failure:

[xUnit.net 00:01:16.59]     FSharp.Core.UnitTests.FSharp_Core.Microsoft_FSharp_Control.AsyncType.TaskAsyncValueException [FAIL]
Failed   FSharp.Core.UnitTests.FSharp_Core.Microsoft_FSharp_Control.AsyncType.TaskAsyncValueException
Error Message:
 System.TimeoutException : The operation has timed out.
Stack Trace:
   at Microsoft.FSharp.Control.AsyncPrimitives.RunSynchronouslyInAnotherThread[a](CancellationToken token, FSharpAsync`1 computation, FSharpOption`1 timeout)
   at Microsoft.FSharp.Control.FSharpAsync.RunSynchronously[T](FSharpAsync`1 computation, FSharpOption`1 timeout, FSharpOption`1 cancellationToken)
   at FSharp.Core.UnitTests.FSharp_Core.Microsoft_FSharp_Control.AsyncType.TaskAsyncValueException() in D:\a\1\s\tests\FSharp.Core.UnitTests\FSharp.Core\Microsoft.FSharp.Control\AsyncType.fs:line 424

@dsyme dsyme closed this Mar 21, 2019
@dsyme dsyme reopened this Mar 21, 2019
@dsyme dsyme removed the Needs-RFC label Mar 21, 2019
@isaacabraham
Copy link
Contributor

@vasily-kirichenko how would you distinguish what the return type of this is - is it int list or int list list?

let x =
  [
      [ 1 .. 5 ]
  ]

What about these cases

let y =
  [
      [ 1 .. 5 ] // implicitly yield! ? Or is it int list list?
      1 // compiler error?
  ]

let z =
  [
      1
      [ 1 .. 5 ] // compiler error? implicitly "yield!" ?
  ]

On the one hand, I get the idea of making this "simpler" to look at, but on the other hand I find this "implict" yield (and especially yield!) feels to me to be going against the explicit and (very importantly) predictable nature of F#. I feel that this feature would have to be very clearly documented to explain what and why is happening.

@dsyme dsyme closed this Apr 14, 2019
@dsyme dsyme reopened this Apr 14, 2019
@dsyme
Copy link
Contributor Author

dsyme commented May 22, 2019

Closed in favour of #6806

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants