Typesafe MRef with a regular monad

Simon Peyton-Jones simonpj@microsoft.com
Mon, 16 Jun 2003 09:16:13 +0100


| If you use Simon PJ's type signatures, you can't really disallow using
| a key from one map with another map.

Yes, that's a good point.  So there are really three issues:
	a) single-threaded-ness=20
	b) making sure you look up in the right map
	c) making sure the thing you find has the right type

Even if you have typed keys, (Key a), then if you look them up in the
wrong map, any guarantee that it maps to a value of type 'a' is out of
the window.  I can think of two solutions
	i) Guarantee that keys are unique across all maps,=20
	so that a key from one map is never in the domain of another.

	ii) Use the (ST s) and (STRef s) trick, to connect the key with
the map.
	This seems cleaner, but demands more of the programmer.

But my main point remains: that some form of typed finite map ought to
exist that does no dynamic type checks, because none are necessary.
This must be a terribly old problem; and unsafeCoerce seems like a
rather brutal "solution". =20

Simon