Stream: beginners

Topic: Effectful higher-order functions


view this post on Zulip misterdrgn (Jan 31 2025 at 12:43):

I hadn’t thought about the fact that higher-order functions must have a different name if they take an effectful function than if they don’t, since effectful functions have different type signatures. Given this, will there be effectful versions of all higher-order functions in the builtins?

For example, the current builtins documentation has a List.walk! but not a List.map!, even though the example code for List.walk! would be simpler as List.map!.

view this post on Zulip Anton (Jan 31 2025 at 12:51):

will there be effectful versions of all higher-order functions in the builtins?

I think the plan was to provide effectful versions on an as needed basis. We've talked about List.map! before, let me see if I can find that.

view this post on Zulip Anton (Jan 31 2025 at 12:53):

#contributing > More standard library purity inference @ 💬

view this post on Zulip misterdrgn (Jan 31 2025 at 12:59):

Alright. Obviously you can always use walk! to achieve what you would do with map!. It’s just a tradeoff between more clutter in the builtins vs slightly more complicated code.

I don’t see anything at that link that talks about whether to have a List.map!, but I take it people concluded walk! and for_each! were enough.

EDIT: Oh I see, List.map! is mentioned earlier.

view this post on Zulip Anton (Jan 31 2025 at 13:02):

It’s just a tradeoff between more clutter in the builtins vs slightly more complicated code.

Yeah, we always prefer "feature" discussion based on specific needs instead of hypothetical needs. List.map! could make sense though!

view this post on Zulip misterdrgn (Jan 31 2025 at 13:05):

I do find it slightly amusing that the documentation for List.walk! itself provides a good use case for List.map!. Of course that might not come up too often in practice.

view this post on Zulip Anton (Jan 31 2025 at 13:08):

Yeah, examples can be artificial because their goal is simply to be a nice demonstration


Last updated: Jul 06 2025 at 12:14 UTC