[Haskell-cafe] STArray newListArray

Daniel Fischer daniel.is.fischer at web.de
Sun Feb 21 15:51:03 EST 2010


Am Sonntag 21 Februar 2010 21:26:31 schrieb Vojtěch Knyttl:
> Ok, the problem was the Monad, which I still don't get completely,
> because I continue like this:
>
> data Field = W|B|H|D deriving (Eq,Show)
>
> pas :: ST s (STArray s (Int, Int) Field) -> ST s (STArray s (Int, Int)
> Field) pas b = do writeArray b (1,1) W

Here, b has type (STArray s (Int,Int) Field), and writeArray has type
ghci> :t writeArray
writeArray :: (MArray a e m, Ix i) => a i e -> i -> e -> m ()
, in this case (STArray s (Int,Int) Field -> (Int,Int) -> Field -> ST s (), 
so the signature ought to be

pas :: STArray s (Int,Int) Field -> ST s ()

It's new[List]Array, readArray, writeArray etc which have a type of 
... -> ST s something
the array itself doesn't.

>
> And still getting:
>     Couldn't match expected type `STArray s (Int, Int) Field'
>            against inferred type `Field'

That's puzzling. I'd expect a different error message.

>
> Thanks.


More information about the Haskell-Cafe mailing list