Re: [Haskell-cafe] Library design question

2008-09-18 Thread Duncan Coutts
On Thu, 2008-09-18 at 15:43 -0300, Andre Nathan wrote: > My Graph type is the following. > > data Graph a b = Graph > { adjacencies :: Map Int (a, (Map Int b)) > , numVertices :: Int > , numEdges:: Int > } > addVertex :: Int -> a -> State (Graph a b) () > addVertex vert

Re: [Haskell-cafe] Library design question

2008-09-18 Thread Henning Thielemann
On Thu, 18 Sep 2008, Andre Nathan wrote: On Thu, 2008-09-18 at 21:15 +0200, Henning Thielemann wrote: Think of the state monad as processing a graph in-place. Which graph is addressed is declared when running the State monad using runState or evalState. Interesting. Is it good practice then

Re: [Haskell-cafe] Library design question

2008-09-18 Thread Andre Nathan
On Thu, 2008-09-18 at 21:13 +0200, minh thu wrote: > If you need the one inside the State monad, you can reuse the new > version of addVertex. You mean making the graph creation functions (which will call addVertex/Edge) use the State monad instead? Interesting idea... what I really wanted was to

Re: [Haskell-cafe] Library design question

2008-09-18 Thread Andre Nathan
On Thu, 2008-09-18 at 21:15 +0200, Henning Thielemann wrote: > Think of the state monad as processing a graph in-place. Which graph is > addressed is declared when running the State monad using runState or > evalState. Interesting. Is it good practice then to do something like type GraphM a b

Re: [Haskell-cafe] Library design question

2008-09-18 Thread Henning Thielemann
On Thu, 18 Sep 2008, Andre Nathan wrote: The issue I hit was when writing the function to add a vertex to the graph. Since I need to update the vertex counter, I've used the state monad: addVertex :: Int -> a -> State (Graph a b) () addVertex vertex label = do g <- get let adj = Map.in

Re: [Haskell-cafe] Library design question

2008-09-18 Thread minh thu
2008/9/18 Andre Nathan <[EMAIL PROTECTED]>: > Hello > > I'm trying to write a simple graph library for a project of mine > (actually, I'm porting it from OCaml) but I've got a design question > right in the beginning. > > My Graph type is the following. > > data Graph a b = Graph >{ adjacencie

[Haskell-cafe] Library design question

2008-09-18 Thread Andre Nathan
Hello I'm trying to write a simple graph library for a project of mine (actually, I'm porting it from OCaml) but I've got a design question right in the beginning. My Graph type is the following. data Graph a b = Graph { adjacencies :: Map Int (a, (Map Int b)) , numVertices :: Int