fthomas / fthomas/refined

[discussion] eliminating macro dependency for `refineMV`

Open
#762 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Scala
Stars
1.7k
Forks
152
Avg merge
1h 20m
Merged PRs (30d)
6

Description

moving this sub-discussion on #758 to its own topic for clarity

It seems like it could be possible for `refined` to go completely macro-less, if (for example) `refineMV[Positive](5)` was instead written as `refineMV[Positive, 5]`.

This would involve the compile-time `refineMV` leaning totally on singleton-ops, and expressions of the (pseudo)form `implicit valid: OpAuxBoolean[P[V], true]`. In that respect, all the macros get pushed to singleton-ops. https://github.com/fthomas/singleton-ops/issues/134 would probably get singleton-ops close to supporting all of refined, maybe not all the way. It could put `refined` in a better position for scala 3, and localize all the macro porting to singleton-ops.

In pre-2.13 scala this would not be as nice: `refineMV[Positive, W.`5`.T]`, but the future is first-class literal types.

A possible alternative would be to use scala trickery to bind the literal type from the parameter:
```scala
scala> def foo[T <: Singleton](ce: T)(implicit tt: WeakTypeTag[T]): String = tt.tpe.toString
foo: [T <: Singleton](ce: T)(implicit tt: WeakTypeTag[T])String

scala> foo(5)
res34: String = Int(5)

scala> foo(x)
res35: String = x.type

scala> foo("abc")
res36: String = String("abc")
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.