Got to the bottom of a stubborn problem trying to export Coulomb #443
Replies: 4 comments 16 replies
-
when you say it exports when I was working with the opaque type design for Quantity, I also found that its behavior was a bit unintuitive. I also recall having problems exporting objects that are defined at a |
Beta Was this translation helpful? Give feedback.
-
One thing that might work to work around some of this is if I change ALL of the definitions in coulomb to be inside It would break MiMa, and might require some of the path names to change. The advantage of |
Beta Was this translation helpful? Give feedback.
-
I tried a simplified reproducer of what I believe to be the basic structure of coulomb, and for what it's worth, it seems to work. There are a lot of advanced scala features in play with coulomb, and it's hard to know if any candidate reproducer is capturing the right ones. package freetp {
opaque type FreeTP[V, U] = V
object FreeTP:
def apply[U](using a: Applier[U]) = a
class Applier[U]:
def apply[V](v: V): FreeTP[V, U] = v
object Applier:
given given_Applier[U]: Applier[U] = new Applier[U]
extension [V, U](f: FreeTP[V, U])
def value: V = f
}
package exporter {
object all:
// no wildcard exports from a package
export _root_.coulomb.freetp.FreeTP
// ok to wildcard export from object
export math.{*, given}
object math:
import _root_.coulomb.freetp.FreeTP
abstract class AddFreeTP[V, U]:
def plus(x: FreeTP[V, U], y: FreeTP[V, U]): FreeTP[V, U]
given given_AddFreeTP[V, U](using n: Numeric[V]): AddFreeTP[V, U] =
new AddFreeTP[V, U]:
def plus(x: FreeTP[V, U], y: FreeTP[V, U]): FreeTP[V, U] =
FreeTP[U](n.plus(x.value, y.value))
}
object repro:
final type Free
import _root_.coulomb.exporter.all.{*, given}
val x = FreeTP[Free](1)
val add = summon[AddFreeTP[Int, Free]]
val x2 = add.plus(x, x) |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
export
ing Coulomb has been very flaky for me, lots of weird compiler errors in application code that tries to use Coulomb in exported form. I finally got to the bottom of why.The apparent workaround is to avoid
export coulomb.Quantity
and instead alias viatype Quantity[U, V] = coulomb.Quantity[U, V]
Copied from the Scala discord:
severian — Today at 6:41 PM
I've hit an issue using Scala 3 export. There seems to be an ambiguity (or double-meaning) in the current syntax rules [https://docs.scala-lang.org/scala3/reference/other-new-features/export.html].
Say I have a package that defines a type and an object:
If I then export this via the expression
export exporter.Foo
, it seems that I export bothSometimes this is undesirable. I cannot find any export syntax that can refer to solely the type, or the object members, without exporting the other one. There's an unwanted "pun" in the export syntax. Does anyone know a way?
BTW this is not a purely academic question. I have spent several days tracking down a subtle issue when exporting the Coulomb [https://github.com/erikerlandson/coulomb] library that is caused by the double-export behavior.
Beta Was this translation helpful? Give feedback.
All reactions