Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Nested CE
type ThirdLevel =
| Payload of int
and SecondLevel =
| Nested of ThirdLevel list
| Payload of string
and FirstLevel =
| Nested of SecondLevel list
| Payload of double
| EmptyLine
and AllBuilder() =
member __.Yield (x: FirstLevel list) = x
member __.Combine (x, y) = x @ y
member __.Delay f = f()
member __.Zero() = []
and FirstBuilder() =
member __.Yield (x: double) = [FirstLevel.Payload x]
member __.Yield (x: SecondLevel list) = [FirstLevel.Nested x]
member __.Combine (x, y) = x @ y
member __.Delay f = f()
member __.Zero() = [FirstLevel.EmptyLine]
and SecondBuilder() =
member __.Yield (x: string) = [SecondLevel.Payload x]
member __.Yield (x: ThirdLevel list) = [SecondLevel.Nested x]
member __.Combine (x, y) = x @ y
member __.Delay f = f()
member __.Zero() = []
and ThirdBuilder() =
member __.Yield (x: int) = [ThirdLevel.Payload x]
member __.Combine (x, y) = x @ y
member __.Delay f = f()
member __.Zero() = []
let all = AllBuilder()
let first = FirstBuilder()
let second = SecondBuilder()
let third = ThirdBuilder()
let someThird = third { 1 }
let example =
all {
first { printfn "hello" }
first {
2.
//it's a compile error to put "first" inside "first"
//first {
// 1.
//}
second {
someThird
third { 1 }
// compile error to put string in "third"
//third { "1" }
"1"
}
10.
}
}
//val example : FirstLevel list =
//[EmptyLine; Payload 2.0; Nested [Nested [Payload 1]; Nested [Payload 1]; Payload "1"]; Payload 10.0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.