phantom-types

    0熱度

    1回答

    對於我的主鍵,可以使用Code First的幻像類型嗎? 我有這樣的事情: class Id<TEntity, TKey> where TEntity : Entity { // implementation } class Entity<TEntity, TKey> { [Key] public Id<MyEntity, Guid> Id { ge

    0熱度

    1回答

    我用Haskell聲明瞭一個像這樣的幻像類型。 newtype Length (a::UnitLength) b = Length b deriving (Eq,Show) data UnitLength = Meter | KiloMeter | Miles deriving (Eq,Show) 現在,我想寫一些函數來使用這種類型。但是我沒有

    8熱度

    1回答

    假設我有: class Bounded[A] { type apply[C <: A] = C } 這編譯: implicitly[Bounded[Any]#apply[String] =:= String] 這種失敗: type Str = Bounded[Any]#apply[String] ...有: [error] /home/grant/Workspace/scu

    5熱度

    2回答

    所以我試圖爲可變長度元組創建一個類型,基本上是Either a (Either (a,b) (Either (a,b,c) ...))和Either (Either (Either ... (x,y,z)) (y,z)) z的更漂亮的版本。 {-# LANGUAGE TypeOperators, TypeFamilies, MultiParamTypeClasses, FlexibleInstan

    2熱度

    2回答

    下面是在Data.Fixed之後建模的模塊化算術Num實例的實現。 我想寫一個替代實施fromRational這看起來是這樣的: fromRational r = case invertMod (denominator r) theModulus of Just inv -> normalize $ (numerator r) * inv Nothing ->

    1熱度

    1回答

    我有一個模塊插槽使用虛擬類型執行一些簡單的訪問控制: module Socket : sig type 'a t val ro : string -> [ `Read ] t val rw : string -> [ `Read | `Write ] t end 我想在Container.t記錄來包裝一個Socket.t,但有沒有一些方法也傳播幻像類型參數到

    4熱度

    5回答

    讓我們有以下的數據類型: data Foo1 a = Foo1 data Foo2 a = Foo2 (Foo3 a) data Foo3 a = C1 (Foo1 a) | C2 Int 而現在我們希望能夠從Foo1或int得到Foo3。 一個解決方案是使用類型類: class ToFoo3 a where toFoo3 :: a -> Foo3 b -- Here start