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

Generalized formatting of generated values #326

Open
ghost opened this issue Mar 24, 2021 · 3 comments
Open

Generalized formatting of generated values #326

ghost opened this issue Mar 24, 2021 · 3 comments
Milestone

Comments

@ghost
Copy link

ghost commented Mar 24, 2021

Following a quick discussion from #324, this issue is being created to provide generalized formatting for values from a Gen<'a>.

Ideally, we'd change the Gen<'a> type to be a record, and add a formatter field that looks like 'a -> string. To maintain compatibility, this field should have a default value of sprintf "%A". Another function should be exposed to override this default, withFormatter : ('a -> string) -> Gen<'a> -> Gen<'a>.

Any values from a generator that are formatted should use the provided formatter.

@ghost ghost added the enhancement label Mar 24, 2021
@ghost ghost added this to the 0.11.0 milestone Mar 24, 2021
@TysonMN
Copy link
Member

TysonMN commented Mar 24, 2021

Ideally, we'd change the Gen<'a> type to be a record, and add a formatter field that looks like 'a -> string.

I am not convinced that this is the right approach. My first impression is that we should make a change like that to Property<_> or the functions of Property. It is those functions that want to string representation.

How does Haskell-Hedgehog solve this problem?

@ghost
Copy link
Author

ghost commented Mar 31, 2021

Ideally, we'd change the Gen<'a> type to be a record, and add a formatter field that looks like 'a -> string.

I am not convinced that this is the right approach. My first impression is that we should make a change like that to Property<_> or the functions of Property. It is those functions that want to string representation.

Gen would have better knowledge of the 'a being generated, I don't think Property is parameterized on the type being generated. I think of it as "gen can make a thing, and also a string representation of the thing".

How does Haskell-Hedgehog solve this problem?

They probably just use type classes, like Show and don't have this problem at all. The equivalent in .NET would be to override ToString, which we can't do for types we don't control.

@dharmaturtle
Copy link
Member

I'm thinking about the interplay between GenConfig and PropertyConfig. Might we have something like PropertyConfig.withGenConfig, or is that too much 🤪

Also, would it be reasonable to eventually add size and/or seed to GenConfig?

...and if so, how would we explain to users why they're on GenConfig and not PropertyConfig? 😅

@ghost ghost modified the milestones: 0.11.0, 0.12.0 Sep 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants