[web-devel] GGHandler and MonadPeelIO

Michael Snoyman michael at snoyman.com
Fri Apr 8 15:46:02 CEST 2011


Well, regarding:

   type DB = SqlPersist Handler

Assuming the definition of Handler is something like:

   type Handler = GHandler MyApp My App

The definition of GHandler is:

   type GHandler sub master = GGHandler sub master (Iteratee ByteString IO)
-- or something like that

So you've defined that a database action wraps around an Iteratee. As the
text below states, an Iteratee cannot have an instance of MonadPoolIO, and
therefore you can't perform Persistent actions against it. Therefore, you'll
never be able to do anything. So instead, we need the inner monad for DB to
be something with a MonadPoolIO instance, such as:

    type DB = SqlPersist (GGHandler MyApp MyApp IO)

The only problem is that after running a DB action, you'll be left with a
GGHandler wrapping around IO, but Yesod expects a GGHandler wrapping around
Iteratee. Therefore, you need to call liftIOHandler, which has a type of
something like:

    liftIOHandler :: MonadIO m => GGHandler sub master IO a -> GGHandler sub
master m a

HTH,
Michael

On Fri, Apr 8, 2011 at 2:53 PM, Aur Saraf <sonoflilit at gmail.com> wrote:

> Hello,
>
> ----------------->>>>>>>>>><<<<<<<<<--------------------
>
> runDB: need liftIOHandler
>
> ⁋For the impatient: stick liftIOHandler at the beginning of runDB like
> so: runDB db = liftIOHandler $ fmap connPool getYesod >>=
> Settings.runConnectionPool dbNo comments
> Add a commentName:
>
> ⁋For everyone else: WAI 0.2 contained the request body as an
> Enumerator in the Request datatype, and an Application was Request ->
> IO Response. In WAI 0.3, an Application is Request -> Iteratee
> ByteString IO Response. Long story short: all code in your Handler
> function now lives on top of an Iteratee monad so that it can access
> the request body.No comments
> Add a commentName:
>
> ⁋This works great most of the time. The only downside is when you need
> to deal with exceptions. It's impossible to define a MonadPeelIO
> instance for Iteratee. Therefore, in Yesod 0.7, we have a new datatype
> called GGHandler, which is just a generalization of GHandler to allow
> an arbitrary inner monad.No comments
> Add a commentName:
>
> ⁋GHandler defaults to having an Iteratee on the inside. But when you
> need a MonadPeelIO (like we do in Persistent), you need to have an IO
> on the inside. Eventually though, you'll need to convert your
> GGHandler IO to a GHandler. That's what liftIOHandler does.No comments
>
> ----------------->>>>>>>>>><<<<<<<<<--------------------
>
>
> Could anyone please explain this better, and what it means to someone
> upgrading an application?
>
> Specifically, what happens to:
>
>    -- | A useful synonym; most of the DB handler functions are of this type
>    type DB = SqlPersist Handler
>
> ?
>
>
> Thanks :-),
>  Aur
>
> _______________________________________________
> web-devel mailing list
> web-devel at haskell.org
> http://www.haskell.org/mailman/listinfo/web-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/web-devel/attachments/20110408/48926484/attachment.htm>


More information about the web-devel mailing list