[Haskell-beginners] Trying to understand type families, continued...

Michael Litchard michael at schmong.org
Sat Aug 20 01:53:54 CEST 2011


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?



More information about the Beginners mailing list