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

Computation Expressions bug when using MaintainsVariableSpace / ProjectionParameter #1373

Open
GratianPlume opened this issue Jun 20, 2024 · 0 comments

Comments

@GratianPlume
Copy link

   type AH =
      | AH

      member _.For(x, f) = f x

      member _.Yield x = x

      [<CustomOperation(MaintainsVariableSpace=true,AllowIntoPattern=true)>]
      member _.foo(x, [<ProjectionParameter>]y) = 
         let x = y x
         x, "A"

      [<CustomOperation(MaintainsVariableSpace=true, AllowIntoPattern=true)>]
      member _.select(src, [<ProjectionParameter>]f) = f src

   let foo (x: int) = 
      AH {
         for x in x do
         let n = x
         foo (n + x) 
         select n
      }

The above code compiles successfully, but the result is not the value of n, as intuitively expected, but "A". I understand why this is the case, but can we be smarter when parsing the CE?

Because if you don't consider the implementation of CE, it is easy for users to write wrong expressions.

But if the CE implementation considers how to avoid this, there is only one conclusion: do not generate tuples.

Not generating tuples often makes some code impossible to optimize.

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

No branches or pull requests

1 participant