Stream: API design

Topic: Random number generation via Task


view this post on Zulip Richard Feldman (Jan 04 2024 at 16:53):

splitting this off from https://roc.zulipchat.com/#narrow/stream/304641-ideas/topic/.E2.9C.94.20randomness.20in.20Task as a note about an API design idea in the future where we have module params

view this post on Zulip Richard Feldman (Jan 04 2024 at 16:57):

in that world, we can have a randomness package with two modules:

view this post on Zulip Richard Feldman (Jan 04 2024 at 16:58):

this solves the problem of "chaining together a mix of interleaved Gens and Tasks does not work nicely" by giving Gen a way to be wrapped in Task

view this post on Zulip Richard Feldman (Jan 04 2024 at 17:00):

also it means beginners who don't necessarily want to use Gen can just use the Random.u16 convenience functions (which are slower, because they have to go to the OS each time to get randomness, and also they require a Task, and also they are not reproducible using a Seed - all of which are reasons to learn Gen later!) because at first they probably know how tasks work and just want to get a random number or something.

view this post on Zulip Richard Feldman (Jan 04 2024 at 17:00):

cc @Fletch Canny since I saw you mentioned you've been porting a randomness library from Elm!


Last updated: Jul 06 2025 at 12:14 UTC