Skip to content

Add genBoundedEnum#29

Merged
garyb merged 3 commits into
masterfrom
gen
Jun 8, 2017
Merged

Add genBoundedEnum#29
garyb merged 3 commits into
masterfrom
gen

Conversation

@garyb
Copy link
Copy Markdown
Member

@garyb garyb commented Jun 8, 2017

No description provided.

Comment thread src/Data/Enum/Gen.purs Outdated
-- | `fromEnum bottom` and `fromEnum top`.
genBoundedEnum :: forall m a. MonadGen m => BoundedEnum a => m a
genBoundedEnum =
unsafePartial fromJust <<< toEnum
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unsafePartial is only safe if the Enum instance is valid, I think.

Another option is oneOf (bottom .. top), or something along those lines, right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This generator I lifted from QuickCheck actually, it was recently added there, so it suffers from any of the same problems that that one has.

Can you explain what you're thinking with oneOf (bottom .. top), I'm not sure I follow?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does say in the comment that toEnum must be well behaved too 😉

Copy link
Copy Markdown
Contributor

@paf31 paf31 Jun 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By bottom .. top, I meant to say enumFromTo bottom top, which must be safe, I think.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh yeah, that'd work. It'll be kinda expensive if used for large enums, but can revisit if we have a case where it's obviously terrible. :)

@garyb
Copy link
Copy Markdown
Member Author

garyb commented Jun 8, 2017

How's this? A slight bias to bottom now, but necessary without adding dependencies or FFI something, since there's no array/list dependency even transitively.

@paf31
Copy link
Copy Markdown
Contributor

paf31 commented Jun 8, 2017

👍 Thanks!

@garyb garyb merged commit d307db5 into master Jun 8, 2017
@garyb garyb deleted the gen branch June 8, 2017 20:27
hdgarrood pushed a commit that referenced this pull request Jul 29, 2017
* Add `genBoundedEnum`

* Use `enumFromTo` for `genBoundedEnum`

* Un-bias the enum generator
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

Successfully merging this pull request may close these issues.

2 participants