Idea: Polymorphism for the compiler plugin

オープン
#2,097 コメント 1 件 リアクション 1 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
kotlin
領域
compilers

調査の方向性

Start by reviewing the compiler plugin behavior described here and compare it with issue #1347 and the linked kotlin-structural-typing project. Define how a final local DataFrame type should gain compatible @DataSchema interfaces within its module, then verify the UserLike example compiles and supports the nameAndAge call.

索引モデルが issue の本文から書いたものです。

説明

Compiler plugin

Similar yet alternative approach to https://github.com/Kotlin/dataframe/issues/1347. Can we use the compiler plugin to write code like this?

@DataSchema
interface UserLike {
    val name: String
    val age: Int
}

fun DataFrame<UserLike>.nameAndAge(): String = rows().joinToString { "$name is $age years old" }

fun main() {
    val df = dataFrameOf(
        "name" to columnOf("Alice", "John"),
        "age" to columnOf(12, 13),
        "favoriteColor" to columnOf("blue", "yellow"),
    )

    println(df.nameAndAge())
}

In this example, val df: DataFrame<DataFrameOf_41>, DataFrameOf_41 would automatically gain UserLike as supertype because it is compatible.

Background

I was inspired by https://github.com/obabichev/kotlin-structural-typing, a compiler plugin that allows writing code like this:

Image

You can see, it automatically injects @Structural interfaces as supertype of classes if they are compatible. This allows you to write a function like

fun UserLike.nameAndAge(): String = "$name is $age years old"

and you can call it on both users and dogs.

This logic also works with dataframe and the compiler plugin, as long as you materialize the schema and cast to it:

Image

Of course, what would be the most useful is if our local types automatically pick up compatible @DataSchema interfaces as supertype! That would make dataframes polymorphic again :)

We can save us a combinatorial explosion by only adding supertypes to the final local type, not intermediate interfaces and by sticking to the module it's written in, similar to the @Structural plugin.

Overlap with https://github.com/Kotlin/dataframe/issues/1347

While there is overlap, this idea is simpler and more concrete. It doesn't use generics and requires no tracking of a modifying data schema. Of course #1347 would be even better, but it is likely outside the 1.0 scope. This idea might be small enough to be included, maybe.

主要言語
Kotlin
スター
1.1k
フォーク
87
平均マージ
2日 21時間
マージ済み PR(30日)
40

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Kotlin/dataframe のほかの issue

Kotlin/dataframe の issue をすべて見る

似ている issue

Kotlin の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。