These are chat archives for fthomas/refined

13th
Sep 2016
Felix Dietze
@fdietze
Sep 13 2016 14:40 UTC
Hi, what am I doing wrong here?
scala> val l:List[Int] Refined Size[W.`2`.T] = List(1,2)
<console>:42: error: type mismatch;
 found   : List[Int]
 required: eu.timepit.refined.api.Refined[List[Int],eu.timepit.refined.collection.Size[Int(2)]]
       val l:List[Int] Refined Size[W.`2`.T] = List(1,2)
                                                   ^
Oron Port
@soronpo
Sep 13 2016 15:11 UTC
@fdietze Is this what you mean to do?
val l:List[Int Refined Size[W.`2`.T]] = List(1,2)
Felix Dietze
@fdietze
Sep 13 2016 15:12 UTC
I'd like to have a list with exactly two elements
Howy Perrin
@howyp
Sep 13 2016 15:12 UTC
@fdietze did you import eu.timepit.refined.auto._?
Felix Dietze
@fdietze
Sep 13 2016 15:13 UTC
yes
Howy Perrin
@howyp
Sep 13 2016 15:14 UTC
hmm - does it work with an explicit refineMV(...)?
Felix Dietze
@fdietze
Sep 13 2016 15:16 UTC
like this?
scala> refineMV[List[Int Refined Size[W.`2`.T]]](List(1,2))
<console>:43: error: could not find implicit value for parameter v: eu.timepit.refined.api.Validate[List[Int],List[eu.timepit.refined.api.Refined[Int,eu.timepit.refined.collection.Size[Int(2)]]]]
       refineMV[List[Int Refined Size[W.`2`.T]]](List(1,2))
                                                ^
Howy Perrin
@howyp
Sep 13 2016 15:19 UTC
ah no it would need to be: refineMV[Size[W.`2`.T]](List(1,2)) - ie. just give the refinement parameter
Felix Dietze
@fdietze
Sep 13 2016 15:21 UTC
still the missing implicit
i imported
    import eu.timepit.refined._
    import eu.timepit.refined.api.Refined
    import eu.timepit.refined.auto._
    import eu.timepit.refined.numeric._
    import eu.timepit.refined.boolean._
    import eu.timepit.refined.char._
    import eu.timepit.refined.collection._
    import eu.timepit.refined.generic._
    import eu.timepit.refined.string._
scala> refineMV[Size[W.`2`.T]](List(1,2))
<console>:68: error: could not find implicit value for parameter v: eu.timepit.refined.api.Validate[List[Int],eu.timepit.refined.collection.Size[Int(2)]]
       refineMV[Size[W.`2`.T]](List(1,2))
                              ^
and, if that's important, I have all optional libraries in my project:
      "eu.timepit" %% "refined" % "0.5.0" ::
      "eu.timepit" %% "refined-scalaz" % "0.5.0" :: // optional
      "eu.timepit" %% "refined-scodec" % "0.5.0" :: // optional
      "eu.timepit" %% "refined-scalacheck" % "0.5.0" % "test" :: // optional
Felix Dietze
@fdietze
Sep 13 2016 15:35 UTC
@soronpo, thank you, I'm reading this right now
Frank Thomas
@fthomas
Sep 13 2016 17:34 UTC
@fdietze val l:List[Int] Refined Size[W.`2`.T] = List(1,2) does not work because the right hand side (List(1, 2)) is not a literal and Size[W.`2`.T] is not a valid predicate, it should be Size[Equal[W.`2`.T]] instead. Currently refined can only refine literals at compile-time. The best you can do right now is this:
scala> refineV[Size[Equal[W.`2`.T]]](List(1, 2))
res2: Either[String, Refined[List[Int], Size[Equal[Int(2)]]]] = Right(List(1, 2))
Howy Perrin
@howyp
Sep 13 2016 17:35 UTC
so is ‘literal’ limited to primitive-ish types?
Frank Thomas
@fthomas
Sep 13 2016 17:38 UTC
sort of. there are literals for Int, Long, Double, Float, Boolean, Char, and String but not for Byte and Short
btw, refineMV with the correct refinement gives an appropriate error message:
scala> refineMV[Size[Equal[W.`2`.T]]](List(1, 2))
<console>:48: error: compile-time refinement only works with literals
       refineMV[Size[Equal[W.`2`.T]]](List(1, 2))
                                     ^