
On 3/16/11 9:52 AM, Andrew Coppin wrote:
Hmm, yes. That will work, but I wonder if there's some way of doing this that doesn't limit the scope of the container to one single span of code...
You can write helper functions which take containers as argument by parameterizing these helper functions over s:
takesTwoContainers :: Container s1 -> Container s2 -> ... takesTwoContainers c1 c2 = ... -- c1 and c2 can be used here
This function could be called like this:
withContainer (\c1 -> withContainer (\c2 -> takesTwoContainers c1 c2)) -- c1 and c2 can be used here
In this example, the scope of the containers is not limited to a single span of code.
What you can't do is write functions such as
foo :: Container x -> (Cursor x, Cursor x)
for example.
-- ? foo cx = (curse cx, curse cx)
Perhaps this property is just too tricky to check in the type system. It's quite possible to check it at run-time; I'd just prefer to check at compile-time, if it's not too difficult to implement.
It sounds like you want something based on "memory regions". The ST monad uses a restricted version of regions, but there are more general versions which allow for comparing region names for equality etc (as opposed to ST where the existential quantification requires the types to unify or be unequal). Try googling around. -- Live well, ~wren