How do you represent a graph in Haskell?

后端 未结 8 724
星月不相逢
星月不相逢 2020-11-27 09:39

It\'s easy enough to represent a tree or list in haskell using algebraic data types. But how would you go about typographically representing a graph? It seems that you need

8条回答
  •  -上瘾入骨i
    2020-11-27 10:05

    I like this implementation of a graph taken from here

    import Data.Maybe
    import Data.Array
    
    class Enum b => Graph a b | a -> b where
        vertices ::  a -> [b]
        edge :: a -> b -> b -> Maybe Double
        fromInt :: a -> Int -> b
    

提交回复
热议问题