[Haskell-cafe] Lifting Writer to ListT

Arjun Comar nrujac at gmail.com
Tue Mar 3 16:22:49 UTC 2015


You might prefer using the ListT
<https://hackage.haskell.org/package/pipes-4.1.4/docs/Pipes.html#g:5>
implementation from the Pipes package which has instances for MonadReader,
MonadWriter, and MonadState already. Also, the provided source might give
you some insight into how to write these instances for the list-t:ListT
type.

On Tue, Mar 3, 2015 at 6:03 AM, Nicola Gigante <nicola.gigante at gmail.com>
wrote:

> Hi all,
>
> Suppose I have this monad stack:
>
> type MyMonad = ListT (Writer W)
>
> Where ListT is done right (from the list-t package).
> What I want is a nondeterministic computation where each
> alternative logs to the same writer, and indeed the type of
>
> runWriter . toList
>
> is MyMonad a -> ([a], w)
>
> so I think I got it right.
>
> What I would like to do is to write an instance of MonadWriter
> for this monad, but I'm stuck with the implementation of listen.
>
> Just using lift won't work, and indeed I see that MonadWriter
> lifting instances for other monads (e.g MaybeT), are a bit convoluted.
>
> Could someone explain me a little bit what should I do (what
> listen should do in a ListT in the first place)
>
> Thank you :)
> Nicola
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150303/f259faac/attachment.html>


More information about the Haskell-Cafe mailing list