nick8325 / quickcheck

Automatic testing of Haskell programs.
Other
713 stars 119 forks source link

Semigroup Gen instance #321

Open yaitskov opened 3 years ago

yaitskov commented 3 years ago

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 commented 3 years ago

wow! the ticket launches missiles 321 ;)

MaximilianAlgehed commented 5 months ago

... 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 (<>).