
colour_grid :: (Particle -> IO ()) -> Grid ph -> IO () colour_grid fn g = sequence_ $ runST $ do ps <- grid_coords g mapM (\pix -> do particle <- read_grid g pix return $ fn particle ) ps When I attempt to run this, GHCi just gives me a very cryptic type checker error. I can't figure out what's wrong here. As far as I can tell, this should run...

I haven't tried to run the code, but my first bet is that, due to the
rank-2 polymorphism of ST, you should use parenthesis instead of $ in
the case of runST.
On Sun, Aug 24, 2008 at 3:25 PM, Andrew Coppin
colour_grid :: (Particle -> IO ()) -> Grid ph -> IO () colour_grid fn g = sequence_ $ runST $ do ps <- grid_coords g
mapM (\pix -> do particle <- read_grid g pix return $ fn particle ) ps
When I attempt to run this, GHCi just gives me a very cryptic type checker error. I can't figure out what's wrong here. As far as I can tell, this should run...
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Alfonso Acosta wrote:
I haven't tried to run the code, but my first bet is that, due to the rank-2 polymorphism of ST, you should use parenthesis instead of $ in the case of runST.
Perhaps if Andrew is using an old compiler. That is no longer a problem in recent versions of GHC. A more basic issue is that fn is in the IO monad, but its use inside the mapM will need it to be in the ST monad. Regards, Yitz

Am Sonntag, 24. August 2008 17:21 schrieb Yitzchak Gale:
Alfonso Acosta wrote:
I haven't tried to run the code, but my first bet is that, due to the rank-2 polymorphism of ST, you should use parenthesis instead of $ in the case of runST.
Perhaps if Andrew is using an old compiler. That is no longer a problem in recent versions of GHC.
A more basic issue is that fn is in the IO monad, but its use inside the mapM will need it to be in the ST monad.
No, return (fn particle) :: ST s (IO ()) , so that's fine. Indeed, filling in a few dummies, the code compiles with the 6.8 branch.
Regards, Yitz
Cheers, Daniel

I wrote:
A more basic issue is that fn is in the IO monad, but its use inside the mapM will need it to be in the ST monad.
Daniel Fischer wrote:
No, return (fn particle) :: ST s (IO ()) , so that's fine.
Ah, true. But I doubt that Andrew really meant to do the calculation in ST s (IO ()).
Indeed, filling in a few dummies, the code compiles with the 6.8 branch.
So then the only way to know why it didn't compile for Andrew is if we see more of the code. But that's only a technical issue. I hope that now Andrew has a better idea about what's wrong. If not - please let us know. Regards, Yitz

BTW, this is a case where it may be more convenient to use forM: forM ps $ \pix -> do particle <- read_grid g pix return $ fn particle (untested...) forM is just another way of saying (flip mapM). / Emil Andrew Coppin skrev:
colour_grid :: (Particle -> IO ()) -> Grid ph -> IO () colour_grid fn g = sequence_ $ runST $ do ps <- grid_coords g
mapM (\pix -> do particle <- read_grid g pix return $ fn particle ) ps
When I attempt to run this, GHCi just gives me a very cryptic type checker error. I can't figure out what's wrong here. As far as I can tell, this should run...
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (5)
-
Alfonso Acosta
-
Andrew Coppin
-
Daniel Fischer
-
Emil Axelsson
-
Yitzchak Gale