
On Wed, 2004-06-30 at 12:00, MR K P SCHUPKE wrote:
Ahh.. I see whats happening:
MArray (STUArray s) a (ST s) => String -> String -> ST s (UArray (Int,Int) a)
IArray UArray a => String -> String -> a
nothing here is specifying a... you cannot leave a polymorphic in this case.
You need to supply the constraint "MArray (STUArray s) a (ST s)" to distString but "s" is not in context...
Right, because the return type of distString Int is an instance of MArray. But if we try to make 'a' polymorphic then we can't specify the constraint because it involves 's'. So the obvious follow-on question, is is there any intermediate point where 's' is in scope where we can supply a type annotation to supply the context or is it simply impossible? To restate the question for Haskell-Cafe readers: Is it possible to return an arbitrary unboxed array that was constructed in the ST monad (as an STUArray)? The issue is that you end up with a MArray class constraint that involves the state thread's 's' parameter, but this type variable gets 'hidden' by runST which universally quantifies over it. runST :: forall a. (forall s. ST s a) -> a Duncan