我想深入瞭解Scala中的類型級編程,並開始做一些小練習。我開始在類型級別實現Peano號碼。以下是下面的代碼! sealed trait PeanoNumType { // Type at the end indicates to the reader that we are dealing with types
type plus[That <: PeanoNumType] <: P
我試圖使用dfold定義here dfold
:: KnownNat k
=> Proxy (p :: TyFun Nat * -> *)
-> (forall l. SNat l -> a -> (p @@ l) -> p @@ (l + 1))
-> (p @@ 0)
-> Vec k a
-> p @@ k
基本上它是摺疊該
我嘗試瞭解Haskell類型級別編程。我寫了一個小功能來查找一個鍵,一個符號,在類型級別列表: {-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
import GHC.TypeLits
type famil
我想創建一個Int值存儲這樣的一個類型級表示: sealed trait Position {
def value : Int
}
class P1 extends Position {val value = 1}
class P2 extends Position {val value = 2}
當一個類繼承它: case class PExtended() extends
我試圖在Rust中實現類型級乘法。 加法已經在工作,但我得到了一個「臨時」類型變量的問題。 代碼: use std::marker::PhantomData;
//Trait for the type level naturals
trait Nat {}
impl Nat for Zero {}
impl<T: Nat> Nat for Succ<T> {}
//Zero and
我想在運行時對類型級別進行一些計算。所以我爲它們定義了包裝類和隱式定義。但我不明白爲什麼類型信息計算 sealed trait Solve[In] {
type Out
}
implicit def idSolve[I] = new Solve[I] {
override type Out = I
}
type X = Int
val y = implicitly
假設我有一個類型列表中,那種[*]: let Ts = '[Int, Bool, Char]
我想將其轉換爲一個元組的鏈條:到目前爲止 type family Tupled (ts :: [*]) z :: *
type instance Tupled (t ': ts) z = (t, Tupled ts z)
type instance Tupled '[] z = z
所以好: