1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Scalaの依存型ライブラリrefinedで「W.`数字`.T」・「W.`"文字列".T」とせずに「数字」・「”文字列”」と書いても動いた件

Last updated at Posted at 2021-11-07

以下の記事では、

W.数字.T
W."文字".T

でないとコンパイルエラーになると書かれていました。

refined "0.9.27"を動かしたところ、

W.数字.T
数字
W."文字".T
"文字"
のどれでも動いた。

REPL(Terminal)
scala> val endWithS: String Refined EndsWith[W.`"l"`.T] = "Goal"
val endWithS: eu.timepit.refined.api.Refined[String,eu.timepit.refined.string.EndsWith[String("l")]] = Goal

scala> val endWithS: String Refined EndsWith["l"] = "Goal"
val endWithS: eu.timepit.refined.api.Refined[String,eu.timepit.refined.string.EndsWith["l"]] = Goal

scala> 
REPL(Terminal)
scala> val a: Int Refined Interval.Closed[0, 10] = 2
val a: eu.timepit.refined.api.Refined[Int,eu.timepit.refined.numeric.Interval.Closed[0,10]] = 2

scala> val a: Int Refined Interval.Closed[W.`0`.T, W.`10`.T] = 2
val a: eu.timepit.refined.api.Refined[Int,eu.timepit.refined.numeric.Interval.Closed[Int(0),Int(10)]] = 2

scala> val a: Int Refined Interval.Closed[0, 10] = 11
                                                   ^
       error: Right predicate of (!(11 < 0) && !(11 > 10)) failed: Predicate (11 > 10) did not fail.

scala> val a: Int Refined Interval.Closed[W.`0`.T, W.`10`.T] = 11
                                                               ^
       error: Right predicate of (!(11 < 0) && !(11 > 10)) failed: Predicate (11 > 10) did not fail.

scala> 

REPL(Terminal)
scala> val a: Int Refined (Not[Less[0]] And Not[Greater[10]]) = 8
val a: eu.timepit.refined.api.Refined[Int,eu.timepit.refined.boolean.And[eu.timepit.refined.boolean.Not[eu.timepit.refined.numeric.Less[0]],eu.timepit.refined.boolean.Not[eu.timepit.refined.numeric.Greater[10]]]] = 8

scala> val a: Int Refined (Not[Less[0]] And Not[Greater[10]]) = 10
val a: eu.timepit.refined.api.Refined[Int,eu.timepit.refined.boolean.And[eu.timepit.refined.boolean.Not[eu.timepit.refined.numeric.Less[0]],eu.timepit.refined.boolean.Not[eu.timepit.refined.numeric.Greater[10]]]] = 10

scala> val a: Int Refined (Not[Less[0]] And Not[Greater[10]]) = 11
                                                                ^
       error: Right predicate of (!(11 < 0) && !(11 > 10)) failed: Predicate (11 > 10) did not fail.

scala> val a: Int Refined (Not[Less[W.`0`.T]] And Not[Greater[W.`10`.T]]) = 8
val a: eu.timepit.refined.api.Refined[Int,eu.timepit.refined.boolean.And[eu.timepit.refined.boolean.Not[eu.timepit.refined.numeric.Less[Int(0)]],eu.timepit.refined.boolean.Not[eu.timepit.refined.numeric.Greater[Int(10)]]]] = 8

scala> val a: Int Refined (Not[Less[W.`0`.T]] And Not[Greater[W.`10`.T]]) = 10
val a: eu.timepit.refined.api.Refined[Int,eu.timepit.refined.boolean.And[eu.timepit.refined.boolean.Not[eu.timepit.refined.numeric.Less[Int(0)]],eu.timepit.refined.boolean.Not[eu.timepit.refined.numeric.Greater[Int(10)]]]] = 10

scala> val a: Int Refined (Not[Less[W.`0`.T]] And Not[Greater[W.`10`.T]]) = 11
                                                                            ^
       error: Right predicate of (!(11 < 0) && !(11 > 10)) failed: Predicate (11 > 10) did not fail.

scala> 
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?