[英]Scala 3: dealing with path dependent types
考慮以下代碼段:object Test extends App { class X { class Y } class Z(val x: X) { val y: x.Y = new x.Y } val x: X = new X val z: Z = new ...
[英]When using scala path dependent type as function codomain, why is it impossible to add alias for that function?
這是一個簡單的例子: 這給出了編譯錯誤: 這個(some other)從哪里來? 是類型選擇規則不明確導致的編譯器bug(理論上應該在scala 3解決)? 更新 1對不起,我剛剛意識到P#Repr不應該被稱為類型選擇,它應該只指val p: P;p.Repr ,現在它增加了更多的混亂,因為: 我 ...
[英]How to help the Scala 3 compiler infer a path-dependent-type?
假設,只要類型A可以表示對物理值的不太精確的測量,我就會有一個Imprecise[A]的實例。trait Imprecise[A]: type Precision val ord: Ordering[Precision] def precision(a: A): Precision ...
[英]What is the use of `*.this` in Scala?
看起來.this部分沒有任何影響。 提出一個具體問題:您什么時候使用.this ? ...
[英]In scala, is it possible to initialise a singleton object from a TypeTag?
假設我有一個帶有 TypeTag 的 class: 如果T是 singleton 類型,是否可以在運行時使用 TypeTag 來查找T的值? 即: object TypeViewsSpec { val a = 3 val b = new Object { val c = 3 ...
[英]How do existential types overlap with path-dependent types?
開始 Scala 3 個存在類型已被刪除,其中一個原因說明為存在類型在很大程度上與路徑依賴類型重疊,因此擁有它們的收益相對較小。 鑒於“很大程度上”,所以並非總是如此,我想知道是否可以提供一個具體示例來演示如何將存在類型重寫為路徑相關類型,以及無法進行此類替換的示例? ...
[英]In scala, How to call generalised copy function of a case class if it is declared in a family outer type? - Part 2
這是第 1 部分的后續問題: 在 scala 中,如果在家族外部類型中聲明,如何調用案例 class 的通用副本 function? 在第 2 部分中,class 系列的定義變得稍微復雜一些: 所以舊技巧不再起作用,上面的編譯錯誤如下: 在這種情況下如何編譯? ...
[英]In scala, How to call generalised copy function of a case class if it is declared in a family outer type?
這是由路徑依賴類型引起的 scala 問題:考慮到我有一個家庭類型:trait Outer { case class Inner(v: Int) { val outer = Outer.this } } 如果我想在Outer的實例未知時調用Outer#Inner.copy ...
[英]Scala: Assign the value of path-Independent type to value of path-Depended type
我知道,例如, Long和依賴路徑的類型foo.Long是不同的類型。 但是 Scala 中有沒有辦法將路徑無關類型的值分配給路徑相關類型? 當然,我得到: 我該如何克服呢? ...
[英]Referencing path-dependent type of an argument in the type of another argument to a constructor
我有自動機,它具有狀態和轉換標簽的依賴類型(我稱它們為關聯類型)。trait Automaton { type State type Label type Transition = (State, Label, State) } 現在我想寫一個 class 作為參數,一個自動機和一個 ...
[英]Behaviour of context bounds and implicit parameter lists with regards to path dependent types
我一直認為上下文邊界和隱式參數列表的行為完全相同,但顯然不是。 在下面的示例中,我希望summon1[Int]和summon2[Int]返回相同的類型,但它們沒有。 我希望summon2[Int]返回一個依賴於路徑的類型,但它給了我一個類型投影。 為什么?Welcome to the Ammonit ...
[英]How to add type-checking to a function extraction summary
我正在發現 Dotty,我很想提出我的算法的打字版本。 我想實現以下我可以在 JavaScript 中輕松完成的事情。 它基本上是一種提取記錄或數組屬性的精簡方法: function Field(key, action) { return { apply(record) { ...
[英]How to translate type projections into PDTs in implicits?
這是一個慣用的 scala 2 示例: 如您所見,它已經部分轉換為路徑依賴類型的使用。 但是如何為引用self.Content (例如O =:= self.Content本身)的O類型創建Mapper的隱式值? 理想情況下,一個在 Scala 2 和 Scala 3 之間具有直接等效性的解決方案 ...
[英]Scala: pattern matching on a path-dependent type
無法弄清楚為什么 Scala 2.13 對這里的模式匹配不滿意 trait A { sealed trait T case class TImpl() extends T } trait Fail[B <: A] { val a: B // no error ...
[英]Enforcing that dependent return type must implement typeclass
我試圖強制執行一個規則,類型類的(依賴)返回類型必須本身實現一個類型類。 所以當用戶實現下面的IsVec類型類時,還必須保證getElem方法的返回值實現了另一個類型類( IsVecElem )。 我試圖使這項工作看起來像這樣: 問題來自 IsVecOps 中的 getElem - 這會引發編譯 ...
[英]Incompatible type error when overriding type bounds
無法弄清楚為什么 scalac 在這里不開心(2.12): trait A { type Self <: A type X <: Self } trait B extends A { override type Self <: B override type X ...
[英]Why is it possible to define a class with a unreified path-dependent type?
考慮以下示例: class Reif1顯然應該工作。 因為type Out被具體化並成為類型別名 class Reif2也有效,但認真嗎? type Out只定義了上限/下限,而且這個界限還不夠嚴密: this.type是一個單例類型,而Reif2是一個類類型。 那么如果Reif2被實例化 ...
[英]In scala 2.13+ / 3.x, how can we address the diamond inheritance problem of abstract types?
這是一個簡單的例子: trait Sup { type A def a: A def b: A } trait Sub1 extends Sup { override type A = Product override def a = "s" -> "s" } ...
[英]How to implement an ADT for a container with one or many values in Scala
歸根結底,這是我想要實現的目標: 為了實現這一點,似乎需要一個代表一個或多個值的 ADT。 這是我的實現。 是否有另一種/更好/更簡單的方法來實現它(我使用了路徑相關類型和 F 有界類型)。 是否有一個已經實現它的庫(用例似乎很流行)。 ...