elm-community / graph

Functional Graph Library in Elm.

Home Page:http://package.elm-lang.org/packages/elm-community/graph/latest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to run regular graph functions on acyclic graphs

DavidDTA opened this issue · comments

Since AcyclicGraph is an opaque type it can not be passed into the normal graph functions (such as nodeIds). This means that if I want to run both functions which require an acyclic graph and those that do not I need to keep around two references to the same graph (one of type Graph, and the other of type AcyclicGraph).

There are two solutions to this:

  1. Create a method forgetAcyclicness : AcyclicGraph n e -> Graph n e which can be used to obtain a Graph reference from an AcyclicGraph. This is the easier approach from the current state of the library.
  2. Create a nonce type Acyclic and add a phantom type variable to Graph. The graph creation methods would return Graph n e () and most of the existing methods could then take a Graph n e a, but the acyclic ones would only accept Graph n e Acyclic. This is I think the conceptually cleaner approach.

Thanks for your input! I'd happily accept a PR implementing 1.

I'd be happy to make one! Do you have input regarding the name of that method? My instinct would probably be acyclicGraphToGraph.

Actually, I came to like forgetAcyclic or getAcyclicGraph. Anyway, choose one that suits you.