I suggest we ...

Allow nested Computation Expression for writing Builder Like DSLs

type DirectionBuilder() =
member self.Yield(()) = []

[<CustomOperation("left")>]
member self.Left (acc, degree) = somefn degree

[<CustomOperation("right")>]
member self.Right (acc, degree) = somefn degree

[<CustomOperation("velocity")>]
member self.Velocity (acc, ()) = new VelocityBuilder()

and VelocityBuilder() =
member self.Yield(()) = []

[<CustomOperation("accelerate")>]
member self.Accesslarate (acc, v) = somefn v

[<CustomOperation("decelerate")>]
member self.Decelerate (acc, v) = somefn v

let direction () = new DirectionBuilder()

direction() {
right 90
left 30
velocity() {
accelerate 1
}
}

5 votes
Vote
Sign in
(thinking…)
Sign in with: Facebook Google
Signed in as (Sign out)
You have left! (?) (thinking…)
Robert Kuzelj shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

1 comment

Sign in
(thinking…)
Sign in with: Facebook Google
Signed in as (Sign out)
Submitting...
  • Don Syme commented  ·   ·  Flag as inappropriate

    More design detail, use-cases and motivation would be needed here. This would be a pretty substantial feature - what's the killer app for this? The above case is not convincing enough for me.

F# Language

Feedback and Knowledge Base