Does roc
have something like Reader
in haskell? I find I almost always want something to "inject" values in my programs once they're larger than a trivial size. It would be a tough one to give up.
I'm not familiar with Reader
but I wonder if importing files as Str would help you here?
I don't think they are related at all.
Reader is a monad pattern for piping constant data around
I don't know it well enough to be confident to comment. Not sure if it requires higher kinded types or not. I think it or something similar should be doable in roc, but we definitely don't have it in the standard.
Would injecting values through the platform and/or through code generation suffice?
not currently, but I'm partway through writing up a proposal that happens to cover similar use cases to Reader
at least in terms of this:
something to "inject" values in my programs once they're larger than a trivial size
great! it's not Reader
i care about, specifically, but this "lightweight injection" is soooo hard to give up in real purely-functional programs
what are some of the things you inject in this way?
Considering that Reader
can be implemented on functions and that we have backpassing, i'm guessing there's some way to make it "just work", but I haven't tried.
@Richard Feldman generally program-wide configuration. I'll have an effectful "setup" phase and then outputs of this are passed around.
yeah I'm just wondering specifically what types of configuration
things like db connections on the back end, or "setters" to avoid prop-drilling on the front end
(this is in haskell on the back end and purescript on the front end)
one sec, looking at my front end source
so, as a simple example, on drewolson.org (which is just my little playground for experimenting with the front end), i include the initial path and the push-state navigation handle in the environment
so any component can create a push-state link
(btw, really enjoying your podcast! also i'm friends with the some of the RWX folks, super excited they're supporting your work)
thanks! :smiley:
Brendan Hansknecht said:
Not sure if it requires higher kinded types or not.
it doesn't have to: https://package.elm-lang.org/packages/Punie/elm-reader/latest/
Yeah, I think you can translate any Haskell monad to a Roc type + functions. What you can't have is Monad Transformers, as they do require HKTs.
You would want the ability to interleave effects in Reader
, but I guess you get that for free given that effects are handled by the platform, right? Maybe Reader
is actually an ability but also I know nothing about Roc abilities at this point.
Agus Zubiaga said:
What you can't have is Monad Transformers, as they do require HKTs.
I implemented ReaderT
and other monad transformers in Elm (in order to experiment with some Haskell code samples). It works, but you have to pass the specific monad functions as parameters, though. (For example, you have to pass the monad's pure
function to the ReaderT
asks
function.)
That's good a point. It's technically possible, just more explicit.
Last updated: Jul 05 2025 at 12:14 UTC