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

Graph CE #89

Open
vasily-kirichenko opened this issue Jan 14, 2018 · 2 comments
Open

Graph CE #89

vasily-kirichenko opened this issue Jan 14, 2018 · 2 comments

Comments

@vasily-kirichenko
Copy link
Contributor

type GraphBuilder(b: GraphDsl.Builder<_>) =
    member __.Return x = x
    member __.Yield x = x
    member __.Bind(m, f) = f(b.Add(m))

[<AutoOpen>]
module GraphBuilder =
    let graph = GraphBuilder
let partition (evens: Flow<int, 'a, _>) (odds: Flow<int, 'a, _>) =
        Graph.create (fun b -> 
            graph b {
                let! p = Partition(2, fun x -> if x % 2 = 0 then 0 else 1)
                let! merge = Merge<_>(2)
                b.From(p.Out 0).Via(evens).To(merge.In 0)
                b.From(p.Out 1).Via(odds).To(merge.In 1)
                return FlowShape(p.In, merge.Out)
            })

It works, but I don't like how Graph.create (fun b -> graph b { ... }) looks :( Also, I'd like to add custom operations so the following would be possible:

graph b {
    let! p = Partition(2, fun x -> if x % 2 = 0 then 0 else 1)
    let! merge = Merge<_>(2)

    from (p.Out 0)
    via evens
    to (merge.In 0)

    return FlowShape(p.In, merge.Out)
}

(I've failed so far).

@Horusiath
Copy link
Owner

Great idea :) With custom operations, maybe we'd be able to completely remove builder and keep it implicit inside the computation expression itself. I was thinking about something like:

graph {
    let! p = Partition(2, fun x -> if x % 2 = 0 then 0 else 1)
    let! merge = Merge<_>(2)

    connect (p.Out 0 => evens => merge.In 0)

    return FlowShape(p.In, merge.Out)
}

@vasily-kirichenko
Copy link
Contributor Author

yes, I thought about hiding the builder, but I cannot see how to obtain one inside the CE since it does not have public ctor and the only way to get it is inside lambda passed to Graph.create.

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

2 participants