ulid icon indicating copy to clipboard operation
ulid copied to clipboard

Don't use `unsafePerformIO`, and migrate to random-1.2.

Open igrep opened this issue 4 years ago • 5 comments
trafficstars

I think the ULID type shouldn't be an instance of Random (or Uniform since random-1.2) by taking the trouble to use unsafePerfomIO.

The random function should be pure: if the argument g is the same value, the result of random g should be same. Breaking this rule can cause some troubles. For example, we can't reproduce the same value with the same generator (perhaps deserialized from a database). I haven't actually got troubled with such a case, but I think it'll cause some hard-to-find bug some day.

My suggestion is to drop the support for Random instance of ULID, and define the instance Random ULIDRandom instead. That makes the package safely available.

Speaking of the random package, due to the changes in random-1.2, now this package can't be built with the latest random. So how about fixing the problem and supporting random-1.2 at the same time?

igrep avatar Apr 18 '21 10:04 igrep

More details: https://github.com/commercialhaskell/stackage/issues/5474

ad-si avatar Oct 04 '21 10:10 ad-si

Should be fixed with: https://github.com/jimenezrick/ulid/commit/3e0f1f9698f6e2cce88bfb78832da30e06854d54

jimenezrick avatar Jan 31 '22 11:01 jimenezrick

Thanks @jimenezrick. Fixed this in 68e29c3

ad-si avatar Feb 12 '22 16:02 ad-si

@igrep is there some documentation or a blog post where I can read more about this?

ad-si avatar Feb 12 '22 16:02 ad-si

@ad-si I can find only this https://www.reddit.com/r/haskell/comments/hefgxa/ann_random120_a_long_overdue_upgrade/

igrep avatar Feb 12 '22 22:02 igrep