These are chat archives for fthomas/refined

11th
Dec 2015
Jean-Rémi Desjardins
@jedesah
Dec 11 2015 20:24
I keep running into this when trying to supply/write Arbitrary instances for refined types:
This message was deleted

both value tagRefType in object RefType of type => eu.timepit.refined.api.RefType[shapeless.tag.@@]
[error]  and value refinedRefType in object RefType of type => eu.timepit.refined.api.RefType[eu.timepit.refined.api.Refined]
[error]  match expected type eu.timepit.refined.api.RefType[F]
[error]   implicit val longPositive: Arbitrary[Positive] = greaterArbitrary
it seems to happen whether I use Refine[Long, Positive] or Long @@ Positive
Very confused, anyone have any idea why this is happening?
Jean-Rémi Desjardins
@jedesah
Dec 11 2015 20:31
@fthomas yes, that is correct
fyi, type Positive = Refined[Long, eu.timepit.refined.numeric.Positive]
btw, as a side question, do you recommend Refined or @@?
Frank S. Thomas
@fthomas
Dec 11 2015 20:38
@jedesah If you don't already use @@, I recommend Refined. You'll run into troubles if you try to use a type alias like type PosInt = Int @@ Positive. OTOH type PosInt = Int Refined Positive is perfectly fine
I can reproduce the problem with Arbitrary but don't have a solution for that yet.
Jean-Rémi Desjardins
@jedesah
Dec 11 2015 20:42
@fthomas Well, a known problem is a huge improvement over a mysterious bug :-)
Do you want me to open an issue?
Frank S. Thomas
@fthomas
Dec 11 2015 20:43
@jedesah that would be great
Frank S. Thomas
@fthomas
Dec 11 2015 20:51
@jedesah the problem seems to be the eu.timepit.refined.numeric.Positive predicate which is defined as Greater[_0] where _0 is a Nat but greaterArbitrary does not support Nats
scala> implicitly[Arbitrary[Int Refined Positive]]
<console>:30: error: diverging implicit expansion for type org.scalacheck.Arbitrary[eu.timepit.refined.api.Refined[Int,eu.timepit.refined.numeric.Positive]]
starting with method arbTuple2 in trait ArbitraryArities
       implicitly[Arbitrary[Int Refined Positive]]
                 ^

scala> implicitly[Arbitrary[Int Refined Greater[W.`0`.T]]]
res16: org.scalacheck.Arbitrary[eu.timepit.refined.api.Refined[Int,eu.timepit.refined.numeric.Greater[Int(0)]]] = org.scalacheck.ArbitraryLowPriority$$anon$3@857e21f
If you use Greater[W.`0`.T] instead of Positive it should work
Frank S. Thomas
@fthomas
Dec 11 2015 20:57
hmm nope, that wasn't the problem
Jean-Rémi Desjardins
@jedesah
Dec 11 2015 20:58
btw, what is `W.
I mean what is W.\0`.T`?
hmm...
you know what I mean :P
W.`0`.T
ha!
Jean-Rémi Desjardins
@jedesah
Dec 11 2015 21:00
ah, I see, thx!
Frank S. Thomas
@fthomas
Dec 11 2015 21:00
:-)
Jean-Rémi Desjardins
@jedesah
Dec 11 2015 21:01
why are you saying that wasn’t the problem?
looks like in your repl sessions you were able to get an Arbitrary
Frank S. Thomas
@fthomas
Dec 11 2015 21:04
Yes, but this still fails:
scala> val longPositive: Arbitrary[Long Refined Greater[W.`0`.T]] = greaterArbitrary
<console>:29: error: ambiguous implicit values:
 both value tagRefType in object RefType of type => eu.timepit.refined.api.RefType[shapeless.tag.@@]
 and value refinedRefType in object RefType of type => eu.timepit.refined.api.RefType[eu.timepit.refined.api.Refined]
 match expected type eu.timepit.refined.api.RefType[F]
       val longPositive: Arbitrary[Long Refined Greater[W.`0`.T]] = greaterArbitrary
                                                                    ^
Jean-Rémi Desjardins
@jedesah
Dec 11 2015 21:07
ah, so it’s when Long is introduced, that things go awry?
Frank S. Thomas
@fthomas
Dec 11 2015 21:08
you're right
scala> val intPositive: Arbitrary[Int Refined Greater[W.`0`.T]] = greaterArbitrary
intPositive: org.scalacheck.Arbitrary[eu.timepit.refined.api.Refined[Int,eu.timepit.refined.numeric.Greater[Int(0)]]] = org.scalacheck.ArbitraryLowPriority$$anon$3@5567d042
now I'm confused
Jean-Rémi Desjardins
@jedesah
Dec 11 2015 21:09
Also, side comment, but in your previous example, why is arbTuple2 getting involved?
Frank S. Thomas
@fthomas
Dec 11 2015 21:13
ok, the confusion is gone:
scala> val longPositive: Arbitrary[Long Refined Greater[W.`0L`.T]] = greaterArbitrary
longPositive: org.scalacheck.Arbitrary[eu.timepit.refined.api.Refined[Long,eu.timepit.refined.numeric.Greater[Long(0L)]]] = org.scalacheck.ArbitraryLowPriority$$anon$3@7971d211
Jean-Rémi Desjardins
@jedesah
Dec 11 2015 21:15
ah!
took me a bit to see the difference!
Frank S. Thomas
@fthomas
Dec 11 2015 21:18
the type argument of Greater needs to be a subtype of the base type
Jean-Rémi Desjardins
@jedesah
Dec 11 2015 21:19
yes, I remember seing that and being confused, because I was attempting to stick a Nat in there. But this makes much more sense
Frank S. Thomas
@fthomas
Dec 11 2015 21:21
Nats usually work (also with Long) but the problem you encountered is that we don't provide Arbitrary instances for predicates indexed by Nats
Jean-Rémi Desjardins
@jedesah
Dec 11 2015 21:24
ah, ok, got it
I might do a PR with doc for that :D
Frank S. Thomas
@fthomas
Dec 11 2015 21:26
I love PRs! :-)