Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

experiment with named classes in operations #265

Merged
merged 35 commits into from
Apr 6, 2022
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a795b93
PowImplFP experiment
erikerlandson Mar 31, 2022
a933042
study1 and study2
erikerlandson Apr 1, 2022
b6a9de2
pow
erikerlandson Apr 1, 2022
57324c9
implicit conversions
erikerlandson Apr 2, 2022
7c0c568
named unit conversion classes
erikerlandson Apr 2, 2022
8106a6c
named simplify class
erikerlandson Apr 2, 2022
833338b
unused import
erikerlandson Apr 2, 2022
4a436e9
named add
erikerlandson Apr 2, 2022
721ee81
named sub
erikerlandson Apr 2, 2022
6f7b5db
named mul
erikerlandson Apr 2, 2022
24509e0
named div
erikerlandson Apr 2, 2022
3e4661a
named tquot and tpow
erikerlandson Apr 2, 2022
6d3dc7c
named ord
erikerlandson Apr 2, 2022
fcd5dc1
move simplification
erikerlandson Apr 2, 2022
f2ca846
named deltasub
erikerlandson Apr 2, 2022
5aa2abe
named deltasubq
erikerlandson Apr 2, 2022
1cdd9b4
named deltaaddq
erikerlandson Apr 2, 2022
d7e3a9d
named deltaord
erikerlandson Apr 2, 2022
5ad20dd
named neg
erikerlandson Apr 2, 2022
06671bf
clean up rational.typeexpr
erikerlandson Apr 2, 2022
d4dea8a
AddNC SubNC MulNC DivNC
erikerlandson Apr 5, 2022
a2871f4
clean up implicit conversion defs using SAM/lambdas
erikerlandson Apr 5, 2022
c2d3615
increase benchmark iteration time for more stability
erikerlandson Apr 5, 2022
817be07
experiment with named class for unit defs
erikerlandson Apr 5, 2022
e93247d
neg with SAM/lambda
erikerlandson Apr 5, 2022
ee70e03
TQuotNC
erikerlandson Apr 5, 2022
92c63fa
PowNC, TPowNC
erikerlandson Apr 5, 2022
72795b8
Ord using SAM/lambda
erikerlandson Apr 5, 2022
cbcd64a
DeltaSubNC
erikerlandson Apr 5, 2022
463e3bc
DeltaSubQNC
erikerlandson Apr 5, 2022
b189c48
DeltaAddQNC
erikerlandson Apr 5, 2022
26ed1ee
DeltaOrd with SAM/lambdas
erikerlandson Apr 5, 2022
e84558b
VRNC
erikerlandson Apr 5, 2022
b0872d8
policy cleanup
erikerlandson Apr 6, 2022
658f02a
fix benchmark imports
erikerlandson Apr 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
implicit conversions
erikerlandson committed Apr 5, 2022
commit 57324c9f8f4e14975521bea866de9907597264ae
43 changes: 31 additions & 12 deletions core/src/main/scala/coulomb/conversion/standard/scala.scala
Original file line number Diff line number Diff line change
@@ -26,35 +26,54 @@ object scala:
// https://docs.scala-lang.org/scala3/reference/contextual/conversions.html

given ctx_Quantity_Conversion_1V1U[V, U]: Conversion[Quantity[V, U], Quantity[V, U]] =
new Conversion[Quantity[V, U], Quantity[V, U]]:
def apply(q: Quantity[V, U]): Quantity[V, U] = q
new infra.QC1V1U[V, U]

given ctx_Quantity_Conversion_1V2U[V, UF, UT](using
uc: UnitConversion[V, UF, UT]
): Conversion[Quantity[V, UF], Quantity[V, UT]] =
new Conversion[Quantity[V, UF], Quantity[V, UT]]:
def apply(q: Quantity[V, UF]): Quantity[V, UT] =
uc(q.value).withUnit[UT]
new infra.QC1V2U[V, UF, UT](uc)

given ctx_Quantity_Conversion_2V1U[U, VF, VT](using
vc: ValueConversion[VF, VT],
): Conversion[Quantity[VF, U], Quantity[VT, U]] =
new Conversion[Quantity[VF, U], Quantity[VT, U]]:
def apply(q: Quantity[VF, U]): Quantity[VT, U] =
vc(q.value).withUnit[U]
new infra.QC2V1U[U, VF, VT](vc)

given ctx_Quantity_Conversion_2V2U[VF, UF, VT, UT](using
vc: ValueConversion[VF, VT],
uc: UnitConversion[VT, UF, UT]
): Conversion[Quantity[VF, UF], Quantity[VT, UT]] =
new Conversion[Quantity[VF, UF], Quantity[VT, UT]]:
def apply(q: Quantity[VF, UF]): Quantity[VT, UT] =
uc(vc(q.value)).withUnit[UT]
new infra.QC2V2U[VF, UF, VT, UT](vc, uc)

given ctx_DeltaQuantity_conversion_2V2U[B, VF, UF, VT, UT](using
vc: ValueConversion[VF, VT],
uc: DeltaUnitConversion[VT, B, UF, UT]
): Conversion[DeltaQuantity[VF, UF, B], DeltaQuantity[VT, UT, B]] =
new Conversion[DeltaQuantity[VF, UF, B], DeltaQuantity[VT, UT, B]]:
new infra.DQC2V2U[B, VF, UF, VT, UT](vc, uc)

object infra:
class QC1V1U[V, U] extends Conversion[Quantity[V, U], Quantity[V, U]]:
def apply(q: Quantity[V, U]): Quantity[V, U] = q

class QC1V2U[V, UF, UT](uc: UnitConversion[V, UF, UT]) extends
Conversion[Quantity[V, UF], Quantity[V, UT]]:
def apply(q: Quantity[V, UF]): Quantity[V, UT] =
uc(q.value).withUnit[UT]

class QC2V1U[U, VF, VT](vc: ValueConversion[VF, VT]) extends
Conversion[Quantity[VF, U], Quantity[VT, U]]:
def apply(q: Quantity[VF, U]): Quantity[VT, U] =
vc(q.value).withUnit[U]

class QC2V2U[VF, UF, VT, UT](
vc: ValueConversion[VF, VT],
uc: UnitConversion[VT, UF, UT]) extends
Conversion[Quantity[VF, UF], Quantity[VT, UT]]:
def apply(q: Quantity[VF, UF]): Quantity[VT, UT] =
uc(vc(q.value)).withUnit[UT]

class DQC2V2U[B, VF, UF, VT, UT](
vc: ValueConversion[VF, VT],
uc: DeltaUnitConversion[VT, B, UF, UT]) extends
Conversion[DeltaQuantity[VF, UF, B], DeltaQuantity[VT, UT, B]]:
def apply(q: DeltaQuantity[VF, UF, B]): DeltaQuantity[VT, UT, B] =
uc(vc(q.value)).withDeltaUnit[UT, B]