[Haskell-cafe] Re: The danger of Monad ((->) r)
Arie Peterson
ariep at xs4all.nl
Tue May 15 08:27:13 EDT 2007
Hi Tomek!
> In a CGI application I was gathering SQL statements I wanted to run in
> the final transaction. Because I use haskelldb, it was most convenient
> to use (Database -> IO ()) as the type of the statement or a group of
> statements. In this representation concatenating two statement groups so
> they are executed in sequence can be done with:
>
> concatStmts s1 s2 = \db -> s1 db >> s2 db
>
> My mistake was that I forgot about db and wrote:
>
> concatStmts s1 s2 = s1 >> s2
>
> And it was accepted because I had the Monad instance for ((->) r) in
> scope (from Control.Monad.Trans I guess)!
Have you considered changing the statements to have type 'ReaderT Database
IO ()'? Then (>>) actually does what you want.
Pozdrawiam,
Arie
--
Always go along with the group, or someone may drop a sixteen-ton safe on
you.
- The Buddy Bears
More information about the Haskell-Cafe
mailing list