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
Copy file name to clipboardExpand all lines: content/typeclasses-syntax.md
+2-183Lines changed: 2 additions & 183 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -555,7 +555,7 @@ one would have to put the function in parentheses, in both current and proposed
555
555
givenContextascontext= deferred
556
556
557
557
// By-name given
558
-
given=>Contextascontext=ctx
558
+
given=>Contextascontext=curCtx
559
559
```
560
560
**Notes:**
561
561
@@ -597,7 +597,7 @@ As an alternative, here is a version of new style given, but using the current `
597
597
givencontext:Context= deferred
598
598
599
599
// By-name given
600
-
givencontext:=>Context=ctx
600
+
givencontext:=>Context=curCtx
601
601
```
602
602
**Notes:**
603
603
@@ -621,184 +621,3 @@ which also covers the other prospective changes slated to be proposed in two fut
621
621
existing implementation techniques for type classes.
622
622
623
623
The changes proposed in this SIP are time-sensitive since we would like to correct some awkward syntax choices in Scala 3 before more code migrates to the new constructs (so far, it seems most code still uses Scala 2 style implicits, which will eventually be phased out). It is easy to migrate to the new syntax and to support both old and new for a transition period.
624
-
625
-
## Comparison
626
-
627
-
**Current, Anonymous**
628
-
629
-
```scala
630
-
// Simple typeclass
631
-
givenOrd[Int] with
632
-
defcompare(x: Int, y: Int) = ...
633
-
634
-
// Parameterized typeclass
635
-
given [A:Ord]:Ord[List[A]] with
636
-
defcompare(x: List[A], y: List[A]) = ...
637
-
638
-
// Typeclass with using clause
639
-
given [A](usingOrd[A]):Ord[List[A]] with
640
-
defcompare(x: List[A], y: List[A]) = ...
641
-
642
-
// Simple alias
643
-
givenOrd[Int] =IntOrd()
644
-
645
-
// Parameterized alias
646
-
given [A:Ord]:Ord[List[A]] =
647
-
ListOrd[A]()
648
-
649
-
// Alias with using clause
650
-
given [A](usingOrd[A]):Ord[List[A]] =
651
-
ListOrd[A]
652
-
653
-
// Concrete class instance
654
-
givenContextwith {}
655
-
656
-
// Abstract or deferred given
657
-
// given Context // can't be expressed
658
-
659
-
// By-name given
660
-
given [DummySoItsADef]:Context= curCtx
661
-
```
662
-
663
-
**Proposal, Anonymous**
664
-
665
-
```scala
666
-
// Simple typeclass
667
-
givenOrd[Int]:
668
-
defcompare(x: Int, y: Int) = ...
669
-
670
-
// Parameterized typeclass
671
-
given [A:Ord] =>Ord[List[A]]:
672
-
defcompare(x: List[A], y: List[A]) = ...
673
-
674
-
// Typeclass with using clause
675
-
given [A](usingOrd[A]) =>Ord[List[A]]:
676
-
defcompare(x: List[A], y: List[A]) = ...
677
-
678
-
// Simple alias
679
-
givenOrd[Int] =IntOrd()
680
-
681
-
// Parameterized alias
682
-
given [A:Ord] =>Ord[List[A]] =
683
-
ListOrd[A]()
684
-
685
-
// Alias with using clause
686
-
given [A](usingOrd[A]) =>Ord[List[A]] =
687
-
ListOrd[A]
688
-
689
-
// Concrete class instance
690
-
givenContext
691
-
692
-
// Abstract or deferred given
693
-
givenContext= deferred
694
-
695
-
// By-name given
696
-
given=>Context= curCtx
697
-
```
698
-
**Current, Named**
699
-
700
-
```scala
701
-
// Simple typeclass
702
-
givenintOrd:Ord[Int] with
703
-
defcompare(x: Int, y: Int) = ...
704
-
705
-
// Parameterized typeclass
706
-
givenlistOrd: [A:Ord]:Ord[List[A]] with
707
-
defcompare(x: List[A], y: List[A]) = ...
708
-
709
-
// Typeclass with using clause
710
-
given [A](usingOrd[A]):Ord[List[A]] with
711
-
defcompare(x: List[A], y: List[A]) = ...
712
-
713
-
// Simple alias
714
-
givenintOrd:Ord[Int] =IntOrd()
715
-
716
-
// Parameterized alias
717
-
givenlistOrd[A:Ord]:Ord[List[A]] =
718
-
ListOrd[A]()
719
-
720
-
// Alias with using clause
721
-
givenlistOrd[A](usingOrd[A]):Ord[List[A]] =
722
-
ListOrd[A]
723
-
724
-
// Concrete class instance
725
-
givencontext:Contextwith {}
726
-
727
-
// Abstract or deferred given
728
-
givencontext:Context
729
-
730
-
// By-name given
731
-
givencontext[DummySoItsADef]:Context= curCtx
732
-
```
733
-
734
-
**Proposal, Named**
735
-
736
-
```scala
737
-
// Simple typeclass
738
-
givenOrd[Int] asintOrd:
739
-
defcompare(x: Int, y: Int) = ...
740
-
741
-
// Parameterized typeclass
742
-
given [A:Ord] =>Ord[List[A]] aslistOrd:
743
-
defcompare(x: List[A], y: List[A]) = ...
744
-
745
-
// Typeclass with using clause
746
-
given [A](usingOrd[A]) =>Ord[List[A]] aslistOrd:
747
-
defcompare(x: List[A], y: List[A]) = ...
748
-
749
-
// Simple alias
750
-
givenOrd[Int] asintOrd=IntOrd()
751
-
752
-
// Parameterized alias
753
-
given [A:Ord] =>Ord[List[A]] aslistOrd=
754
-
ListOrd[A]()
755
-
756
-
// Alias with using clause
757
-
given [A](usingOrd[A]) =>Ord[List[A]] aslistOrd=
758
-
ListOrd[A]
759
-
760
-
// Concrete class instance
761
-
givenContextascontext
762
-
763
-
// Abstract or deferred given
764
-
givenContextascontext= deferred
765
-
766
-
// By-name given
767
-
given=>Contextascontext= ctx
768
-
```
769
-
770
-
**Proposal, Named in Current Style**
771
-
772
-
```scala
773
-
// Simple typeclass
774
-
givenintOrd:Ord[Int]:
775
-
defcompare(x: Int, y: Int) = ...
776
-
777
-
// Parameterized typeclass
778
-
givenlistOrd: [A:Ord] =>Ord[List[A]]:
779
-
defcompare(x: List[A], y: List[A]) = ...
780
-
781
-
// Typeclass with using clause
782
-
givenlistOrd: [A](usingOrd[A]) =>Ord[List[A]]:
783
-
defcompare(x: List[A], y: List[A]) = ...
784
-
785
-
// Simple alias
786
-
givenintOrd:Ord[Int] =IntOrd()
787
-
788
-
// Parameterized alias
789
-
givenlistOrd: [A:Ord] =>Ord[List[A]] =
790
-
ListOrd[A]()
791
-
792
-
// Alias with using clause
793
-
givenlistOrd: [A](usingOrd[A]) =>Ord[List[A]] =
794
-
ListOrd[A]
795
-
796
-
// Concrete class instance
797
-
givencontext:Context// this would be a change of meaning from abstract given
0 commit comments