[Haskell-beginners] ListT + Writer

Francesco Ariis fa-ml at ariis.it
Thu May 25 15:43:49 UTC 2017


On Thu, May 25, 2017 at 06:10:27PM +0300, Baa wrote:
>   fn :: [a] -> [a]
>   fn lst = do
>     el <- lst
>     guard $ condition el
>     ...
>     return $ change el
> 
> How can I do the same but with possibility to call "tell" of "Write"
> monad in the fn's body? As I understand it should be:

Should be as easy as:

    import Control.Monad.List
    import Control.Monad.Writer

    type Prova = ListT (Writer String) Int

    fn :: Prova -> Prova
    fn lst = do el <- lst
                guard (rem el 2 == 0)
                lift $ tell "hey bby"
                return (el + 1)


More information about the Beginners mailing list