[Haskell-cafe] Trouble with the ST monad

Ross Mellgren rmm-haskell at z.odi.ac
Mon Dec 29 15:54:45 EST 2008

On Dec 29, 2008, at 3:43 PM, Andre Nathan wrote:
> On Mon, 2008-12-29 at 14:19 -0500, Ross Mellgren wrote:
>> The problem is that you're trying to take a STMatrix from some other
>> ST computation and freeze it in a new ST computation. The isolation
>> between separate computations is done via the rank-2 type variable  
>> "s"
>> in all those ST functions.
> I guess I should go and read the rank-n types page on the wiki...
>> Try this:
>> freezeMatrix :: (forall s . STMatrix s a) -> Matrix a
>> freezeMatrix f :: runST (freezeMatrix f)
> Do you know why point-free style doesn't work here even with the type
> annotation?

I'm not very good with all the type-theoretic principles involved, but  
I think it's because higher ranked types cannot unify with lower  
ranked ones. I'm sure some of the more wizardly types could explain  
this with an example of how doing it like that would make something  
that should be illegal possible and the actual principles involved.

(That's longhand for "it makes a kind of intuitive sense to me but I  
can't explain it")

>> Also, instead of using an array of arrays, maybe an array with (Int,
>> Int) as the Ix might be a bit smoother?
> Thanks for the suggestion. It didn't occur to me that there was an Ix
> instance for that.
> Best,
> Andre


More information about the Haskell-Cafe mailing list