Trying to understand type families, continued...

I'm playing around with type families, and using as a starting point, this example: class GMapKey k where data GMap k :: * -> * empty :: GMap k v lookup :: k -> GMap k v -> Maybe v insert :: k -> v -> GMap k v -> GMap k v Here's an instance that will lead to my question instance GMapKey Int where data GMap Int v = GMapInt (Data.IntMap.IntMap v) empty = GMapInt Data.IntMap.empty lookup k (GMapInt m) = Data.IntMap.lookup k m insert k v (GMapInt m) = GMapInt (Data.IntMap.insert k v m) Here is my experiment
class PM m where data ServerModel m :: * -> * movetoPreProcess :: m -> FilePath -> IO ()
I want to write an instance for this. As GMap can have an Int with some value v, I would like ServerModel to have a type I create (with another data declaration, call it Foo v) with values I define. Here's a little more detail for the sake of any explanation that might come my way. data ModelFoo a = ModelBar a | ModelBaz a ModelFoo is the type I want to use with ServerModel. What would the instance declaration look like? If ServerModel is defined within PM, should ModelFoo be as well?

kmc from #haskell at freenode has told me this is a classic case of
"don't need no typeclass here". So I reckon I will take the approach
discussed in #haskell and abandon this design.
On Fri, Aug 19, 2011 at 4:53 PM, Michael Litchard
I'm playing around with type families, and using as a starting point, this example:
class GMapKey k where data GMap k :: * -> * empty :: GMap k v lookup :: k -> GMap k v -> Maybe v insert :: k -> v -> GMap k v -> GMap k v
Here's an instance that will lead to my question
instance GMapKey Int where data GMap Int v = GMapInt (Data.IntMap.IntMap v) empty = GMapInt Data.IntMap.empty lookup k (GMapInt m) = Data.IntMap.lookup k m insert k v (GMapInt m) = GMapInt (Data.IntMap.insert k v m)
Here is my experiment
class PM m where data ServerModel m :: * -> * movetoPreProcess :: m -> FilePath -> IO ()
I want to write an instance for this. As GMap can have an Int with some value v, I would like ServerModel to have a type I create (with another data declaration, call it Foo v) with values I define.
Here's a little more detail for the sake of any explanation that might come my way.
data ModelFoo a = ModelBar a | ModelBaz a
ModelFoo is the type I want to use with ServerModel. What would the instance declaration look like? If ServerModel is defined within PM, should ModelFoo be as well?
participants (1)
-
Michael Litchard