A monad in programming is a composable computation description. Monads are an important construct in functional programming languages like Haskell.

learn more… | top users | synonyms

3
votes
1answer
82 views

Simple/Naive Implementation of Identity and Maybe Monad in Elixir

This is my first crack at a identity monad and a maybe monad in Elixir. Please be gentle, guys. ...
5
votes
1answer
41 views

Type Validation using State Monad

I am attempting to build a compiler for a stack-based (or concatenative) programming language in Haskell. I've done fine getting the lexer and parser up and running, but now that I'm into the meat of ...
5
votes
2answers
63 views

Applicative permutation to generate knight moves

I want to understand Haskell better by trying to stretch possibilities of Functor, Applicative, and Monad as much as possible and study how they behave. So in Learn You a Haskell there's an exercise ...
8
votes
1answer
166 views

Functional Programming Library

I have started putting together a functional programming library in C# which is somewhat inspired by scalaz and the book Functional Programming in Scala. I am hoping to get some feedback on the Monad ...
5
votes
1answer
32 views

Safe stack operations with lens

I wrote this code to learn how to work with State monad. Then I added Either result to gracefully handle error condition (stack underflow). I believe most of this code is actually unnecessary. I know ...
2
votes
1answer
59 views

Polymorphic components for graphics and program state

I asked this question on StackOverflow, got some answers, most notably a link to this one, and basing on that I've implemented this: ...
5
votes
2answers
54 views

Checking in four directions for board game win

I have the following code which I would like to simplify in Haskell, although I'm not sure how. I recall that I can use monads to simplify a case chain when the result of the case leads onto a next ...
2
votes
1answer
23 views

Haskell: downpair :: (Monad m) => m (a, b) -> (m a, m b) implementation

I'm trying to implement function downpairs which takes monad of pairs and transform it into pair of monad My current implementation is ...
5
votes
1answer
70 views

Popping from a list in state while a condition is true

I'm dealing with data that stores its state as a String, treating the string like a stack. I also have to combine that with error handling. To that end, I'm using ...
1
vote
2answers
119 views

Haskell monads: sum of primes

They say you cannot get out of the monad, but I need to use the result (at least for assertions / unit tests). But print how does it do it? Otherwise, I worked ...
7
votes
2answers
65 views

Random numbers, IO monad, and pure code

To get used to Haskell, I wrote a little program using the Diagrams package which generates 100 random dots (larger dots are more likely to be in the center). ...
2
votes
0answers
34 views

Expressing computations on values as State

I was writing an application with a few Monads in a transformer stack. The top level application state resides in a TVar, and various components of the application ...
3
votes
2answers
56 views

Haskell monad- and error-handling-style

As an answer to excersise 2.3 in Chris Okasaki's book, Purely Functional Data Structures, Inserting an existing element into a binary search tree copies the entire search path even though the ...
2
votes
0answers
31 views

Abstract Key Value Store

I'm attempting to define an abstract interface for a key value store. Some requirements: Once a key has been written it should never be overwritten (although it may be deleted Transactions with ...
2
votes
0answers
187 views

I just released a TypeScript library to help write better conditional statements

http://jumpkick-studios.github.io/Is/ I was attempting to understand the "Maybe Monad" concept, and I found it really fascinating. However all of the implementations ended up looking just as weird ...
5
votes
0answers
172 views

Binary Search Tree Monad Implementation

I've written a Binary Search Tree Monad in Scala. I would like to hear your thoughts on how to improve it (e.g. making insertion/deletion/search faster and more scalable). Also, is there a better way ...
2
votes
1answer
49 views

v2 - Adding a duplicate entry randomly into a list in haskell using random monad

Next version of Adding a duplicate entry randomly into a list in haskell using random monad I wrote this trying to set up a Haskell testcase. The aim is to take a list and add a single duplicate from ...
4
votes
1answer
27 views

Adding a duplicate entry randomly into a list in haskell using random monad

There's a new version of this as v2 - Adding a duplicate entry randomly into a list in haskell using random monad I wrote this trying to set up a Haskell testcase. The aim is to take a list and add ...
10
votes
1answer
153 views

Probably unneeded returns

This is my first "useful" Haskell program. It's invoked with filenames as arguments where the last filename is the destination to which the content of all other files will be concatenated. As far as I ...
7
votes
2answers
997 views

An Either Monad in Java

Interested in a review of this code, in particular the (hopefully monadic) bind. I actually put this to good use. It was a nice complement to Guava's Optional, and shorter than: ...
7
votes
1answer
132 views

Monadic Immutable Linked List in the Least Functional Language Evar

I've written a List monad as an example for a related question. This is a rather frustrating experience as I wanted to use Java, which (as of Java 7) still lacks lambda expressions and lacks ...
6
votes
2answers
164 views

A monad in Java (FriendSpace and People)

After asking a similar question on Stack Overflow, I'm picking up on the answer there to improve my monad. I'm not trying to solve the general case, just come up with one to see how it works. If I'm ...
2
votes
1answer
151 views

Is this a reasonable Scala monad?

I found myself writing code of the form... ...
4
votes
0answers
704 views

Performance of List representation of MonadPlus versus Tree representation

I am working on a code where I represent a MonadPlus using a Tree data structure and then explore it, summing over all of the ...
1
vote
0answers
265 views

Scalaz state monad exercise

I can't tag this with scalaz and state-monad yet since I don't have sufficient reputation to add tags. Below is a self imposed exercise and solution to learn Scalaz state monad. How can I ...
3
votes
2answers
852 views

C# state monad implementation

I want to know whether this thing I wrote in C# is a correct implementation of the state monad. I've used it in code and it does what I expect it to do, but I'm still not quite sure if I'm doing this ...
22
votes
1answer
773 views

How can I make my stack monad faster?

I made a stack monad that lets one manipulate and control values on a stack. I want to know if it's correct (it seems correct), how to make it faster, and how I could detect stack overflows without ...
19
votes
0answers
1k views

Finding minimum scalar product using ST Monad

Inspired by a Stack Overflow question, I decided to practice my Haskell by taking a crack at the Google Code Jam's Minimum Scalar Product problem: Given two vectors ...
16
votes
1answer
3k views

Java monad implementation

I'm learning functional programming and their concept of Monads. I've found nothing more effective in learning than writing an implementation in a programming language I have experience with. I came ...