Questions tagged [monad]

45 questions
102
votes
2 answers

What is the "Free Monad + Interpreter" pattern?

I've seen people talking about Free Monad with Interpreter, particularly in the context of data-access. What is this pattern? When might I want to use it? How does it work, and how would I implement it? I understand (from posts such as this) that…
Benjamin Hodgson
  • 4,488
  • 2
  • 25
  • 34
47
votes
5 answers

Critique of the IO monad being viewed as a state monad operating on the world

The IO monad in Haskell is often explained as a state monad where the state is the world. So a value of type IO a monad is viewed as something like worldState -> (a, worldState). Some time ago I read an article (or a blog/mailing list post) that…
Petr
  • 5,507
  • 3
  • 29
  • 46
40
votes
7 answers

Maybe monad vs exceptions

I wonder what are the advantages of Maybe monad over exceptions? It looks like Maybe is just explicit (and rather space-consuming) way of try..catch syntax. update Please note that I'm intentionally not mentioning Haskell.
30
votes
3 answers

Different ways to see a monad

While learning Haskell I have faced a lot of tutorials trying to explain what are monads and why monads are important in Haskell. Each of them used analogies so it would be easier to catch the meaning. At the end of the day, I have end up with 3…
Oni
  • 927
  • 1
  • 9
  • 13
20
votes
5 answers

Is the benefit of the IO monad pattern for handling side effects purely academic?

Sorry for yet another FP + side effects question, but I couldn't find an existing one which quite answered this for me. My (limited) understanding of functional programming is that state/side effects should be minimised and kept separate from…
Stu Cox
  • 311
  • 2
  • 6
20
votes
2 answers

Are monads a viable (maybe preferable) alternative to inheritance hierarchies?

I'm going to use a language-agnostic description of monads like this, first describing monoids: A monoid is (roughly) a set of functions that take some type as a parameter and return the same type. A monad is (roughly) a set of functions that take…
sea-rob
  • 6,841
  • 1
  • 24
  • 47
19
votes
0 answers

What is a Comonad and how are they useful?

Recently I've been dusting off my knowledge on how Monads work. I've also been introduced to the concept of a 'Comonad', which is described as the inverse dual of a monad. However, I am impossible to wrap my head around it. To understand Monads, I…
Qqwy
  • 4,709
  • 4
  • 31
  • 45
17
votes
4 answers

When programming in Functional style, do you have a single application state that you weave through the application logic?

How do I construct a system that has all of the following: Using pure functions with immutable objects. Only pass into a function data that the function it needs, no more (i.e. no big application state object) Avoid having too many arguments to…
Daisha Lynn
  • 299
  • 1
  • 9
17
votes
1 answer

How does the Free monad and Reactive Extensions correlate?

I come from a C# background, where LINQ evolved into Rx.NET, but always had some interest in FP. After some introduction to monads and some side-projects in F#, I was ready to try and step to the next level. Now, after several talks on the free…
MLProgrammer-CiM
  • 333
  • 2
  • 13
15
votes
4 answers

What programming problems do Monads solve?

I've read a lot of posts that explain what monads are, how unit and bind work, some of them plunging straight into category theory so abstract (for me at least) that makes the eyes bleed, some ignoring that altogether and touching on weird analogies…
Dummy Me
  • 195
  • 3
15
votes
2 answers

Why is the Scala Option type not called Maybe, just as in Haskell?

Why is the Scala Option type not called Maybe, just as in Haskell? Maybe makes a lot more "semantic sense" to me, but maybe Option has different behaviour I am not aware of. Is there any particular reason why Option in Scala was not called Maybe?
fnl
  • 261
  • 2
  • 6
10
votes
6 answers

As a practitioner, why should I care about Haskell? What is a monad and why do I need it?

I just do not get what problem they solve.
Job
  • 6,459
  • 3
  • 32
  • 54
10
votes
1 answer

Futures/Monads vs Events

In an application framework when performance impact can be ignored (10-20 events per second at max), what is more maintainable and flexible to use as a preferred medium for communication between modules - Events or Futures/Promises/Monads? It's…
c69
  • 1,358
  • 1
  • 12
  • 19
9
votes
1 answer

Better to use error monad with validation in your monadic functions, or implement your own monad with validation directly in your bind?

I'm wondering what's better design wise for usability/maintainability, and what's better as far as fitting with the community. Given the data model: type Name = String data Amount = Out | Some | Enough | Plenty deriving (Show, Eq) data Container =…
Jimmy Hoffa
  • 16,039
  • 3
  • 69
  • 80
9
votes
1 answer

What monad is the opposite of the error monad in haskell

In the error monad, the first failure halts any execution further just carrying the fault through any following binds. What monad halts on success only carrying forward successes, and basically swallowing any faults and trying the next bind…
Jimmy Hoffa
  • 16,039
  • 3
  • 69
  • 80
1
2 3