Hey folks - I'm trying to use the record builder syntax but I think there is something outdated between builtin docs and the tutorial.
Ref:
https://www.roc-lang.org/tutorial#record-builder
https://www.roc-lang.org/builtins/Task#batch
How would I use the record builder syntax these days with a Task?
My code as example using the basic-webserver@0.10 platform:
{ Task.ok <-
a: Env.var "A",
b: Env.var "B"
}
Oh, sorry, that's out of date yes
Record builders used to be built with applicative functors
Which was a complex tool for beginners to grok
So now we just accept any function that takes two things and combines them
So Task.batch
is for the old style, and we don't have a function for the new style
Oh wow! Yeah - I was still under the impression it was related to applicatives.
The tutorial needs some love
combineTasks : Task a err, Task b err, (a, b -> c) -> Task c err
combineTasks = \leftTask, rightTask, combiner ->
left = leftTask!
right = rightTask!
Task.ok (combiner left right)
This function should be a userspace record builder combiner
With Purity Inference, you shouldn't really need this
But you could do this:
combine! : ({} => Result a err), ({} => Result b err), (a, b -> c) => Result c err
combine! = \leftGen, rightGen, combiner ->
left = try leftGen! {}
right = try rightGen! {}
Ok (combiner left right)
Why does it need to be a userspace function? Shouldn't it be part of the Task
module?
It should, but Task is going the way of the dodo pretty soon
Maybe I'm misinterpreting what userspace means :grinning_face_with_smiling_eyes:
I guess I could add that just as a stopgap
Ohhh right - with the purity inference thing
Not sure what the right name is.
What would you prefer?
combine
makes sense to me! I like that it seems like a reusable name for the pattern to be used in different modules.
I'll make a PR, then
@Georges Boris could you look at https://github.com/roc-lang/roc/pull/7413 if you get a chance and tell me if the docs make sense to you?
It's pretty simple
Looks good to me!
I wonder if it wouldn't be better to remove the previous batch
example as a whole since that code doesn't compile anymore.
Yeah, probably the right move
done
Last updated: Jul 05 2025 at 12:14 UTC