@@ -16,7 +16,10 @@ IntMonoid.unit <+> 2 // 2
16
16
// end::usage[]
17
17
18
18
// tag::numericdefinition[]
19
- given NumericMonoid [T : Numeric ]: Monoid [T ]:
19
+ // 2025-06-16: The following line was the original syntax in Scala 3
20
+ // given NumericMonoid[T : Numeric]: Monoid[T]:
21
+ // This is the currently acceptable syntax:
22
+ given NumericMonoid : [T : Numeric ] => Monoid [T ]:
20
23
def unit : T = summon[Numeric [T ]].zero
21
24
extension (t : T )
22
25
infix def combine (other : T ): T = summon[Numeric [T ]].plus(t, other)
@@ -30,25 +33,6 @@ NumericMonoid[BigDecimal].unit <+> BigDecimal(3.14)
30
33
NumericMonoid [BigDecimal ].unit combine BigDecimal (3.14 )
31
34
// end::numericdefinition[]
32
35
33
- // tag::numericdefinition2[]
34
- given NumericMonoid [T ](using num : Numeric [T ]): Monoid [T ]:
35
- def unit : T = num.zero
36
- extension (t : T )
37
- infix def combine (other : T ): T = num.plus(t, other)
38
- // end::numericdefinition2[]
39
-
40
- // tag::numericdefinition3[]
41
- given [T : Numeric ]: Monoid [T ]:
42
- def unit : T = summon[Numeric [T ]].zero
43
- extension (t : T )
44
- infix def combine (other : T ): T = summon[Numeric [T ]].plus(t, other)
45
- // or
46
- given [T ](using num : Numeric [T ]): Monoid [T ]:
47
- def unit : T = summon[Numeric [T ]].zero
48
- extension (t : T )
49
- infix def combine (other : T ): T = summon[Numeric [T ]].plus(t, other)
50
-
51
- BigDecimal (3.14 ) <+> summon[Monoid [BigDecimal ]].unit
52
- summon[Monoid [BigDecimal ]].unit <+> BigDecimal (3.14 )
53
- summon[Monoid [BigDecimal ]].unit combine BigDecimal (3.14 )
54
- // end::numericdefinition3[]
36
+ // See MonoidTypeClass2.scala for an alternative definition.
37
+ // We can't write it in this file because loading the script causes errors
38
+ // with alternative definitions in scope.
0 commit comments