Rash thoughts about .NET, C#, F# and Dynamics NAV.


"Every solution will only lead to new problems."

Thursday, 13. September 2012


Graph type providers in FSharpx

Filed under: C#,F#,Informatik,Mathematik — Steffen Forkmann at 9:24 Uhr

After the official Visual Studio 2012 launch yesterday I think it’s a good idea to announce two new type providers which are based on the DGMLTypeProvider from the F# 3.0 Sample Pack.

Synchronous and asynchronous state machine

The first one is only a small extension to the DGMLTypeProvider by Tao. which allows to generate state machines from DGML files. The extension is simply that you can choose between the original async state machine and a synchronous version, which allows easier testing.

image

If you want the async version, which performs all state transitions asynchronously, you only have to write AsyncStateMachine instead of StateMachine.

State machine as a network of types

The generated state machine performs only valid state transitions, but we can go one step further and model the state transitions as compile time restrictions:

image

As you can see the compiler knows that we are in State2 and allows only the transitions to State3 and State4.

If you write labels on the edges of the graph the type provider will generate the method names based on the edge label. In the following sample I’ve created a small finite-state machine which allows to check a binary number if it has an even or odd number of zeros:

image

As you can see in this case the compiler has already calculated that 10100 has an odd number of zeros – no need to run the test Zwinkerndes Smiley.

This stuff is already part of the FSharpx.TypeProviders.Graph package on nuget so please check it out and give feedback.

Tags: , ,

4 Comments »

  1. [...] FSharpx.TypeProviders.Graph which includes type providers for state machines and graphs. [Read more] [...]

    Pingback by FSharpx type providers are available as separate nuget packages » Rash thoughts about .NET, C#, F# and Dynamics NAV. — Wednesday, 26. September 2012 um 20:28 Uhr

  2. Can a function such .findPathsTo(Sate42) be integrated into the Graph Type Provider(TP)? (like: https://github.com/jadell/neo4jphp/blob/master/examples/bacon.php)

    I’ve no idea how to do findPathsTo from the “outside”.
    The “.”-navigation in the IDE is very cool with the TP.
    But how can this mixed with queries?
    (maybe thinking about new possibilities with TP has shake my brain.)

    Comment by Wirbel — Saturday, 29. September 2012 um 9:21 Uhr

  3. @Wirbel: That’s an intersting idea. Let’s try to do this.

    Comment by Steffen Forkmann — Saturday, 29. September 2012 um 9:53 Uhr

  4. For me that is just mindblowing. raising static data to the stage of compiler constraint with ease is one of those defining moments. to turn it into an industrial movement though, we need a platform for composing those operations, labelling, freezing those namespaces.

    Comment by nicolas — Wednesday, 3. October 2012 um 8:08 Uhr

RSS feed for comments on this post. | TrackBack URI

Leave a comment

XHTML ( You can use these tags): <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> .