STArray and Lazy ST

Simon Peyton-Jones
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!


| -----Original Message-----
| From:
| On Behalf Of Josef Svenningsson
| Sent: 08 May 2003 16:20
| To:
| Subject: STArray and Lazy ST
| Hi,
| I've spent some time running after a little bug in my code that seems
| 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
| do it?
| Further more, I got some really weird error messages. My file looked
| something like this:
| \begin{pseudocode}
| import Control.Monad.ST.Lazy
| import Data.Array.ST
| ... further down I have the following function....
| foo :: Ix v =3D> STArray s v Bool -> v -> ST s Bool
| foo a b =3D readArray a b
| \end{pseudocode}
| Now I got the following error message:
| 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
| 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
| ST type! In the error message the name ST means two different things
| is REALLY confusing and it took me a while to figure it out. One ST
| from Control.Monad.ST.Lazy and the other from Data.Array.ST.
| Is there any way to improve the situation? I'm not claiming these
| are bugs, but they certainly made my life a lot harder for a while.
| Cheers,
| 	/Josef
| _______________________________________________
| Glasgow-haskell-users mailing list