Skip to content

Commit 561091c

Browse files
committed
Remove duplicated comparison section
1 parent 6851fea commit 561091c

File tree

1 file changed

+2
-183
lines changed

1 file changed

+2
-183
lines changed

content/typeclasses-syntax.md

Lines changed: 2 additions & 183 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ one would have to put the function in parentheses, in both current and proposed
555555
given Context as context = deferred
556556

557557
// By-name given
558-
given => Context as context = ctx
558+
given => Context as context = curCtx
559559
```
560560
**Notes:**
561561

@@ -597,7 +597,7 @@ As an alternative, here is a version of new style given, but using the current `
597597
given context: Context = deferred
598598

599599
// By-name given
600-
given context: => Context = ctx
600+
given context: => Context = curCtx
601601
```
602602
**Notes:**
603603

@@ -621,184 +621,3 @@ which also covers the other prospective changes slated to be proposed in two fut
621621
existing implementation techniques for type classes.
622622

623623
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-
given Ord[Int] with
632-
def compare(x: Int, y: Int) = ...
633-
634-
// Parameterized typeclass
635-
given [A: Ord]: Ord[List[A]] with
636-
def compare(x: List[A], y: List[A]) = ...
637-
638-
// Typeclass with using clause
639-
given [A](using Ord[A]): Ord[List[A]] with
640-
def compare(x: List[A], y: List[A]) = ...
641-
642-
// Simple alias
643-
given Ord[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](using Ord[A]): Ord[List[A]] =
651-
ListOrd[A]
652-
653-
// Concrete class instance
654-
given Context with {}
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-
given Ord[Int]:
668-
def compare(x: Int, y: Int) = ...
669-
670-
// Parameterized typeclass
671-
given [A: Ord] => Ord[List[A]]:
672-
def compare(x: List[A], y: List[A]) = ...
673-
674-
// Typeclass with using clause
675-
given [A](using Ord[A]) => Ord[List[A]]:
676-
def compare(x: List[A], y: List[A]) = ...
677-
678-
// Simple alias
679-
given Ord[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](using Ord[A]) => Ord[List[A]] =
687-
ListOrd[A]
688-
689-
// Concrete class instance
690-
given Context
691-
692-
// Abstract or deferred given
693-
given Context = deferred
694-
695-
// By-name given
696-
given => Context = curCtx
697-
```
698-
**Current, Named**
699-
700-
```scala
701-
// Simple typeclass
702-
given intOrd: Ord[Int] with
703-
def compare(x: Int, y: Int) = ...
704-
705-
// Parameterized typeclass
706-
given listOrd: [A: Ord]: Ord[List[A]] with
707-
def compare(x: List[A], y: List[A]) = ...
708-
709-
// Typeclass with using clause
710-
given [A](using Ord[A]): Ord[List[A]] with
711-
def compare(x: List[A], y: List[A]) = ...
712-
713-
// Simple alias
714-
given intOrd: Ord[Int] = IntOrd()
715-
716-
// Parameterized alias
717-
given listOrd[A: Ord]: Ord[List[A]] =
718-
ListOrd[A]()
719-
720-
// Alias with using clause
721-
given listOrd[A](using Ord[A]): Ord[List[A]] =
722-
ListOrd[A]
723-
724-
// Concrete class instance
725-
given context: Context with {}
726-
727-
// Abstract or deferred given
728-
given context: Context
729-
730-
// By-name given
731-
given context[DummySoItsADef]: Context = curCtx
732-
```
733-
734-
**Proposal, Named**
735-
736-
```scala
737-
// Simple typeclass
738-
given Ord[Int] as intOrd:
739-
def compare(x: Int, y: Int) = ...
740-
741-
// Parameterized typeclass
742-
given [A: Ord] => Ord[List[A]] as listOrd:
743-
def compare(x: List[A], y: List[A]) = ...
744-
745-
// Typeclass with using clause
746-
given [A](using Ord[A]) => Ord[List[A]] as listOrd:
747-
def compare(x: List[A], y: List[A]) = ...
748-
749-
// Simple alias
750-
given Ord[Int] as intOrd = IntOrd()
751-
752-
// Parameterized alias
753-
given [A: Ord] => Ord[List[A]] as listOrd =
754-
ListOrd[A]()
755-
756-
// Alias with using clause
757-
given [A](using Ord[A]) => Ord[List[A]] as listOrd =
758-
ListOrd[A]
759-
760-
// Concrete class instance
761-
given Context as context
762-
763-
// Abstract or deferred given
764-
given Context as context = deferred
765-
766-
// By-name given
767-
given => Context as context = ctx
768-
```
769-
770-
**Proposal, Named in Current Style**
771-
772-
```scala
773-
// Simple typeclass
774-
given intOrd: Ord[Int]:
775-
def compare(x: Int, y: Int) = ...
776-
777-
// Parameterized typeclass
778-
given listOrd: [A: Ord] => Ord[List[A]]:
779-
def compare(x: List[A], y: List[A]) = ...
780-
781-
// Typeclass with using clause
782-
given listOrd: [A](using Ord[A]) => Ord[List[A]]:
783-
def compare(x: List[A], y: List[A]) = ...
784-
785-
// Simple alias
786-
given intOrd: Ord[Int] = IntOrd()
787-
788-
// Parameterized alias
789-
given listOrd: [A: Ord] => Ord[List[A]] =
790-
ListOrd[A]()
791-
792-
// Alias with using clause
793-
given listOrd: [A](using Ord[A]) => Ord[List[A]] =
794-
ListOrd[A]
795-
796-
// Concrete class instance
797-
given context: Context // this would be a change of meaning from abstract given
798-
799-
// Abstract or deferred given
800-
given context: Context = deferred
801-
802-
// By-name given
803-
given context: => Context = ctx
804-
```

0 commit comments

Comments
 (0)