GHC and MPTCs

Ketil Malde ketil at ii.uib.no
Wed Aug 25 09:44:34 EDT 2004


Hi,

I recently tried to do the following code:

  class VertexState s v where
      new_point :: s -> v -> v -> v
      next_state :: s -> s

  -- interleave :: (VertexState s a) => s -> [a] -> [a] -> [a]
  interleave s (t:ts) (b:bs) = 
      new_point s t b : interleave (next_state s) bs (t:ts)
  interleave _ [] [b] = []

Firstly, GHC doesn't deal all too gracefully with this if the type
signature is uncommented, it tells me:

    Could not deduce (VertexState s v)
        from the context (VertexState s a)
      arising from use of `next_state' at Grid.lhs:25
    Probable fix:
        Add (VertexState s v) to the type signature(s) for `interleave'

Unfortunately, doing the probable fix just results in a new request
for (VertexState s v1), and so on.

I suppose the real problem is that GHC can't decide from next_state
that it is supposed to use exactly this instance of VertexState, is
there a good way to do that without adding an explicit dummy parameter
of type v?  

(I really would like to be able to have instances with the same s but
different v's, which I think adding functional deps would make
difficult.)

-kzm
-- 
If I haven't seen further, it is by standing in the footprints of giants


More information about the Glasgow-haskell-users mailing list