Questions tagged [reader-monad]
75 questions
1
vote
1 answer
How do I leverage the MonadReader instance of Free?
I want to use Reader in my DSL that I created using a Free monad.
I notice that there is a instance of MonadReader for Free here:
https://hackage.haskell.org/package/free-4.12.1/docs/src/Control-Monad-Free.html#line-264
If I try to call ask inside…

Joe Hillenbrand
- 845
- 9
- 26
0
votes
1 answer
Reader Monad without explicit call to ask: is it possible?
I'm trying to understand how the Reader monad is used in this blog post as a mechanism to perform functional dependency injection.
The part that confuses me is this bit (taken from the blog post):
Eventually, with this type in hand our simple…

GrumpyRodriguez
- 649
- 5
- 12
0
votes
1 answer
Is there ReaderT raised into a monad?
I've written the following monad transformers (which I believe are equivalent to each other), namely:
newtype MonadReaderT1 r m a = MonadReaderT (ReaderT (r m) m a)
newtype MonadReaderT2 r m a = MonadReaderT (ReaderT (m r) m a)
The purpose of these…

Clinton
- 22,361
- 15
- 67
- 163
0
votes
1 answer
Reader monad inside RxJs mergeMap
I am using rxjs and want to use Reader monad from fp-ts package as a Dependency Injection solution.
Here is my code:
import { of } from 'rxjs';
import { pipe } from 'fp-ts/function';
import { mergeMap } from 'rxjs/operators';
import * as R from…

mohsen saremi
- 685
- 8
- 22
0
votes
3 answers
Readability vs. maintainability: nested functions
What are the pros and cons of each option, considering long-term implications (increasing the number of functions / parameters, other developers taking over, etc.)?
Option 1: removes the need to pass foo and bar to each method, but will create…

Teodor Ciuraru
- 3,417
- 1
- 32
- 39
0
votes
1 answer
How to use mapReader from Control.Monad.Reader for reader monad?
I am trying to figure out that how to use mapReader from Control.Monad.Reader.
For example I have this reader monad
myReaderMonad :: Reader String Int
myReaderMonad = do
string <- ask
return (length string)
I can run it like this
>>> runReader…

Saurabh kukade
- 1,608
- 12
- 23
0
votes
1 answer
Arrow KT: Reader Monad vs @extension for Dependency Injection
I've read about Reader Monad from this article by Jorge Castillo himself and I've also got this article by Paco. It seems that both tackles the idea of Dependency Injection just in a different way. (Or am I wrong?)
I'm really confused whether I…

Archie G. Quiñones
- 11,638
- 18
- 65
- 107
0
votes
3 answers
Testing if a reader monad is called in the wrong environment
I have a MonadReader that generates data for an application I am working on. The main monad here generates the data based on some environment variables. The monad generates the data by selecting one of several other monads to run based on the…

Wheat Wizard
- 3,982
- 14
- 34
0
votes
1 answer
Scala: ReaderT composition with different contexts and dependencies
Example of s3f1 and s3f2 functions that return different ReaderT:
type FailFast[A] = Either[List[String], A]
trait Service1 { def s1f:Option[Int] = Some(10) }
trait Service2 { def s2f:FailFast[Int] = Right(20) }
import cats.instances.option._
def…

Alexandr
- 9,213
- 12
- 62
- 102
0
votes
1 answer
Scala: write for-comprehension with ReaderT and Option
Here is example:
trait Service1 { def s1f = Option(10) }
trait Service2 {
type ReaderS1[A] = ReaderT[Option,Service1,A]
def s2f1: ReaderS1[Int] =
ReaderT(s1 =>
for {
r1 <- Option(1)
r2 <- s1.s1f
} yield r1 + r2
…

Alexandr
- 9,213
- 12
- 62
- 102
0
votes
1 answer
Scala-cats, compose Reader with ReaderT
Here is a small composition of functions, all of which return ReaderT:
type FailFast[A] = Either[List[String], A]
def f1:ReaderT[FailFast, Map[String,String], Boolean] = ReaderT(_ => Right(true))
def f2:ReaderT[FailFast, Map[String,String],…

Alexandr
- 9,213
- 12
- 62
- 102
0
votes
1 answer
Modify ST dependent environment in ReaderT – problem with `local` function
This question is a sequel of this thread: https://stackoverflow.com/a/54317095/4400060
I was asking there about carrying STRef in ReaderT's environment and performing ST-actions under it. My setup now looks like:
import Data.HashTable.ST.Cuckoo as…

radrow
- 6,419
- 4
- 26
- 53
0
votes
2 answers
Understanding (->) r as instance of Reader
So I'm told (->) r is an instance of the Reader monad, but I can't seem to find any concrete examples of how this is supposed to work. I want to use this without having to explicitly wrap some of my code in a Reader
import…

Electric Coffee
- 11,733
- 9
- 70
- 131
0
votes
2 answers
How to return only the latest result of a function application on an iterator object with monad reader
I translate my problem in this little "oversimplified" example. Objective is to return only the latest computation based on a simple function execution on each element of an iterator object.
val l = List(1,2,3,4).toIterator
def…

reyman64
- 523
- 4
- 34
- 73
-2
votes
1 answer
What does "ask" mean in Haskell and what's the difference of it and "asks" function?
I can't understand how to use the ask function, I know how to use the asks function, but I don't know if they're related.
I was reading the "What I wish I knew when learning Haskell" of Stephen and I found this example:
{-# LANGUAGE…

NrBanMex
- 305
- 2
- 8