Questions tagged [reader-monad]
75 questions
2
votes
0 answers
Scotty and the Reader Monad
I'm trying to bring the Reader monad in my Scotty application, as a means of having a unified root path for URL expansion internally. I can't seem to wrap my head around how Scotty handles monad transformation - normally, I would just see something…

Athan Clark
- 3,886
- 2
- 21
- 39
2
votes
1 answer
Using the Reader monad with QuickCheck / monadicIO
I'd like to pass an integer as a CLI argument to a Haskell program that makes use of QuickCheck / monadicIO. That integer is going to be used inside the assert to make the tests customizable.
The problem is that once I parse the integer value in…

Toshio
- 133
- 8
2
votes
2 answers
What is the difference between the reader monad and a partial function in Clojure?
Leonardo Borges has put together a fantastic presentation on Monads in Clojure. In it he describes the reader monad in Clojure using the following code:
;; Reader Monad
(def reader-m
{:return (fn [a]
(fn [_] a))
:bind (fn [m k]
…

hawkeye
- 34,745
- 30
- 150
- 304
1
vote
1 answer
A Reader monad for multiple arguments?
Is there an equivalent to the Reader monad that's equivalent to a -> b -> c rather than just a -> b. I know I could do (a, b) -> c but I'm not sure that's going to be very ergonomic.

joel
- 6,359
- 2
- 30
- 55
1
vote
1 answer
Could not deduce MonadReader in ReaderT wrapping
Following and adapting this blog post, I've been trying to produce a solution which should allow testing of a function which reads env vars (using System.Environment.lookupEnv).
That way, I should be able to inject an artificial environment for…

notquiteamonad
- 1,159
- 2
- 12
- 28
1
vote
1 answer
How to write stateful dbus methods in haskell?
I'm working with dbus in haskell, and I'm having difficulties figuring out how to export dbus methods that perform stateful operations. Below is a fully fleshed out example to illustrate where I'm stuck.
Let's say you're writing a counter service…

MyriaCore
- 13
- 2
1
vote
1 answer
Scala cannot infer parameter type in Reader monad implementation
I am using Scala 2.13, and I am developing the Reader monad my own. The implementation of the monad is the following.
object ReaderMonad {
implicit def reader[From, To](f: From => To): Reader[From, To] = Reader(f)
case class Reader[From,…

riccardo.cardin
- 7,971
- 5
- 57
- 106
1
vote
1 answer
How do I run this method with MonadReader and MonadIO?
I am following this post about the reader monad in Haskell.
It starts with the definition:
load :: Config -> String -> IO String
load config x -> readFile (config ++ x)
Where Config is a type alias for String and it represents a directory name.
The…

Marco Faustinelli
- 3,734
- 5
- 30
- 49
1
vote
1 answer
For comprehension not composing steps fully in unit test using Reader
I have a tagless final implementation with unit test, when I run the unit test only the first step is invoked not the rest.
Here is the test target:
class NameThing[F[_]: Monad](implicit console: Console[F]) {
def program: F[Unit] = for {
_…

jakstack
- 2,143
- 3
- 20
- 37
1
vote
1 answer
How to use scalaz.Reader from Java
I have a service, written in Scala, that uses scalaz.Reader for DI and a test for it.
In the test the op function is defined, to compose functions of the service.
import scala.util.{Failure, Success, Try}
import scalaz.{Reader =>…

Alexandr
- 9,213
- 12
- 62
- 102
1
vote
1 answer
How to map Result<'a,'b> to Reader in f#?
I have the function to map a function to "Reader-Result", where f is 'a->'b:
('a->'b) -> Reader> -> Reader>
let map f = Reader.map <| Result.map f
But how to I write a similar map that takes the function…

Dan Rino Lauritzen
- 392
- 2
- 8
1
vote
0 answers
Differing Reader Behaviour
I'm writing a wrapper around a Warp server where users can specify routes and handlers to make a web server. I decided to try using Continuation Monads to allow handlers to exit using a continuation when a route matches.
Here are the types and…

Chris Penner
- 1,881
- 11
- 15
1
vote
1 answer
How to build a custom reader monad along with a custom typeclass?
I'm trying to marry the approach given at http://lexi-lambda.github.io/blog/2016/06/12/four-months-with-haskell/ (section titled "Typeclasses can emulate effects") with some sort of homegrown reader monad.
The overall problem I'm trying to solve is…

Saurabh Nanda
- 6,373
- 5
- 31
- 60
1
vote
1 answer
What does the map and flat map operations mean for a ReaderMonad
I am a scala newbie. I come from a background of Java. I have been reading up on monads and have formed a general idea about it. While i can appreciate the map and flatMap operations on types such as List i cannot wrap my head around what they mean…

Som Bhattacharyya
- 3,972
- 35
- 54
1
vote
1 answer
Composing Kleisli and Reader monad in Scala
Suppose I have functions like this:
val fooXAB: X => A => Try[B] = ...
val fooXBC: X => B => Try[C] = ...
val fooXCD: X => C => Try[D] = ...
I'd like to compose them to make a new function fooXAD: X => A => Try[D], which calls fooXAB, fooXBC, and…

Michael
- 41,026
- 70
- 193
- 341