Generate UUID - Polysemy

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

Sridhar Ratnakumar

Which builtin effect(s) are recommended for use when generating UUIDs?

TheMatten

@Sridhar Ratnakumar do you have concrete initial seed? If not, you'll probably need source of randomness = IO

Sridhar Ratnakumar

Would it be a bad idea to have a single seed for the entire lifecycle of a backend process when it comes to generating UUIDs (triggered by different app users)?

Sridhar Ratnakumar

So I could just use Input to pass around this seed from main

TheMatten

But if it restarts for some reason, it will start assigning the same UUIDs, won't it?

Sridhar Ratnakumar

I need to update it as well.

Sridhar Ratnakumar

The initial seed will be generated in IO and random.

Sridhar Ratnakumar

Guess I need to track the seed in Polysemy.State

TheMatten

I just wonder whether it makes sense to pass seed around in pure State or whether you could just create mutable var once you're already using IO

Sridhar Ratnakumar

The later is probably better. So Polysemy.Random is out of core?

TheMatten

It's in polysemy-zoo - if you don't mind dependencies, you can use it

Sridhar Ratnakumar

Last time I tried it I had trouble with making deps happy in nix. It is called a zoo after all.

Sridhar Ratnakumar

I suppose I could just create a UUID effect.

Sridhar Ratnakumar

/me looks at https://github.com/polysemy-research/polysemy-zoo/pull/60

GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sridhar Ratnakumar

Well, there is always unsafePerformIO lol

TheMatten

Running nextRandom into IO seems reasonable - you probably have it in your stack somewhere anyway, so I don't think there's any reason to lie about purity :slight_smile:

Sridhar Ratnakumar

Oh yea, I can do IO. But you have to create a whole new GADT with one constructor nextUUID just for this right?

TheMatten

You need new effect if you don't want to use Embed IO directly

Georgi Lyubenov // googleson78

if it's going to be an effect with only one constructor that gives a value you might as well use Input, or am I missing something?