[Haskell-beginners] ListT + Writer

Francesco Ariis fa-ml at ariis.it
Thu May 25 18:44:57 UTC 2017


On Thu, May 25, 2017 at 07:02:58PM +0300, Baa wrote:
>
> В Thu, 25 May 2017 17:43:49 +0200
> > Should be as easy as:
> > 
> >     import Control.Monad.List
> >     import Control.Monad.Writer
> > 
> >     type Prova = ListT (Writer String) Int
> 
> Yes! And this is the source of my questions.. 1) How to call it? 2)
> What does mean to provide argument of type ".. Writer .."? As result,
> it's good: you can run it with "runWriter", but what is "writer" in
> input argument? Fake writer (which is ignoring)?

I am not sure for question #1. If we look at the constructor of ListT
(`runListT :: m [a]`) and MonadWriter (`(a, w)`) and we compose the two
we get:

    ([a], w)
    -- or ([Integer], String) in our example
    -- e.g. ListT (writer ([1,2], "ciao")) <-- to construct

No idea what is the correct name of this critter.

As we can see by running it, the argument in `fn` (both the list part and
the string part) is not ignored:

    λ> fn $ ListT (writer ([1,2], "ciao"))
    ListT (WriterT (Identity ([3],"ciaohey baby")))

Does this answer your questions?


More information about the Beginners mailing list