Questions tagged [monads]
A monad in programming is a composable computation description. Monads are an important construct in functional programming languages like Haskell.
75 questions
5votes
1answer
925views
Monad object in C++
Have I defined a Monad object for C++? Below is a class called var which I created years ago to implement a lambda calculus like interpreter in C++. The class ...
5votes
1answer
158views
Ackermann-Péter function call count using Writer monad
I'm quite new to Monads and I tried add function call counting to the Ackermann function code. The goal was simplicity, not performance. I want to have code review on the ...
5votes
1answer
177views
Composite expected in C++
I'm interested in creating a successor to the expected monad in C++. Specifically I want it to be capable of storing error which may has one of many types, and a ...
1vote
1answer
147views
Hangman game in Haskell, written using a state monad
I recently made a simple hangman game in Haskell but soon wanted to explore the state monad, since it could possibly simplify the code. The result was this (see below), which is exactly 30% more lines ...
6votes
2answers
2kviews
Hamming distance between two strings
I wrote this module to find the Hamming distance between two strings. (It's a problem from exercism.io's Haskell track.) As I saw it, the problem has two distinct ...
7votes
1answer
422views
A beginner's brainfuck interpreter in Haskell
I am rather new to haskell, and could use some feedback on my code and the decisions I had to make. In my previous project, I made a JSON parser, but relied heavily on guidance from a university ...
3votes
1answer
96views
Haskell - saving content of HTTP request in selected file
As a Haskell beginner I'm currently playing around the IO monad and prepared simple program which gets from the user two information: URL (http) Output file path Then it performs ...
1vote
2answers
1kviews
Either monad in C++11
I'm using C++11 with https://github.com/SmingHub/Sming. It has no support of std lib or exceptions. I wanted to use Either monad ...
11votes
1answer
495views
Telegram bot in Haskell using custom monad transformers
Note: I show almost all of my code for completeness, but I really only want the review to focus on Session.hs, Handler.hs, and maybe Controller.hs. I can delete the extra code from the review or ...
2votes
1answer
755views
How can I use the State monad effectively in Haskell?
I have written a simple fibonacci function in Haskell that uses the State monad to save solutions to overlapping sub-problems. Now despite the function working I am not really happy with the solution, ...
4votes
1answer
547views
Loading Files from a Directory in Haskell
I'm a very new Haskell programmer, and I've written the following code for loading TSV files. I think it can be improved, but I'm not sure how. I feel like the giant "do" block in loadData is ...
1vote
1answer
125views
Monad to sample without replacement
I created a monad in Haskell that lets you sample without replacement from user-defined urns, and then at the end gives you a list of all possible outcomes. It looks like it's similar to the list ...
5votes
1answer
173views
Typescript monad for data being loaded
I have been struggling to make typescript happy about the types. I am pulling data from our backend API and I wanted to give context to the data. Basically it is a monad with 4 shapes: Initial (...
6votes
1answer
300views
C++17 Either implementation for error handling [closed]
This is a C++17 Either implementation for error handling. First intent is I want to improve myself. Second intent is I want to create a more expressive solution than variant for exception free error ...
4votes
2answers
152views
Implementation of partitionM
I needed a monadic version of partition today. I settled on the following version: ...