
On Fri, Aug 19, 2011 at 18:27, Michael Litchard
instance GMapKey () where data GMap () v = GMapUnit (Maybe v) empty = GMapUnit Nothing lookup () (GMapUnit v) = v insert () v (GMapUnit _) = GMapUnit $ Just v
Could someone explain what the () is doing?
Nothing? It's a dummy example using Haskell's "unit type" () (a type with only one non-bottom value, namely () itself; you can think of it as a nullary tuple type). In this case, it's being declared as an instance of GMapKey, so it is used where a GMapKey is needed; that means the key type parameter of the GMap type and the key value parameter of the lookup and insert functions. Since there's only one value, the corresponding map type GMapUnit is a Maybe instead of a list or tree of some kind, since the single possible key value is either present or absent. This lets the example focus on the instance machinery without complicating it with nontrivial lookup and insert operations. -- brandon s allbery allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms