Open ShapeOfMatter opened 1 year ago
Note that there are a few other ways these changes could have been handled:
random
, randomR
, and uniform
and uniformR
. I don't like that because it adds cruft/overhead to all interpretations (and it recapitulates more details from System.Random, which is contrary to the spirit of Polysemy).infiniteSamples :: Sem r (Data.Stream.Stream a)
, but it wasn't clear to me today how to write it without adding something analogous to System.Random.split
to the API, and I wasn't sure we'd want that extra complexity.In the variant of Random
I'm using, I added the type of the random values as an effect parameter, so I'd depend on Random Int64
etc., and I can move the dependency on random
to the interpreter. Any thoughts on that?
In the variant of
Random
I'm using, I added the type of the random values as an effect parameter, so I'd depend onRandom Int64
etc., and I can move the dependency onrandom
to the interpreter. Any thoughts on that?
Interesting... At first I didn't like it but I'm opening to the idea. Where's the variant you use?
:: * -> Constraint
) instead of a specific type? I'm unsure if that would be better or not.random
and randomR
into separate effects?Anyway, I think it's a bigger change than I'm proposing in this PR. If other people are enthusiastic about it I can participate in the work, starting with opening a new Issue...
It's pretty banal: https://github.com/tek/polysemy-hasql/blob/main/packages/db/lib/Polysemy/Db/Interpreter/Random.hs
anyway, I just wanted to ask your opinion, you can proceed with this without changing the effect further. I haven't used it enough to have an informed view on the matter.
so, PR looks fine to me!
In the variant of Random I'm using, I added the type of the random values as an effect parameter, so I'd depend on Random Int64 etc., and I can move the dependency on random to the interpreter. Any thoughts on that?
Thinking about it more, I don't think this suggestion is the way forward.
data Random x m a where random :: Random x m x
, then isn't it just an alias for Input? I appreciate the desire to have each thing you want on hand with a relevant name, but I really think there'd be no value to it. Specifically, I think there'd still be demand for something more like the existing Random
with its randomR
function.data Random c m a where random :: (c x) => Random c m x
, that would open up a lot of flexibility! But it still couldn't handle both random
and randomR
.data Random c arg m a where random :: (c x arg) => arg -> Random c arg m x
? The only thing I can think of is to introduce a new "meta" class ("Affords c arg x
"?) to track what constraints imply which arguments... I think most people looking for a Random
effect are going to want something with an off-the-shelf handler to System.Random
and/or Crypto.Random
(which I should add...)
It's awkward using the existing Polysemy.Random, because it maps to the
Random
class, which the current documentation suggests shouldn't be used in new code.This pull request fixes that, and adds relevant unit tests and QOL details.