monad-transformers Questions

1

Solved

Take the MaybeT monad transformer: newtype MaybeT m a = MaybeT { runMaybeT :: m (Maybe a) } I wouldn't have expected a different definition for it, because Maybe is just kind of a box with a (opti...

3

Solved

C++23 adds some "monadic-style" functionality regarding optionals, as methods of optional<T>: optional<T>::and_then() (and ignoring qualifiers of this): template<class F&g...
Exigible asked 26/11, 2022 at 9:30

1

Here's a class, I'm calling BlahMap: class BlahMap t where blahMap :: (m a -> n b) -> t m a -> t n b This is an instance of BlahMap: instance BlahMap (ReaderT r) where blahMap f = Reade...
Ledbetter asked 13/10, 2022 at 3:11

3

Solved

There have been a couple of questions (e.g. this and this) asking whether every monad in Haskell (other than IO) has a corresponding monad transformer. Now I would like to ask a complementary quest...
Elaterite asked 3/6, 2022 at 13:48

3

Solved

In many cases, it isn't clear to me what is to be gained by combining two monads with a transformer rather than using two separate monads. Obviously, using two separate monads is a hassle and can i...
Tannenberg asked 2/8, 2016 at 0:45

1

The haskell transformers library provides MonadIO class and liftIO to lift IO operations in a monad transformer stack. It seems to me that the same could be done for the ST monad, but I couldn't fi...

1

Solved

I am trying to write some Scala code to have custom behaviour in an mtl style. For example, in order to expose the "write to DB" functionality abstracting over the specific effect I wrote...
Generalissimo asked 27/5, 2022 at 14:40

2

A servant-server Handler is a newtype wrapper over an ExceptT, and has instances for MonadThrow, MonadCatch, MonadError, etc. This might be a somewhat contrived example, but it shows an issue I of...
Trainor asked 28/3, 2018 at 6:43

3

Solved

Let's say I have this (arguably mislead) piece of code laying around: import System.Environment (getArgs) import Control.Monad.Except parseArgs :: ExceptT String IO User parseArgs = do args &lt...
Conn asked 4/1, 2016 at 9:55

4

Solved

I am trying to use OptionT to combine methods returning Future[Option[T]] in a for-comprehension. import cats.data._ import cats.implicits._ import cats.instances.future._ for { data <- Opti...
Encircle asked 13/4, 2017 at 9:29

7

Solved

Applicatives compose, monads don't. What does the above statement mean? And when is one preferable to other?

3

As a math student, the first thing I did when I learned about monads in Haskell was check that they really were monads in the sense I knew about. But then I learned about monad transformers and tho...
Sulky asked 28/7, 2011 at 5:1

1

Solved

In Haskell, here's a monad that combines the State and Maybe monads: type StatefulMaybe a = StateT Int Maybe a This is a computation that can succeed (returning a value) or fail. If it succeeds, i...
Revenge asked 7/4, 2021 at 19:26

1

Solved

I have a datatype defined as data Foo a = Foo a (a -> a) The Foo data constructor has two parameter value and function. I need to write Monad and Monad transform instance for this. I am trying ...
Leonleona asked 14/1, 2021 at 21:6

1

Solved

Consider the following example. newtype TooBig = TooBig Int deriving Show choose :: MonadPlus m => [a] -> m a choose = msum . map return ex1 :: (MonadPlus m, MonadError TooBig m) => m In...
Willodeanwilloughby asked 6/1, 2021 at 5:19

1

Solved

Note, this question is not about "monoids in the category of endofunctors". Nor is it directly about Functors (a Monad is always a Functor, but this question is concerned mainly about mo...
Kareykari asked 14/9, 2020 at 9:55

1

I am wondering if this monad has a standard name in the Haskell ecosystem data Delay a = Wait (Delay a) | Done a deriving (Show, Eq, Functor) instance Monad Delay where return a = Done a (Done ...
Monogamous asked 12/8, 2020 at 13:57

2

Related question - Is it safe to derive MonadThrow, MonadCatch, MonadBaseControl, MonadUnliftIO, etc? - where I had enabled, both - DeriveAnyClass and GeneralizedNewtypeDeriving to get the code to...
Corr asked 25/7, 2019 at 9:34

3

Solved

Working through Haskell textbook chapters on different monads, I repeatedly get lost when the authors jump from explaining the details of bind and the monad laws to actually using monads. Suddenly,...
Jamey asked 15/5, 2020 at 7:49

3

Solved

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.
Raceway asked 13/10, 2010 at 6:21

1

Solved

I am fairly new to Haskell. I am trying to combine the State monad with error propagation by treating Either as a monad. I would like to recurse over an abstract syntax tree (for example, for writi...
Larcher asked 10/3, 2020 at 17:19

2

Solved

I am trying to define a family of state machines with somewhat different kinds of states. In particular, the more "complex" state machines have states which are formed by combining the states of si...
Wira asked 4/12, 2019 at 17:27

1

I'm learning State Monad, and was told it doesn't exist any more, the first question is why Haskell remove it? and when I using import Data.Functor.Identity import Control.Monad.Trans.State type...
Thermoplastic asked 20/10, 2019 at 16:24

3

Solved

Edward Kmett's exceptions library does not provide a MonadMask instance for ExceptT. Ben Gamari once asked about this and then concluded that it was explained by the documentation. This is the clo...
Heracliteanism asked 31/1, 2017 at 20:27

1

According to the cats official document: https://typelevel.org/cats-effect/typeclasses/liftio.html, if we want lift something from IO to other container, you should implement LiftIO trait, but the ...
Illconditioned asked 12/9, 2019 at 0:47

© 2022 - 2024 — McMap. All rights reserved.