Stream: beginners

Topic: Reader


view this post on Zulip drew (May 20 2023 at 21:14):

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.

view this post on Zulip Luke Boswell (May 20 2023 at 23:13):

I'm not familiar with Reader but I wonder if importing files as Str would help you here?

view this post on Zulip Brendan Hansknecht (May 21 2023 at 00:01):

I don't think they are related at all.

view this post on Zulip Brendan Hansknecht (May 21 2023 at 00:01):

Reader is a monad pattern for piping constant data around

view this post on Zulip Brendan Hansknecht (May 21 2023 at 00:02):

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.

view this post on Zulip Georges Boris (May 21 2023 at 02:12):

Would injecting values through the platform and/or through code generation suffice?

view this post on Zulip Richard Feldman (May 21 2023 at 10:07):

not currently, but I'm partway through writing up a proposal that happens to cover similar use cases to Reader

view this post on Zulip Richard Feldman (May 21 2023 at 13:06):

at least in terms of this:

something to "inject" values in my programs once they're larger than a trivial size

view this post on Zulip drew (May 21 2023 at 13:15):

great! it's not Reader i care about, specifically, but this "lightweight injection" is soooo hard to give up in real purely-functional programs

view this post on Zulip Richard Feldman (May 21 2023 at 13:17):

what are some of the things you inject in this way?

view this post on Zulip drew (May 21 2023 at 13:17):

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.

view this post on Zulip drew (May 21 2023 at 13:18):

@Richard Feldman generally program-wide configuration. I'll have an effectful "setup" phase and then outputs of this are passed around.

view this post on Zulip Richard Feldman (May 21 2023 at 13:18):

yeah I'm just wondering specifically what types of configuration

view this post on Zulip drew (May 21 2023 at 13:19):

things like db connections on the back end, or "setters" to avoid prop-drilling on the front end

view this post on Zulip drew (May 21 2023 at 13:19):

(this is in haskell on the back end and purescript on the front end)

view this post on Zulip drew (May 21 2023 at 13:20):

one sec, looking at my front end source

view this post on Zulip drew (May 21 2023 at 13:21):

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

view this post on Zulip drew (May 21 2023 at 13:21):

so any component can create a push-state link

view this post on Zulip drew (May 21 2023 at 13:23):

(btw, really enjoying your podcast! also i'm friends with the some of the RWX folks, super excited they're supporting your work)

view this post on Zulip Richard Feldman (May 21 2023 at 15:19):

thanks! :smiley:

view this post on Zulip Richard Feldman (May 21 2023 at 17:50):

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/

view this post on Zulip Agus Zubiaga (May 21 2023 at 17:59):

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.

view this post on Zulip drew (May 21 2023 at 19:35):

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.

view this post on Zulip Pit Capitain (May 22 2023 at 19:41):

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.)

view this post on Zulip Agus Zubiaga (May 22 2023 at 19:43):

That's good a point. It's technically possible, just more explicit.


Last updated: Jul 05 2025 at 12:14 UTC