GHC and MPTCs

Simon Peyton-Jones simonpj at microsoft.com
Thu Aug 26 12:32:54 EDT 2004


Your problem is that
	next_state :: forall s v. VertexState s v => s -> s

So an application of next_state to an argument of type sty will require
the constraint
	VertexState sty v
but that says NOTHING about v.  It's a bit like calling a function with
type
	forall a b. Foo a => b -> b

Anyway, I think what you want is a functional dependency

	class VertesState s v | s -> v

Then fixing s will fix v, which is what you want I think

Simon

| -----Original Message-----
| From: glasgow-haskell-users-bounces at haskell.org
[mailto:glasgow-haskell-users-
| bounces at haskell.org] On Behalf Of Ketil Malde
| Sent: 25 August 2004 14:45
| To: glasgow-haskell-users at haskell.org
| Subject: GHC and MPTCs
| 
| 
| 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
| _______________________________________________
| Glasgow-haskell-users mailing list
| Glasgow-haskell-users at haskell.org
| http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


More information about the Glasgow-haskell-users mailing list