[英]How to use the singletons library to define a HasRep instance for existentially quantified types?
我想使用存在大小的圖像窗口有幾個原因:
Zip
實例。 我正在使用此代碼執行此操作:
-- | A "matrix" represented as a composition of sized vectors.
type Mat h w = Vector h :.: Vector w
-- | A handy alias for locating a window in the 2D plane.
type Orig = (Integer,Integer)
-- | An attempt at using `singletons` to define windows.
data Wind :: Nat -> Nat -> Type -> Type where -- height -> width
Wind
:: (KnownNat h, KnownNat w)
=> { img :: Mat h w a -- ^ image data matrix
, ll :: Orig -- ^ position of lower-left corner
, dflt :: a -- ^ out-of-bounds value
} -> Wind h w a
data SomeWind a :: Type where
MkSomeWind :: Sing h -> Sing w -> Wind h w a -> SomeWind a
現在,我需要為SomeWind
類型創建一個HasRep
實例:
import qualified ConCat.Rep as R
instance R.HasRep (SomeWind a) where
type Rep (SomeWind a) = ???
repr (MkSomeWind _ _ (Wind im orig def)) = (im, (orig, def))
abst (im :: (Vector h :.: Vector w) a, (orig, def)) =
MkSomeWind (SNat :: Sing h) (SNat :: Sing w) (Wind im orig def)
我有一種嘮叨的預感,我應該能夠使用單身人士庫來幫助我取代“???” 上面有正確的定義,但我無法弄清楚如何。
有人可以幫忙嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.