Created
August 8, 2025 06:06
-
-
Save p-pavel/647cbb1e276e14572b6a806c3a1137e7 to your computer and use it in GitHub Desktop.
_[_] kind abstractions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** we can start with pure structure, not even thinking about specific types here's the structure of | |
| * a person | |
| */ | |
| trait PersonBase: | |
| val name, birthdate: Any | |
| val children: Any // What about this? we know more than just Any! | |
| /** How about abstracting the idea of "something type-indexed"? */ | |
| object AbstractKindedTypes: | |
| opaque type K1[A] = Any | |
| opaque type K1Impl[F[_], A] >: F[A] <: K1[A] & F[A] = F[A] | |
| export AbstractKindedTypes.* | |
| trait Person extends PersonBase: | |
| val children: K1[Person] | |
| trait PersonImpl extends Person: | |
| val name: String | |
| val birthdate: java.time.LocalDate | |
| val children: K1Impl[Seq, Person] | |
| end PersonImpl | |
| val samplePerson: PersonImpl = | |
| new PersonImpl: | |
| val name = "John Doe" | |
| val birthdate = java.time.LocalDate.now() | |
| val children = Seq(new PersonImpl: | |
| val name = "Jane Doe's son" | |
| val birthdate = java.time.LocalDate.now() | |
| val children = Seq.empty) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment