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

Support more natural law syntax #23

Closed
jdegoes opened this issue Mar 25, 2020 · 2 comments · Fixed by #44
Closed

Support more natural law syntax #23

jdegoes opened this issue Mar 25, 2020 · 2 comments · Fixed by #44
Assignees

Comments

@jdegoes
Copy link
Member

jdegoes commented Mar 25, 2020

Right now our laws are a mixture of booleans and TestResult. Use of booleans, such as a > b, will result in quite poor error messages. Ideally, every law failure produces a richly detailed error message, fully utilizing ZIO Test's facilities for reporting.

We fake this right now using <-> as an alternate operator, but this doesn't scale: what would we choose for >, >=, etc.

I think it might be useful to define a new type, like Arbitrary / Arb:

object Arb extends SubtypeF
type Arb[A] = Arb.Type[A]

implicit class ArbSyntax[A](value: Arb[A]) {
  def === (that: Arb[A])(implicit equal: Equal[A]): TestResult = ???
  def > (that: Arb[A])(implicit ord: Ord[A]): TestResult = ???
  ...
}

Then to define (redefine?) Law1, etc. classes such that they are passed Arb[A] instead of A.

Then laws can have this form:

(a1 < a2) && (a2 < a3) ==> (a1 < a3)
(a1 === a2) ==> (a2 === a1)

But they will generate detailed error messages.

/cc @adamgfraser

@adamgfraser
Copy link
Contributor

I’ll take this.

@jdegoes
Copy link
Member Author

jdegoes commented Mar 27, 2020

@adamgfraser Thank you! Could use some more development.

It would be great if we didn't have to duplicate Law1, etc. I couldn't think of a way to do that.

EDIT: To give a new meaning to ===, >, etc., it seems we need a wrapper type, hence Arb. But if we have a wrapper type, then it also seems the existing law machinery will be less useful.

It almost argues the law machinery belongs here in ZIO Prelude. But I think it's useful for ZIO Test to support laws even without any type class library.

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 a pull request may close this issue.

2 participants