Connect vertices of the graph in Haskell -


graph stored list of tuples. first element of tuple - vertex, second element tuple - vertices connected.

headname-vertex want connect[:t=srting]**

elements-vertises want connect[:t=list]**

a can connect vertices [(1,[2]),(2,[])], want connect [(1,[2]),(2,[1])]. kind of did, not work. wrong? help, please.

connect_command graph headname []=(graph,"you didnt enter elements connect!\n") connect_command graph headname elements=     if (has_element graph headname) ((update_connect graph graph headname elements []),"element "++headname++"  connected "++listtostring (checked_elements graph headname elements []) []++"\n")     else (graph,"element "++headname++" name not found!")   update_connect _ [] _ _ result=result  update_connect maingraph (item:graph) headname (i:elements) result=     if ((fst item)==headname) (update_connect maingraph graph headname elements (result++[((fst item),(checked_elements maingraph headname elements []))]))     else if ((fst item)==i) (update_connect maingraph graph headname (i:elements) (result++[((fst item),[headname])]))     else (update_connect maingraph graph headname elements (result++[item]))   checked_elements _ _ [] result=result checked_elements graph headname (item:elements) result=     if (has_element graph item)&& (item /=headname)then checked_elements graph headname elements (result++[item])     else (checked_elements graph headname elements result) 

headname-vertex want connect*[:t=srting]*

elements-vertises want connect*[:t=list]*

  1. "does not work" kind of vague.

  2. you appear trying use lists of key/value tuples dictionary. standard libraries provide real dictionary, don't have manually implement functions has_element yourself. @ data.map.

  3. actually, standard libraries have data.graph, may need. (depending on whether need graph, or whether you're writing way learn haskell.)

  4. at rate, defining custom data types rather having lists , tuples , strings in narrowing down what's going wrong. (it try figure out what's supposed happening here...)


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -