monads Questions

3

Solved

Say I have a list like: [Nothing, Just 1, Nothing, Just 2] I want to get the first Just (non-error) value; in this case, it's Just 1. The only thing I can think of is: firstJust xs = case filte...
Dinnie asked 4/4, 2016 at 19:13

7

In C++23, given: expected<A, string> getA(const X& x); expected<B, string> getB(const Y& y); C compute_all(const A& a, const B& b); Is there a way to avoid a classic s...
Geophysics asked 11/7 at 9:47

4

Solved

I'm having trouble understanding why the following code correctly compiles: f :: a -> Maybe a f = return Just 3 return Just has a type of Monad m => m (a -> Maybe a) so I'm not sure why p...
Sillabub asked 7/5 at 15:19

6

Solved

I just reinvented some monad, but I'm not sure which. It lets you model steps of a computation, so you can interleave the steps of numerous computations to find which one finishes first. {-# LANGU...
Sexology asked 28/8, 2011 at 20:57

2

What's the simplest yet most elegant way to NOT short-circuit and instead collect errors until their values are used? What's so hard in accumulating errors? Short circuit only if a function call re...
Polytrophic asked 11/3 at 11:55

6

There is a lot of talk about monads these days. I have read a few articles / blog posts, but I can't go far enough with their examples to fully grasp the concept. The reason is that monads are a fu...
Fawnia asked 23/3, 2009 at 19:20

2

Solved

It is known that natural transformations with type signature a -> a must be identity functions. This follows from the Yoneda lemma but can be also derived directly. This question asks for the sa...
Crumble asked 26/4, 2020 at 16:42

2

Solved

The F# 3.0 beta contains a query {} computation expression with tons of new keywords. How can I define my own keywords in a computation builder?
Crist asked 5/3, 2012 at 11:39

2

To practice my Haskell I decided to write a little JSON parser. In the main file I call the different parts of my parser, print the results so I have more information for debugging and then write t...
Halfdan asked 28/12, 2023 at 16:52

4

Solved

Why and how specifically is a Scala Future not a Monad; and would someone please compare it to something that is a Monad, like an Option? The reason I'm asking is Daniel Westheide's The Neophyte's...
Irresolute asked 13/12, 2014 at 2:9

1

Solved

Consider the following datatype: data Foo = Halt | Iter Foo This is the fixpoint of Maybe. It contains the direct limit of the sequence Void, Maybe Void, Maybe (Maybe Void) and so on, where pure i...
Sticktight asked 31/7, 2023 at 2:12

4

Solved

The reader monad is so complex and seems to be useless. In an imperative language like Java or C++, there is no equivalent concept for the reader monad, if I am not mistaken. Can you give me a sim...
Guevara asked 6/1, 2013 at 3:6

1

In Haskell, Given a monad m, there is mfix :: (a -> m a) -> m a that computes the fixed-point of a monadic computation. Dually, given a comonad w, there is cofix :: w (w a -> a) -> a th...
Crist asked 15/3, 2023 at 12:35

3

Solved

After looking up the Control.Monad documentation, I'm confused about this passage: The above laws imply: fmap f xs = xs >>= return . f How do they imply that?
Surgical asked 22/5, 2017 at 5:52

3

In Java you can call peek(x -> println(x)) on a Stream and it will perform the action for each element and return the original stream, unlike foreach which is Unit. Is there something similar in...
Lindbergh asked 8/7, 2016 at 0:43

2

std::transform from the <algorithm> header applies to ranges, and it is what "enables" us to use ranges as the functors they are (in the sense of category theory(¹)). std::transform...
Igloo asked 9/1, 2022 at 9:58

1

I am writing a project that involves composing several stacks of StateT and ReaderT monads: newtype FooT m a = FooT { unFooT :: (StateT State1 (ReaderT Reader1 m)) a } newtype BarT m a = BarT { un...
Volnay asked 27/7, 2022 at 16:50

1

Solved

The codensity monad on a type constructor f is defined by: newtype C f a = C { unC ∷ forall r. (a → f r) → f r } It is well known that C f is a monad for any type constructor f (not necessarily c...

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

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

5

Solved

From categorical point of view, functor is pair of two maps (one between objects and another between arrows of categories), following some axioms. I have assumed, what every Functor instance is si...
Stipulation asked 8/2, 2014 at 15:12

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...

3

Solved

I'm relatively new to studying functional programming and things were going well until I had to treat errors and promises. Trying to do it in the “right” way I get a lot of references for Monads as...
Beatific asked 15/9, 2022 at 21:48

2

Solved

I was kinda surprised when I read the source code of instances of Applicative Complex and Monad Complex from GHC Data.Complex module: -- | @since 4.9.0.0 instance Applicative Complex where pure a...
Stclair asked 8/11, 2017 at 13:32

© 2022 - 2024 — McMap. All rights reserved.