Haskell Ord instance with a Set
Posted
by mvid
on Stack Overflow
See other posts from Stack Overflow
or by mvid
Published on 2010-06-17T20:42:26Z
Indexed on
2010/06/17
20:53 UTC
Read the original article
Hit count: 298
I have some code that I would like to use to append an edge to a Node data structure:
import Data.Set (Set)
import qualified Data.Set as Set
data Node = Vertex String (Set Node)
deriving Show
addEdge :: Node -> Node -> Node
addEdge (Vertex name neighbors) destination
| Set.null neighbors = Vertex name (Set.singleton destination)
| otherwise = Vertex name (Set.insert destination neighbors)
However when I try to compile I get this error:
No instance for (Ord Node)
arising from a use of `Set.insert'
As far as I can tell, Set.insert expects nothing but a value and a set to insert it into. What is this Ord?
© Stack Overflow or respective owner