XMLGen really only needs Applicative?

2 views
Skip to first unread message

stepcut

unread,
Jan 27, 2012, 11:46:37 AM1/27/12
to Haskell Server Pages
The XMLGen instance looks like:

> class Monad m => XMLGen m where
> type XML m
> data Child m
> data Attribute m
> genElement :: Name -> [XMLGenT m [Attribute m]] -> [XMLGenT m [Child m]] -> XMLGenT m (XML m)
> genEElement :: Name -> [XMLGenT m [Attribute m]] -> XMLGenT m (XML m)
> genEElement n ats = genElement n ats []
> xmlToChild :: XML m -> Child m
> pcdataToChild :: String -> Child m

And has the (Monad m) constraint. But, shouldn't Applicative be
sufficient? That would make it possible to use trhsx with digestive-
functors..

- jeremy

Niklas Broberg

unread,
Jan 28, 2012, 11:33:45 AM1/28/12
to haskell-se...@googlegroups.com
Hi Jeremy,

I seem to recall that monads really are necessary, and something tells me we've had this discussion before. Right now I can't quite wrap my head around it though.

Here's something that might be a clue:

instance (EmbedAsChild m c, m ~ n) => EmbedAsChild m (XMLGenT n c) where
  asChild m = asChild =<< m

Basically that's 'join' - the hallmark of monads over applicatives. This instance is what makes nested child tags work, and could not be written for a generic Applicative. However, it's not immediately clear that this particular instance couldn't be written once for each data type. We already know it can be written for all monads. Could it be written for the Applicatives you want to use?

Cheers,

/Niklas
Reply all
Reply to author
Forward
0 new messages