簡體   English   中英

如何使用單例庫為存在量化類型定義HasRep實例?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM