monad-transformers

How do I combine monads in Haskell?

Particularly, I need to be able to combine the CGI monad with the IO monad, but an example of how to combine the IO monad with the Maybe monad might be even better... ...

awkward monad transformer stack

Solving a problem from Google Code Jam (2009.1A.A: "Multi-base happiness") I came up with an awkward (code-wise) solution, and I'm interested in how it could be improved. The problem description, shortly, is: Find the smallest number bigger than 1 for which iteratively calculating the sum of squares of digits reaches 1, for all bases fr...

Haskell Monad Transformer Stack and Type Signatures

I am attempting to create a stack of monad transformers and am having trouble getting the correct type signatures for my functions. (I'm still pretty new to Haskell) The stack combines multiple StateT transformers since I have multiple states I need to keep track of (two of which could be tupled, but I'll get to that in a second) and a ...

monad tranformers and stacking of multiple monads

I have a f function with signature f :: [a] -> StateT Int Reader b [c], and f' with signature f' :: a -> StateT Int Reader b [c] The computation in f (very simplified) looks like that: f [] = return [] f (s:st) = f' s >>= \x -> f st >>= \y -> return $ ... And in place of the ... I would like to return the [c] pa...

Using MonadError with Parsec

I'm trying to use MonadError together with Parsec. I've come up with the following code snippet: f5 = do char 'a' throwError "SomeError" f6 = f5 `catchError` (\e -> unexpected $ "Got the error: " ++ e) ret = runErrorT (runParserT f6 () "stdin" "a") However, ret is Left "SomeError", it seems the catchError doesn't have any ef...

Type error while trying to implement the (>>=) function in order to create a custom monad transformer.

Hello, I'm trying to create a monad transformer for a future project, but unfortunately, my implementation of the Monad typeclasse's (>>=) function doesn't work. First of all, here is the underlying monad's implementation : newtype Runtime a = R { unR :: State EInfo a } deriving (Monad) Here, the implementation of the Monad type...

How can I make a Maybe-Transformer MaybeT into an instance of MonadWriter?

I am trying to build a MaybeT-Transformer Monad, based on the example in the Real World Haskell, Chapter Monad Transformers: data MaybeT m a = MaybeT { runMT :: m (Maybe a) } instance (Monad m) => Monad (MaybeT m) where m >>= f = MaybeT $ do a <- runMT m case a of Just x -> runMT (...

Has anyone ever encountered a Monad Transformer in the wild?

In my area of business - back office IT for a financial institution - it is very common for a software component to carry a global configuration around, to log it's progress, to have some kind of error handling / computation short circuit... Things that can be modelled nicely by Reader-, Writer-, Maybe-monads and the like in Haskell and ...

mtl, transformers, monads-fd, monadLib, and the paradox of choice

Hackage has several packages for monad transformers: mtl: Monad transformer library transformers: Concrete functor and monad transformers monads-fd: Monad classes, using functional dependencies monads-tf: Monad classes, using type families monadLib: A collection of monad transformers. mtl-tf: Monad transformer library using type famili...

Use of type synonyms in monad transformers

Is it possible to use type synonyms as arguments of monad transformers' type constructor? In particular, if there is an unary type synonym for an applied monad transformer, could it be used as a type of the underlying monad in another monad transformer? From what I see type synonyms are not accepted as first-class type constructors, see...

Tips for more elegant code with monads?

Hi. I finally got a hold on how to use monads (don't know if I understand them...), but my code is never very elegant. I guess is from a lack of grip on how all those functions on Control.Monad can really help. So I'd thought it would be nice to ask for tips on this in a particular piece of code using the state monad. The goal of the co...

Why is my code using monadic lists from the List package so slow?

Last week user Masse asked a question about recursively listing files in a directory in Haskell. My first thought was to try using monadic lists from the List package to avoid building the entire list in memory before the printing can start. I implemented this as follows: module Main where import Prelude hiding (filter) import Control...

Haskell: lift vs liftIO

In what situations should liftIO be used? When I'm using ErrorT String IO, the lift function works to lift IO actions into ErrorT, so liftIO seems superfluous. ...