Is there a standard applicative reader instance?

Is there a pre-existing instance that I found in this post?

data Reader r a = Reader (r -> a)
instance Functor (Reader r) where
    fmap f (Reader x) = Reader (f . x)
instance Applicative (Reader r) where
    pure x = Reader $ pure x
    (Reader f) <*> (Reader x) = Reader (f <*> x)

      

+3


source to share


1 answer


Yes. By the time the object itself Applicative

is in scope, the instance for is (->) r

also in scope. (And that should be true for code you wrote even for type checking - have you noticed that an instance Applicative

for is Reader

just sent to an instance Applicative

for (->) r

? =)



+6


source







All Articles