我了解到您可以ContT從轉換器重新定義,以便r型別引數是隱式的(并且可以使用 顯式指定TypeApplications),即:
-- | Same as `ContT` but with the `r` made implicit
type ContT ::
forall (r :: Type).
(Type -> Type) ->
Type ->
Type
data ContT m a where
ContT ::
forall r m a.
{runContT :: (a -> m r) -> m r} ->
ContT @r m a
type ContVoid :: (Type -> Type) -> Type -> Type
type ContVoid = ContT @()
我沒有意識到這在 GHC 中是可能的。使用隱式型別引數定義型別族的這種方式稱為使用forallin 型別定義(在上面的示例中是指外部forall- 而不是簡單地forall統一r?
uj5u.com熱心網友回復:
沒有人為此目的(不使用依賴項)使用此(不可見的依賴量化),但它與Type -> ..隱式給出引數相同。
type EITHER :: forall (a :: Type) (b :: Type). Type
data EITHER where
LEFT :: a -> EITHER @a @b
RIGHT :: b -> EITHER @a @b
eITHER :: (a -> res) -> (b -> res) -> (EITHER @a @b -> res)
eITHER left right = \case
LEFT a -> left a
RIGHT b -> right b
您還可以使用“可見依賴量化”,其中可見forall->對應物是forall.,所以forall (a :: Type) -> ..就像a沒有出現在..中一樣:Type -> ..
type EITHER :: forall (a :: Type) -> forall (b :: Type) -> Type
data EITHER a b where
LEFT :: a -> EITHER a b
RIGHT :: b -> EITHER a b
eITHER :: (a -> res) -> (b -> res) -> (EITHER a b -> res)
eITHER left right = \case
LEFT a -> left a
RIGHT b -> right b
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/427302.html
上一篇:有什么作用。(點)代表什么?
