[英]Constraint to see if one type “satisfies” another
Is there a way to write a constraint: 有没有办法写一个约束:
C t1 t2 :: Constraint
Such that it "satisfies" (is that the right word) if t2
matches against t1
. 如果
t2
与t1
相匹配,则它“满足”(是正确的单词)。
For example: 例如:
C (forall a. Num a => a -> a -> a) (forall a. Num a => a -> a -> a) -- good
C (forall a. Num a => a -> a -> a) (Int -> Int -> Int) -- good
C (forall a. Num a => a -> a -> a) (Bool -> Bool -> Bool) -- fails
C (Int -> Int -> Int) (forall a. Num a => a -> a -> a) -- fails
The basic answer is no. 基本答案是不。 Haskell's type system is predicative : a type variable can only be instantiated to a monotype.
Haskell的类型系统是谓词的 :类型变量只能实例化为单型。 So if you had
所以如果你有
class C t u
or 要么
type family C t u
the t
and u
simply can't be instantiated to the polymorphic types you want to talk about. t
和u
根本无法实例化为您要谈论的多态类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.