You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importmonocle.syntax.all.*traitAlgebra[Result[_], Element]:defempty:Result[Element]
defaddSomething(
partialResult: Result[Element],
newData: String
):Result[Element]
endAlgebradefweeklyGrind[Result[_], Element](
algebra: Algebra[Result, Element]
):Result[Element] =valmonday= algebra.empty
valtuesday= algebra.addSomething(monday, "A hard working day.")
// Long weekend follows...
tuesday
endweeklyGrindtypeSteps[Element] =Vector[[Result[Element]] =>Algebra[Result, Element] =>Result[
Element
] =>Result[Element]]
// Polymorphic because we don't know what kind of result// the downstream algebra will work with.caseclassRecording[Element](steps: Vector[[Result[Element]] =>Algebra[Result, Element] =>Result[
Element
] =>Result[Element]]):// Changing to the commented out definition fixes the Monocle error.../*case class Recording[Element](steps: Steps[Element]):*/defplayback[Result[Element]](
algebra: Algebra[Result, Element]
):Result[Element] =
steps.foldLeft(algebra.empty)((partialResult, step) =>
step(algebra)(partialResult)
)
classRecordingAlgebra[Element] extendsAlgebra[Recording, Element]:defempty:Recording[Element] =Recording(steps =Vector.empty)
defaddSomething(
partialResult: Recording[Element],
newData: String
):Recording[Element] =
partialResult
.focus(_.steps)
.modify(
_.appended(
[Result[_]] =>
(downstreamAlgebra: Algebra[Result, Element]) =>
downstreamAlgebra.addSomething(_, newData)
)
)
endRecordingAlgebravalonTheRecord= weeklyGrind(newRecordingAlgebra)
Note the alternative definition of Recording:
caseclassRecording[Element](steps: Vector[[Result[Element]] =>Algebra[Result, Element] =>Result[
Element
] =>Result[Element]]):// Changing to the commented out definition fixes the Monocle error.../*case class Recording[Element](steps: Steps[Element]):*/
In the uncommented form, the macro expansion of the .focus(_.steps).modify(...) call in RecordingAlgebra fails with:
Exception occurred while executing macro expansion.
scala.quoted.runtime.impl.ExprCastException:
Expected type:
scala.collection.immutable.Vector[scala.PolyFunction {
val apply: [Result _ >: scala.Nothing <: [Element >: scala.Nothing <: scala.Any] => scala.Any](x$1: Playground.Algebra[Result, Recording.this.Element])scala.Function1[Result[Recording.this.Element], Result[Recording.this.Element]]
}]
Actual type: from.steps
Expression: from.steps
at scala.quoted.runtime.impl.ExprCastException$.apply(ExprCastException.scala:15)
at scala.quoted.runtime.impl.QuotesImpl.asExprOf(QuotesImpl.scala:75)
at scala.quoted.runtime.impl.QuotesImpl$reflect$TreeMethods$.asExprOf(QuotesImpl.scala:123)
at scala.quoted.runtime.impl.QuotesImpl$reflect$TreeMethods$.asExprOf(QuotesImpl.scala:122)
at monocle.internal.focus.features.selectonlyfield.SelectOnlyFieldGenerator.generateSelectOnlyField$$anonfun$1$$anonfun$1(SelectOnlyFieldGenerator.scala:24)
at monocle.internal.focus.features.selectonlyfield.SelectOnlyFieldGenerator.generateSelectOnlyField$$anonfun$1(SelectOnlyFieldGenerator.scala:24)
at monocle.internal.focus.features.selectonlyfield.SelectOnlyFieldGenerator.generateSelectOnlyField$$anonfun$adapted$1(SelectOnlyFieldGenerator.scala:25)
at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:110)
Using the commented form uses an equivalent type alias, and compiles correctly.
I'm not sure if this is down to Monocle, or is an issue with the Scala compiler itself.
The workaround is available (and looks better anyway), but I've raised this in case there is a deeper issue - but it's not urgent for me.
The text was updated successfully, but these errors were encountered:
A Scastie is provided here...
Scala 3.3.4,
SBT includes Monocle dependency of:
Note the alternative definition of
Recording
:In the uncommented form, the macro expansion of the
.focus(_.steps).modify(...)
call inRecordingAlgebra
fails with:Using the commented form uses an equivalent type alias, and compiles correctly.
I'm not sure if this is down to Monocle, or is an issue with the Scala compiler itself.
The workaround is available (and looks better anyway), but I've raised this in case there is a deeper issue - but it's not urgent for me.
The text was updated successfully, but these errors were encountered: