[Haskell-cafe] [Haskell] ANN: Haskell bindings for the igraph C library

Nils Schweinsberg mail at nils.cc
Mon Dec 17 14:38:49 CET 2012


Am 16.12.2012 20:24, schrieb Jason Dagit:
> How does this compare with fgl? http://hackage.haskell.org/package/fgl

FGL is a pure Haskell library while our haskell-igraph package uses the 
foreign function interface to run all graph-related calculations in C 
the C library igraph (I haven't implemented any graph algorithms). The 
runtime performance with our igraph library should be the same as if 
you'd be using the native C library (if you ignore the small 
Haskell->C->Haskell overhead).

It is also seems to be more of a higher level library. As user you don't 
have to worry about node-IDs/labels or whether your graph is "static" or 
not (in the FGL context). Using features like GADTs and type 
families/associated types it is possible to keep track of informations 
like whether or not your graph is directed/weighted or not, while in FGL 
all graphs are by default directed and unweighted. Consider for example

   edges :: Graph d a -> [Edge d a]

   -- directed, unweighted graph
   g :: Graph D a

   -- undirected, weighted graph
   w :: Graph (Weighted U) a

which leads to

   edges g :: [Edge D a]
   edges w :: [Edge (Weighted U) a]

or even functions like

   toUndirected :: (IsDirected d, E (ToUndirected d) a)
                => Graph d a
                -> Graph (ToUndirected d) a

   toDirected   :: (IsUndirected u, E (ToDirected u) a)
                => Graph u a
                -> Graph (ToDirected u) a

which evaluate to

   toUndirected g :: Graph U a
   toDirected   w :: Graph (Weighted D) a

This is even revertable, and `toDirected . toUndirected == id` while the 
FGL function `undir` simply adds all missing edges and loses track of 
what the original/directed graph looked like.

Maybe George has more details on why he wanted to use igraph instead of FGL.


- Nils



More information about the Haskell-Cafe mailing list