Modelling labview/blender style diagrams with types

Hi all

I have a fairly generic question. I am wondering, out of curiosity, whether one could model a graph like the following with types:

(from GitHub - projectstorm/react-diagrams: a super simple, no-nonsense diagramming library written in react that just works)

Basically every node should be an object mapping inputs to outputs but instead of just having a single input / output type it can have several ports on both ends. Composing these objects should work by connecting some ports to others as inputs. The new, composed object loses the connected ports and exposes the combined unconnected ones. I am interested in describing the full Graph on the type level so that it can be typechecked but also plotted.

I know that DAGs can be described with types via free Arrows but those would use nested, unnamed Tuples to describe the ports which really isn’t convenient at all and difficult to handle if the graph has lots of branches without Haskell’s proc notation. I wonder if Purescript’s extensible records (for product ports) and Variant types can’t be used to make this a lot more convenient. I also know that effect systems can be built on top of such DAGs (like kernmantle GitHub - tweag/kernmantle: Braiding extensible effects together in a pipeline/workflow of tasks) and that’s great but I don’t need this right now (although if you have an idea how to do this as well let me know).

Any ideas whether someone has done something similar or whether there is a principal problem with this?

@Adrielus weren’t you working on something like this?

Yep, my goto solution has been HashMap NodeId NodeData. This is not very ergonomic to work with (especially if you want invariants like a pin only being connected to a single other pin, which requires you to keep the connection data inside NodeData instead of using a separate structure like the BihashMap a = HashMap a (Array a) I have used for my last project)

I have never heard of representing DAGs using free arrows, but that sounds super interesting, and I would love to hear more!

And as a last point, the only thing keeping me sane while doing this have been optics: lenses & friends are your best friend for manipulating stuff of this complexity!

1 Like

I just wish I understood the words you said :sweat_smile: