【发布时间】:2021-03-25 14:36:01
【问题描述】:
haskell 中是否有任何绑定器来引入在类型中量化的类型变量(和约束)?
我可以添加一个额外的参数,但它违背了目的。
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE GADTs #-}
data Exists x = forall m. Monad m => Exists (m x)
convBad :: x -> Exists x
convBad x = Exists @m (return @m x, undefined) --Not in scope: type variable ‘m’typecheck
data Proxy (m:: * -> *) where Proxy :: Proxy m
convOk :: Monad m => x -> Proxy m -> Exists x
convOk x (_ :: Proxy m) = Exists (return @m x)
【问题讨论】:
-
为什么
return @m x比return @Identity x更受欢迎?
标签: haskell existential-type quantifiers rank-n-types