tags:

views:

67

answers:

1

I am attempting to pass back a Node type from this function, but I get the error that empty is out of scope:

import Data.Set (Set)  
import qualified Data.Set as Set

data Node = Vertex String (Set Node)  
    deriving Show

toNode :: String -> Node  
toNode x = Vertex x empty

What am I doing wrong?

+5  A: 

import qualified Data.Set as Set means that when you want to use something from Data.Set, you have to qualify it with Set.. So to use empty write Set.empty.

sepp2k
Should I have both of those import statements? I just took it from example code.
mvid
The first imports the type Set unqualified (so you don't have to write `Set.Set` in type signatures), but nothing else. The second import allows you to use everything else from `Data.Set` by qualifying it with `Set.`. People generally do it this way (as opposed to importing everything unqualified) to avoid name collisions with Prelude functions (like `map`, `filter` etc.).
sepp2k
@sepp2k: Or worse, name collisions with `Data.Map`, `Data.IntSet`, and `Data.IntMap`...
camccann