Skip to content

Commit

Permalink
Prepare for Scala 3.4
Browse files Browse the repository at this point in the history
Type matches become more strict following scala/scala3#18262
  • Loading branch information
julianpeeters committed Jan 9, 2024
1 parent c40c3d8 commit 5b6b323
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 107 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ import polynomial.morphism.~>
type F[Y] = (Store[Boolean, _] ~> Monomial[Byte, Char, _])[Y]

val M: Mermaid[F] = summon[Mermaid[F]]
// M: Mermaid[F] = polynomial.mermaid.Mermaid$$anon$1@6470dd67
// M: Mermaid[F] = polynomial.mermaid.Mermaid$$anon$1@c13f7ae

println(M.showTitledGraph(titleFmt = Format.Cardinal, graphFmt = Format.Specific))
// ```mermaid
Expand Down
1 change: 0 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ inThisBuild(List(
)
),
scalacOptions ++= Seq(
"-deprecation",
"-feature",
"-source:future",
"-Werror",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,37 @@ import polynomial.mermaid.Mermaid.CustomLabels
import polynomial.mermaid.render.p.MermaidP
import polynomial.mermaid.render.q.MermaidQ
import polynomial.mermaid.render.Format.{Cardinal, Generic, Specific}
import polynomial.mermaid.render.{Render}
import polynomial.mermaid.render.addTitle
import polynomial.mermaid.render.{Render, addTitle}
import polynomial.morphism.PolyMap
import polynomial.`object`.{Binomial, Monomial, Store}

trait Mermaid[F[_]]:
def showGraph(graphFmt: Format): String
def showGraphCustom(graphFmt: Format, labels: CustomLabels[F]): String
def showGraphCustom[Y](graphFmt: Format, labels: CustomLabels[F[Y]]): String
def showTitle(titleFmt: Format): String
def showTitleCustom(labels: CustomLabels[F]): String
def showTitleCustom[Y](labels: CustomLabels[F[Y]]): String
def showTitleHtml(titleFmt: Format): String
def showTitleHtmlCustom(labels: CustomLabels[F]): String
def showTitleHtmlCustom[Y](labels: CustomLabels[F[Y]]): String
def showTitledGraph(titleFmt: Format, graphFmt: Format): String
def showTitledGraphCustom(graphFmt: Format, labels: CustomLabels[F]): String
def showTitledGraphCustom[Y](graphFmt: Format, labels: CustomLabels[F[Y]]): String

object Mermaid:

type ParamLabels[P[_]] = P[Any] match
case Monomial[a, b, Any] => (String, String)
case Binomial[a1, b1, a2, b2, Any] => ((String, String), (String, String))
case Store[s, Any] => String
type ParamLabels[X] = X match
case Monomial[a, b, y] => (String, String)
case Binomial[a1, b1, a2, b2, y] => ((String, String), (String, String))
case Store[s, y] => String

type PolynomialLabels[P[_]] = P[Any] match
case Binomial[a1, b1, a2, b2, Any] => String
case Monomial[a, b, Any] => String
case Store[s, Any] => String
type PolynomialLabels[X] = X match
case Binomial[a1, b1, a2, b2, y] => String
case Monomial[a, b, y] => String
case Store[s, y] => String

type CustomLabels[P[_]] = P[Any] match
case PolyMap[Binomial[a1, b1, a2, b2, _], Monomial[a3, b3, _], Any] => (String, String)
case PolyMap[Monomial[a, b, _], Monomial[a3, b3, _], Any] => (String, String)
case PolyMap[Store[s, _], Monomial[a3, b3, _], Any] => (String, String)
case PolyMap[Store[s, _], Binomial[a1, b1, a2, b2, _], Any] => (String, String)
type CustomLabels[X] = X match
case PolyMap[p, q, y] => CustomLabels[(p[y], q[y])]
case (Monomial[a1, b1, y1], Monomial[a2, b2, y2]) => (String, String)
case (Store[s, y1], Binomial[a1, b1, a2, b2, y2]) => (String, String)
case (Store[s, y1], Monomial[a, b, y2]) => (String, String)

given mooreStoreToMono[S, A, B](using
P: MermaidP[Store[S, _]],
Expand All @@ -53,7 +52,7 @@ object Mermaid:
Render.mermaidCodeFence(Q.graphQGeneric((labelA, labelB))(P.graphPGeneric(P.polynomialGeneric(labelS), labelS)))
case Specific =>
Render.mermaidCodeFence(Q.graphQSpecific(P.graphPSpecific(P.polynomialSpecific)))
def showGraphCustom(graphFmt: Format, labels: (String, String)): String =
def showGraphCustom[Y](graphFmt: Format, labels: (String, String)): String =
graphFmt match
case Cardinal =>
Render.mermaidCodeFence(Q.graphQCardinal(P.graphPCardinal(P.polynomialCardinal)))
Expand All @@ -69,7 +68,7 @@ object Mermaid:
Render.mermaidCodeFence(Render.title(P.polynomialGeneric(labelS), 3, Q.polynomialGeneric((labelA, labelB)), 3))
case Specific =>
Render.mermaidCodeFence(Render.title(P.polynomialSpecific, 3, Q.polynomialSpecific, 3))
def showTitleCustom(labels: (String, String)): String =
def showTitleCustom[Y](labels: (String, String)): String =
Render.mermaidCodeFence(Render.title(labels._1, 3, labels._2, 3))
def showTitleHtml(titleFmt: Format): String =
titleFmt match
Expand All @@ -79,7 +78,7 @@ object Mermaid:
Render.polyMap(P.graphPGeneric(P.polynomialGeneric(labelS), labelS), Q.graphQGeneric((labelA, labelB))(P.graphPGeneric(P.polynomialGeneric(labelS), labelS)))
case Specific =>
Render.polyMap(P.graphPSpecific(P.polynomialSpecific), Q.graphQSpecific(P.graphPSpecific(P.polynomialSpecific)))
def showTitleHtmlCustom(labels: (String, String)): String =
def showTitleHtmlCustom[Y](labels: (String, String)): String =
Render.polyMap(labels._1, labels._2)
def showTitledGraph(titleFmt: Format, graphFmt: Format): String =
(titleFmt, graphFmt) match
Expand Down Expand Up @@ -110,7 +109,7 @@ object Mermaid:
case (Specific, Specific) =>
Render.mermaidCodeFence(Q.graphQSpecific(P.graphPSpecific(P.polynomialSpecific)))
.addTitle(P.polynomialSpecific, 3, Q.polynomialSpecific, 3)
def showTitledGraphCustom(graphFmt: Format, labels: (String, String)): String =
def showTitledGraphCustom[Y](graphFmt: Format, labels: (String, String)): String =
graphFmt match
case Cardinal =>
Render.mermaidCodeFence(Q.graphQCardinal(P.graphPCardinal(P.polynomialCardinal)))
Expand Down Expand Up @@ -138,7 +137,7 @@ object Mermaid:
Render.mermaidCodeFence(Q.graphQGeneric((labelA, labelB))(P.graphPGeneric(P.polynomialGeneric(labelS), labelS)))
case Specific =>
Render.mermaidCodeFence(Q.graphQSpecific(P.graphPSpecific(P.polynomialSpecific)))
def showGraphCustom(graphFmt: Format, labels: (String, String)): String =
def showGraphCustom[Y](graphFmt: Format, labels: (String, String)): String =
graphFmt match
case Cardinal =>
Render.mermaidCodeFence(Q.graphQCardinal(P.graphPCardinal(P.polynomialCardinal)))
Expand All @@ -154,7 +153,7 @@ object Mermaid:
Render.mermaidCodeFence(Render.title(P.polynomialGeneric(labelS), 3, Q.polynomialGeneric((labelA, labelB)), 3))
case Specific =>
Render.mermaidCodeFence(Render.title(P.polynomialSpecific, 3, Q.polynomialSpecific, 3))
def showTitleCustom(labels: (String, String)): String =
def showTitleCustom[Y](labels: (String, String)): String =
Render.mermaidCodeFence(Render.title(labels._1, 3, labels._2, 3))
def showTitleHtml(titleFmt: Format): String =
titleFmt match
Expand All @@ -164,7 +163,7 @@ object Mermaid:
Render.polyMap(P.graphPGeneric(P.polynomialGeneric(labelS), labelS), Q.graphQGeneric((labelA, labelB))(P.graphPGeneric(P.polynomialGeneric(labelS), labelS)))
case Specific =>
Render.polyMap(P.graphPSpecific(P.polynomialSpecific), Q.graphQSpecific(P.graphPSpecific(P.polynomialSpecific)))
def showTitleHtmlCustom(labels: (String, String)): String =
def showTitleHtmlCustom[Y](labels: (String, String)): String =
Render.polyMap(labels._1, labels._2)
def showTitledGraph(titleFmt: Format, graphFmt: Format): String =
(titleFmt, graphFmt) match
Expand Down Expand Up @@ -195,7 +194,7 @@ object Mermaid:
case (Specific, Specific) =>
Render.mermaidCodeFence(Q.graphQSpecific(P.graphPSpecific(P.polynomialSpecific)))
.addTitle(P.polynomialSpecific, 3, Q.polynomialSpecific, 3)
def showTitledGraphCustom(graphFmt: Format, labels: (String, String)): String =
def showTitledGraphCustom[Y](graphFmt: Format, labels: (String, String)): String =
graphFmt match
case Cardinal =>
Render.mermaidCodeFence(Q.graphQCardinal(P.graphPCardinal(P.polynomialCardinal)))
Expand Down Expand Up @@ -224,7 +223,7 @@ object Mermaid:
Render.mermaidCodeFence(Q.graphQGeneric((labelA2, labelB2))(P.graphPGeneric(P.polynomialGeneric((labelA1, labelB1)), (labelA1, labelB1))))
case Specific =>
Render.mermaidCodeFence(Q.graphQSpecific(P.graphPSpecific(P.polynomialSpecific)))
def showGraphCustom(graphFmt: Format, labels: (String, String)): String =
def showGraphCustom[Y](graphFmt: Format, labels: (String, String)): String =
graphFmt match
case Cardinal =>
Render.mermaidCodeFence(Q.graphQCardinal(P.graphPCardinal(P.polynomialCardinal)))
Expand All @@ -240,7 +239,7 @@ object Mermaid:
Render.mermaidCodeFence(Render.title(P.polynomialGeneric((labelA1, labelB1)), 4, Q.polynomialGeneric((labelA2, labelB2)), 4))
case Specific =>
Render.mermaidCodeFence(Render.title(P.polynomialSpecific, 4, Q.polynomialSpecific, 4))
def showTitleCustom(labels: (String, String)): String =
def showTitleCustom[Y](labels: (String, String)): String =
Render.mermaidCodeFence(Render.title(labels._1, 4, labels._2, 4))
def showTitleHtml(titleFmt: Format): String =
titleFmt match
Expand All @@ -250,7 +249,7 @@ object Mermaid:
Render.polyMap(P.graphPGeneric(P.polynomialGeneric((labelA1, labelB1)), (labelA1, labelB1)), Q.graphQGeneric((labelA2, labelB2))(P.graphPGeneric(P.polynomialGeneric((labelA1, labelB1)), (labelA1, labelB1))))
case Specific =>
Render.polyMap(P.graphPSpecific(P.polynomialSpecific), Q.graphQSpecific(P.graphPSpecific(P.polynomialSpecific)))
def showTitleHtmlCustom(labels: (String, String)): String =
def showTitleHtmlCustom[Y](labels: (String, String)): String =
Render.polyMap(labels._1, labels._2)
def showTitledGraph(titleFmt: Format, graphFmt: Format): String =
(titleFmt, graphFmt) match
Expand Down Expand Up @@ -281,7 +280,7 @@ object Mermaid:
case (Specific, Specific) =>
Render.mermaidCodeFence(Q.graphQSpecific(P.graphPSpecific(P.polynomialSpecific)))
.addTitle(P.polynomialSpecific, 4, Q.polynomialSpecific, 4)
def showTitledGraphCustom(graphFmt: Format, labels: (String, String)): String =
def showTitledGraphCustom[Y](graphFmt: Format, labels: (String, String)): String =
graphFmt match
case Cardinal =>
Render.mermaidCodeFence(Q.graphQCardinal(P.graphPCardinal(P.polynomialCardinal)))
Expand Down Expand Up @@ -311,7 +310,7 @@ object Mermaid:
Render.mermaidCodeFence(Q.graphQGeneric(((labelA1, labelB1), (labelA2, labelB2)))(P.graphPGeneric(P.polynomialGeneric(labelS), labelS)))
case Specific =>
Render.mermaidCodeFence(Q.graphQSpecific(P.graphPSpecific(P.polynomialSpecific)))
def showGraphCustom(graphFmt: Format, labels: (String, String)): String =
def showGraphCustom[Y](graphFmt: Format, labels: (String, String)): String =
graphFmt match
case Cardinal =>
Render.mermaidCodeFence(Q.graphQCardinal(P.graphPCardinal(P.polynomialCardinal)))
Expand All @@ -327,7 +326,7 @@ object Mermaid:
Render.mermaidCodeFence(Render.title(P.polynomialGeneric(labelS), 3, Q.polynomialGeneric(((labelA1, labelB1), (labelA2, labelB2))), 3))
case Specific =>
Render.mermaidCodeFence(Render.title(P.polynomialSpecific, 3, Q.polynomialSpecific, 3))
def showTitleCustom(labels: (String, String)): String =
def showTitleCustom[Y](labels: (String, String)): String =
Render.mermaidCodeFence(Render.title(labels._1, 3, labels._2, 3))
def showTitleHtml(titleFmt: Format): String =
titleFmt match
Expand All @@ -337,7 +336,7 @@ object Mermaid:
Render.polyMap(P.graphPGeneric(P.polynomialGeneric(labelS), labelS), Q.graphQGeneric(((labelA1, labelB1), (labelA2, labelB2)))(P.graphPGeneric(P.polynomialGeneric(labelS), labelS)))
case Specific =>
Render.polyMap(P.graphPSpecific(P.polynomialSpecific), Q.graphQSpecific(P.graphPSpecific(P.polynomialSpecific)))
def showTitleHtmlCustom(labels: (String, String)): String =
def showTitleHtmlCustom[Y](labels: (String, String)): String =
Render.polyMap(labels._1, labels._2)
def showTitledGraph(titleFmt: Format, graphFmt: Format): String =
(titleFmt, graphFmt) match
Expand Down Expand Up @@ -368,7 +367,7 @@ object Mermaid:
case (Specific, Specific) =>
Render.mermaidCodeFence(Q.graphQSpecific(P.graphPSpecific(P.polynomialSpecific)))
.addTitle(P.polynomialSpecific, 3, Q.polynomialSpecific, 3)
def showTitledGraphCustom(graphFmt: Format, labels: (String, String)): String =
def showTitledGraphCustom[Y](graphFmt: Format, labels: (String, String)): String =
graphFmt match
case Cardinal =>
Render.mermaidCodeFence(Q.graphQCardinal(P.graphPCardinal(P.polynomialCardinal)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import typesize.SizeOf

trait MermaidP[P[_]]:
// Base constructor of the P component of the graph
def graphP(polynomialLabelP: PolynomialLabels[P], paramLabelsP: ParamLabels[P]): String
def graphP[Y](polynomialLabelP: PolynomialLabels[P[Y]], paramLabelsP: ParamLabels[P[Y]]): String
// Impl constructors of the P component of the graph e.g. A[ ]-->B[ ]
def graphPCardinal(polynomialLabelP: PolynomialLabels[P]): String
def graphPGeneric(polynomialLabelP: PolynomialLabels[P], paramLabelsP: ParamLabels[P]): String
def graphPSpecific(polynomialLabelP: PolynomialLabels[P]): String
def graphPCardinal[Y](polynomialLabelP: PolynomialLabels[P[Y]]): String
def graphPGeneric[Y](polynomialLabelP: PolynomialLabels[P[Y]], paramLabelsP: ParamLabels[P[Y]]): String
def graphPSpecific[Y](polynomialLabelP: PolynomialLabels[P[Y]]): String
// Built-in coefficient labels and exponent labels, e.g., Boolean
def paramLabelsCardinal: ParamLabels[P]
def paramLabelsSpecific: ParamLabels[P]
def paramLabelsCardinal[Y]: ParamLabels[P[Y]]
def paramLabelsSpecific[Y]: ParamLabels[P[Y]]
// Text representation of polynomials e.g., Byᴬ
def polynomialCardinal: String
def polynomialGeneric(paramLabelsP: ParamLabels[P]): String
def polynomialGeneric[Y](paramLabelsP: ParamLabels[P[Y]]): String
def polynomialSpecific: String
// Variable labels, e.g., y
def variableLabel: String
Expand All @@ -27,21 +27,21 @@ object MermaidP:

given [S](using N: NameOf[S], S: SizeOf[S]): MermaidP[Store[S, _]] =
new MermaidP[Store[S, _]]:
def graphP(polynomialLabelP: String, paramLabelsP: String): String =
def graphP[Y](polynomialLabelP: String, paramLabelsP: String): String =
s"S[$paramLabelsP]"
def graphPCardinal(polynomialLabelP: String): String =
def graphPCardinal[Y](polynomialLabelP: String): String =
graphP(polynomialLabelP, paramLabelsCardinal)
def graphPGeneric(polynomialLabelP: String, paramLabelsP: String): String =
def graphPGeneric[Y](polynomialLabelP: String, paramLabelsP: String): String =
graphP(polynomialLabelP, Font.courier(paramLabelsP))
def graphPSpecific(polynomialLabelP: String): String =
def graphPSpecific[Y](polynomialLabelP: String): String =
graphP(polynomialLabelP, Font.courier(paramLabelsSpecific))
def paramLabelsCardinal: String =
def paramLabelsCardinal[Y]: String =
Render.cardinality(S.size)
def paramLabelsSpecific: String =
def paramLabelsSpecific[Y]: String =
N.name
def polynomialCardinal: String =
Render.monomial(paramLabelsCardinal, variableLabel, paramLabelsCardinal)
def polynomialGeneric(paramLabelsP: String): String =
def polynomialGeneric[Y](paramLabelsP: String): String =
Render.monomial(Font.courier(paramLabelsP), variableLabel, Font.courier(paramLabelsP))
def polynomialSpecific: String =
Render.monomial(Font.courier(paramLabelsSpecific), variableLabel, Font.courier(paramLabelsSpecific))
Expand All @@ -50,27 +50,27 @@ object MermaidP:

given [A, B](using NA: NameOf[A], NB: NameOf[B], SA: SizeOf[A], SB: SizeOf[B]): MermaidP[Monomial[A, B, _]] =
new MermaidP[Monomial[A, B, _]]:
def graphP(polynomialLabelP: String, paramLabelsQ: (String, String)): String =
def graphP[Y](polynomialLabelP: String, paramLabelsQ: (String, String)): String =
s"""|A2[ ]:::point
|subgraph s[ ]
| A2:::point---MermaidPMono
| MermaidPMono[${polynomialLabelP}]:::empty
| MermaidPMono---B2
|end
|B2[ ]:::point""".stripMargin
def graphPCardinal(polynomialLabelP: String): String =
def graphPCardinal[Y](polynomialLabelP: String): String =
graphP(polynomialLabelP, paramLabelsCardinal)
def graphPGeneric(polynomialLabelP: String, paramLabelsP: (String, String)): String =
def graphPGeneric[Y](polynomialLabelP: String, paramLabelsP: (String, String)): String =
graphP(polynomialLabelP, paramLabelsP)
def graphPSpecific(polynomialLabelP: String): String =
def graphPSpecific[Y](polynomialLabelP: String): String =
graphP(polynomialLabelP, paramLabelsSpecific)
def paramLabelsCardinal: (String, String) =
def paramLabelsCardinal[Y]: (String, String) =
(Render.cardinality(SA.size), Render.cardinality(SB.size))
def paramLabelsSpecific: (String, String) =
def paramLabelsSpecific[Y]: (String, String) =
(NA.name, NB.name)
def polynomialCardinal: String =
Render.monomial(Font.courier(paramLabelsCardinal._2), variableLabel, Font.courier(paramLabelsCardinal._1))
def polynomialGeneric(paramLabelsP: (String, String)): String =
def polynomialGeneric[Y](paramLabelsP: (String, String)): String =
Render.monomial(Font.courier(paramLabelsP._2), variableLabel, Font.courier(paramLabelsP._1))
def polynomialSpecific: String =
Render.monomial(Font.courier(paramLabelsSpecific._2), variableLabel, Font.courier(paramLabelsSpecific._1))
Expand Down
Loading

0 comments on commit 5b6b323

Please sign in to comment.