如何在函数内的Haskell中将某些内容转换为字符串
我真的是哈斯凯尔的一个笨蛋,我已经被困在一个愚蠢的函数里好几天了。 所以我有一个家庭作业,老师希望我们只修改graphviz模块实例的函数。我试图实现第一个函数,但无法将id转换为字符串(您可以通过查看graphviz模块了解原因) 这是graphviz模块(graphviz.hs) 再一次,为所有这些代码感到抱歉,我认为理解我不理解的东西是必要的 我的问题很简单:既然id不是字符串,如何实现GraphVizNodeList???如何将其转换为适合graphviz函数的值如何在函数内的Haskell中将某些内容转换为字符串,haskell,graph,functional-programming,Haskell,Graph,Functional Programming,我真的是哈斯凯尔的一个笨蛋,我已经被困在一个愚蠢的函数里好几天了。 所以我有一个家庭作业,老师希望我们只修改graphviz模块实例的函数。我试图实现第一个函数,但无法将id转换为字符串(您可以通过查看graphviz模块了解原因) 这是graphviz模块(graphviz.hs) 再一次,为所有这些代码感到抱歉,我认为理解我不理解的东西是必要的 我的问题很简单:既然id不是字符串,如何实现GraphVizNodeList???如何将其转换为适合graphviz函数的值 非常感谢和抱歉grap
非常感谢和抱歉
graphvizNodesList(图形弧标签样式)=[(id,label,style)| idgraphvizNodesList(图形弧标签样式)=[(id,label,style)| idI尝试过了,我在[(show id,label,style)|中做了,或者这里show idkey是数据的函数。Map key::Map k a->[k],O(n)。按升序返回映射的所有键。请参阅我的新注释。我认为存在比仅将id
转换为String
键是数据的函数更大的错误。map
然后id
graphvizNodesList (Graph arcs labels styles) = [(id,label,style) | id<-keys, label<-(elems labels), style<-(elems styles)]
import Data.Map (Map,empty,member,insert,keys,findWithDefault,assocs ,fromList,(!),union,mapWithKey,toList,elems)
import Graphviz
-- | A directed graph
data Graph v = Graph
{ arcsMap :: Map v [v] -- A map associating a vertex with its successors
, labelMap :: Map v String -- The Graphviz label of each node
, styleMap :: Map v String -- The Graphviz style of each node
}
...
Some functions implemented here not important
...
...
blabla
...
-- | A triple @(id,label,style)@ where
--
-- * @id@ is the key identifying the node (must be unique)
-- * @label@ is any string compatible with Graphviz
-- * @style@ is any string describing the Graphviz style of the node
type GraphvizNode = (String, String, String)
-- | A triple @(id1,id2,label)@ where
--
-- * @id1@ is the key of the source vertex
-- * @id2@ is the key of the target vertex
-- * @label@ is the label of the arc
type GraphvizArc = (String, String, String)
-- | Class of types that can be converted to Graphviz strings
class Graphviz g where
-- | The list of Graphviz nodes
--
-- It returns a list of all nodes of the graph, indicating the label and
-- the style of each node.
graphvizNodesList :: g -> [GraphvizNode]
-- | The list of Graphviz arcs
--
-- It returns a list of all arcs of the graph, indicating the label of the
-- arc.
graphvizArcsList :: g -> [GraphvizArc]
-- | The header of the Graphviz string
--
-- This is the string printed before writing the nodes and the arcs.
graphvizHeader :: g -> String
graphvizHeader _ = "digraph {\n"
blablablabla...
graphvizNodesList (Graph arcs labels styles) = [(id,label,style) | id<-keys, label<-(elems labels), style<-(elems styles)]