Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Semigroup Gen instance #321

Open
yaitskov opened this issue Nov 19, 2020 · 2 comments
Open

Semigroup Gen instance #321

yaitskov opened this issue Nov 19, 2020 · 2 comments

Comments

@yaitskov
Copy link

Why there is no Semigroup instance for generators?

It must be very useful when building composite values such as url:

genUrl :: Gen Text
genUrl = elements ["http", "https"] <> pure "://" <> elements ["ya.ru", "google.pl"]
@yaitskov
Copy link
Author

wow! the ticket launches missiles 321 ;)

@MaximilianAlgehed
Copy link
Collaborator

... which semigroup instance do you want?

I can imagine at least two, g <> g' = oneof [g, g'] and g <> g' = (<>) <$> g <*> g'. Either way some people will expect one and other people will expect the other.

You might argue that the first would create poor distrubtions and wouldn't be law abiding (that is very much true) and therefore the other one is the only reasonable choice (TM). However, don't forget that a user might not be familiar enough with the internals of Gen not to shoot themselves in the foot because they are simply wrong about how distributions interact with (<>).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants