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
How to write Arbitrary instances that depend on current time? #176
Comments
IMHO this kind of questions are perfect fit for StackOverflow. Very brief answer: Getting current time is a "side-effect", factor it out.
foo :: MonadTime m => m Res
foo' :: Monad m => m UTCTime -> m Res
data Offset
= Now
| HoursInFuture (Small Int)
| NextMidning
...
applyOffset :: Offset -> UTCTime -> UTCTime
|
@phadej's suggestion of defining an Alternatively, you can avoid the You can do I/O in a property by using the
|
✨ This is an old work account. Please reference @brandonchinn178 for all future communication ✨ I've also historically done arbitraryMyType :: Foo -> Bar -> Gen MyType
forAll (arbitraryMyType foo bar) $ \myType -> ... (I know I'm posting on a really old issue. Maybe this issue should be closed?) |
Closing this as the discussion has moved to Stack Overflow |
I need to write Arbitrary instances for fields of type
UTCTime
, where the values are something that make sense for the problem domain, for example:Related questions:
Arbitrary
instance?The text was updated successfully, but these errors were encountered: