The example is missing a bit of proc for reproduction but this compiles for me 
(though it segfaults at runtime after).
    
    
    import sets, tables, hashes
    
    type
      DEdge*[K, V] = ref object
        fm*: DNode[K]
        to*: DNode[K]
        weight*: V
      
      DNode*[K, V] = ref object
        key*: K
        outedges: HashSet[DEdge[K, V]]
        inedges:  HashSet[DEdge[K, V]]
        priority*: V # for algorithms to sort upon
        index*: int  # for algorithms to store sort position
      
      DGraph*[K, V] = object
        # A directed graph of nodes and directed edges
        nodes: Table[K, DNode[K, V]]
    
    proc hash(x: DEdge): Hash =
      discard
    
    proc add_edge*[K, V](graph: var DGraph[K, V], fm: K, to: K, weight: V = 1): 
DEdge[K, V] =
      # var n1 = graph.add_node(fm)
      # var n2 = graph.add_node(to)
      # result = DEdge[K, V](fm: n1, to: n2, weight: weight)
      result.fm.outedges.incl(result)
      result.to.inedges.incl(result)
    
    proc add_edges*[K, V](graph: var DGraph[K, V], edges: seq[(K,K,V,)]): 
seq[DEdge[K, V]] =
      for (n1, n2, w) in edges:
        result.add(add_edge(graph, n1, n2, w))
    
    var g = DGraph[int,float]()
    let _ = g.add_edges(@[(3,4,3.5),(4,5,4.5)])
    
    
    Run

Note that to avoid potential false inference I would change the `add_edge` 
signature from `weight: V = 1` to `weight = V(1)`

Reply via email to