# STArray and Lazy ST

Simon Peyton-Jones simonpj@microsoft.com
Fri, 9 May 2003 09:24:31 +0100

I would say that the 'bug' is that Data.Array.ST does not export ST.

GHC's policy is to report error messages in the same vocabulary as the
user would use.  Even though you have imported Control.Monad.ST.Lazy and
Data.Array.ST, you can still say "ST" unambiguously, because
Control.Monad.ST.Lazy exports ST, but Data.Array.ST does not -- so
there's only one ST in scope.

If you imported only Data.Array.ST you wouldn't be able to mention "ST"
at all.

If Data.Array.ST exported ST, the error message would give a qualified
name for the ST constructor -- qualified by one of its import modules,
that is.

I'll ask Simon M if we should export a bit more from Data.Array.ST, but
actually I think the compiler is behaving right.  It'd be pain if every
error message used fully-qualified names!

Simon

| -----Original Message-----
| On Behalf Of Josef Svenningsson
| Sent: 08 May 2003 16:20
| Subject: STArray and Lazy ST
|=20
| Hi,
|=20
| I've spent some time running after a little bug in my code that seems
to
| be caused by the following fact:
| If I want to use Data.Array.ST I can only use it with the strict ST
| I would really like to use it with the lazy ST monad. Is there any way
to
| do it?
|=20
| Further more, I got some really weird error messages. My file looked
| something like this:
|=20
| \begin{pseudocode}
| import Data.Array.ST
|=20
| ... further down I have the following function....
|=20
| foo :: Ix v =3D> STArray s v Bool -> v -> ST s Bool
| foo a b =3D readArray a b
| \end{pseudocode}
|=20
| Now I got the following error message:
|=20
| formats/Graph.hs:91:
|     Could not deduce (MArray (STArray s) Bool (ST s))
|         from the context (Ix v)
|     Probable fix:
|         Add (MArray (STArray s) Bool (ST s))
|         to the type signature(s) for contains'
|         Or add an instance declaration for (MArray (STArray s) Bool
(ST s))
|     arising from use of readArray' at formats/Graph.hs:91
|     In the definition of foo': readArray a b
|=20
| The thing is, there is already an instance MArray (STArray s) e (ST
s)! So
| what is the compiler complaining about? The problem is, it's not the
right
| ST type! In the error message the name ST means two different things
which
| is REALLY confusing and it took me a while to figure it out. One ST
comes
| from Control.Monad.ST.Lazy and the other from Data.Array.ST.
|=20
| Is there any way to improve the situation? I'm not claiming these
issues
| are bugs, but they certainly made my life a lot harder for a while.
|=20
| Cheers,
|=20
| 	/Josef
|=20
| _______________________________________________
`